#t545. 统计差值数对
统计差值数对
Counting Pairs with a Given Difference
Problem Description
Given a sequence of positive integers and a positive integer , count the number of pairs satisfying . Pairs whose values are the same but whose positions differ count as different pairs.
Input Format
The input has two lines.
The first line: two positive integers .
The second line: positive integers separated by spaces, the sequence to process.
Output Format
One line with an integer: the number of pairs satisfying .
Sample Input
4 1
1 1 2 3
Sample Output
3
Sample Explanation
For the sample input, , , and the sequence is . When , the two values correspond to two pairs respectively; when , corresponds to one pair. So there are pairs in total, and the output is .
Constraints
For of the data, .
For of the data, , , .