#C12499. Counting Unique k-Pairs

    ID: 41932 Type: Default 1000ms 256MiB

Counting Unique k-Pairs

Counting Unique k-Pairs

Given an array of integers and an integer k, count the number of unique pairs of integers (a, b) in the array such that the difference satisfies \(a - b = k\). A pair is considered unique if the two numbers involved are unique, even if they appear multiple times in the array.

Note:

  • For \(k = 0\), a pair \((a, a)\) is counted only if the number a appears at least twice in the array.
  • For nonzero \(k\) (including negative values), consider a pair \((a, b)\) valid if \(a - b = k\) and each pair is counted only once.

The input is provided via stdin and the output should be written to stdout.

inputFormat

The first line of input contains two space-separated integers: n (the number of elements in the array) and k (the difference value).

The second line contains n space-separated integers representing the elements of the array.

outputFormat

Output a single integer representing the number of unique pairs \((a, b)\) such that \(a - b = k\).

## sample
5 2
1 5 3 4 2
3