class Solution {
public:
inline int sqr(int x) { return x * x; }
inline int d(pair<int, int> const & p1, pair<int, int> const & p2) {
return sqr(p1.first - p2.first) + sqr(p1.second - p2.second);
}
int numberOfBoomerangs(vector<pair<int, int>>& ps) {
int result = 0;
unordered_map<int, int> cnts(ps.size());
for (auto& i: ps) {
cnts.clear();
for (auto& j: ps) ++cnts[d(i, j)];
for (auto& c: cnts) result += c.second * (c.second - 1);
}
return result;
}
};