import java.util.*;
public class Main {
public static int bruteForceCountPairs(int[] arr, int k) {
int count = 0;
for (int i = 0; i < arr.length - 1; ++i) {
for (int j = i + 1; j < arr.length; ++j) {
if (arr[i] + arr[j] == k) {
count++;
}
}
}
return count;
}
public static void main
(String[] args
) { int[] arr = {1, 2, 3, 4, 5};
int k = 6;
System.
out.
println("Count of pairs: " + bruteForceCountPairs
(arr, k
)); }
}
aW1wb3J0IGphdmEudXRpbC4qOwogCnB1YmxpYyBjbGFzcyBNYWluIHsKICAgIHB1YmxpYyBzdGF0aWMgaW50IGJydXRlRm9yY2VDb3VudFBhaXJzKGludFtdIGFyciwgaW50IGspIHsKICAgICAgICBpbnQgY291bnQgPSAwOwogICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgYXJyLmxlbmd0aCAtIDE7ICsraSkgewogICAgICAgICAgICBmb3IgKGludCBqID0gaSArIDE7IGogPCBhcnIubGVuZ3RoOyArK2opIHsKICAgICAgICAgICAgICAgIGlmIChhcnJbaV0gKyBhcnJbal0gPT0gaykgewogICAgICAgICAgICAgICAgICAgIGNvdW50Kys7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIGNvdW50OwogICAgfQogCiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CiAgICAgICAgaW50W10gYXJyID0gezEsIDIsIDMsIDQsIDV9OwogICAgICAgIGludCBrID0gNjsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIkNvdW50IG9mIHBhaXJzOiAiICsgYnJ1dGVGb3JjZUNvdW50UGFpcnMoYXJyLCBrKSk7CiAgICB9Cn0=