```
public int numberOfBoomerangs(int[][] points) {
int sum = 0;
Map<Integer, Integer> map = new HashMap<>();
for(int[] p1 : points) {
for(int[] p2 : points) {
int d = (p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]);
map.put(d, map.getOrDefault(d, 0) + 1);
}
for(int n : map.values()) sum += n * (n - 1);
map.clear();
}
return sum;
}
```