#P1102. Count Pairs with Given Difference
Count Pairs with Given Difference
Count Pairs with Given Difference
You are given a sequence of positive integers and a positive integer \( C \). Your task is to calculate the total number of ordered pairs \((A, B)\) selected from the sequence (with different positions considered as distinct even if they contain the same number) such that the following equation holds:
\(A - B = C\)
For example, if the sequence is [1, 2, 3, 4, 5] and \(C = 2\), one valid pair is \((3, 1)\) because \(3 - 1 = 2\). Note that the order matters; the pair \((1, 3)\) is not valid since \(1 - 3 \neq 2\).
inputFormat
The first line contains two positive integers \(n\) and \(C\), where \(n\) is the length of the sequence and \(C\) is the given positive integer.
The second line contains \(n\) positive integers separated by spaces representing the sequence.
outputFormat
Output a single integer which is the number of ordered pairs \((A, B)\) satisfying \(A - B = C\).
sample
5 2
1 2 3 4 5
3