import java.util.*;
public class Main {
public static int countPairs(int[] b, int k) {
int count = 0;
int n = b.length;
for (int i = 0; i < n; ++i) {
for (int j = i+1; j < n; ++j) {
if (Math.
abs(b
[i
] - b
[j
]) == k
) { count++;
}
}
}
return count;
}
public static void main
(String[] args
) { int[] b = {1, 7, 5, 9, 2, 12, 3};
int k = 2;
System.
out.
println("Number of pairs: " + countPairs
(b, k
)); }
}
CmltcG9ydCBqYXZhLnV0aWwuKjsKIApwdWJsaWMgY2xhc3MgTWFpbiB7CiAKICAgIHB1YmxpYyBzdGF0aWMgaW50IGNvdW50UGFpcnMoaW50W10gYiwgaW50IGspIHsKICAgICAgICBpbnQgY291bnQgPSAwOwogICAgICAgIGludCBuID0gYi5sZW5ndGg7CiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyArK2kpIHsKICAgICAgICAgICAgZm9yIChpbnQgaiA9IGkrMTsgaiA8IG47ICsraikgewogICAgICAgICAgICAgICAgaWYgKE1hdGguYWJzKGJbaV0gLSBiW2pdKSA9PSBrKSB7CiAgICAgICAgICAgICAgICAgICAgY291bnQrKzsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gY291bnQ7CiAgICB9CiAKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKICAgICAgICBpbnRbXSBiID0gezEsIDcsIDUsIDksIDIsIDEyLCAzfTsKICAgICAgICBpbnQgayA9IDI7CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJOdW1iZXIgb2YgcGFpcnM6ICIgKyBjb3VudFBhaXJzKGIsIGspKTsKICAgIH0KfQ==