You are given an array of integers sorted in non-decreasing order and a target value. Count how many index pairs (i, j) with i < j satisfy nums[i] + nums[j] == target.
Equal values at different positions are considered distinct pairs. For example, in [2, 2, 2] with target 4 there are three pairs: (0,1), (0,2), and (1,2).
Input format
Line 1: two integers n and target separated by a space.
Line 2: n space-separated integers in non-decreasing order (this line is present even when n is small; if n == 0 it is empty).
Output format
A single integer: the number of valid index pairs.
Constraints
- 0 ≤ n ≤ 100000
- -1000000000 ≤ each value ≤ 1000000000
- The input array is guaranteed to be sorted in non-decreasing order.
- -2000000000 ≤ target ≤ 2000000000