class Solution {
public int countTriplets(int[] A) {
Map<Integer, Integer> map = new HashMap();
for (int a : A) {
for (int b : A) {
map.put((a & b), map.getOrDefault((a & b), 0) + 1);
}
}
int res = 0;
for (int a : A) {
for (int b : map.keySet()) {
if ((a & b) == 0) {
res += map.get(b);
}
}
}
return res;
}
}