You are given n points in the plane that are all distinct, where points[i] = [xi, yi]. A boomerang is a tuple of points (i, j, k) such that the distance between i and j equals the distance between i and k (the order of the tuple matters).

Return the number of boomerangs.

&nbsp;
Example 1:

Input: points = [[0,0],[1,0],[2,0]]
Output: 2
Explanation: The two boomerangs are [[1,0],[0,0],[2,0]] and [[1,0],[2,0],[0,0]].


Example 2:

Input: points = [[1,1],[2,2],[3,3]]
Output: 2


Example 3:

Input: points = [[1,1]]
Output: 0


&nbsp;
Constraints:


	n == points.length
	1 &lt;= n &lt;= 500
	points[i].length == 2
	-104 &lt;= xi, yi &lt;= 104
	All the points are unique.


class Solution:
    def numberOfBoomerangs(self, points: List[List[int]]) -> int:
        def sq(a):
            return a * a

        def euclid(a, b, c, d):
            dist = sq(a - c) + sq(b - d)
            return sq(dist)

        n = len(points)
        res = 0
        for i in range(n):
            count = defaultdict(lambda : 0)
            for j in range(n):
                d = euclid(points[i][0], points[i][1], points[j][0], points[j][1])
                res += count[d] * 2
                count[d] += 1

        return res
class Solution {
    public int numberOfBoomerangs(int[][] points) {
        
        int answer = 0;
        
        for (int p=0; p<points.length;p++) {
            
            int[] i = points[p];
            
            HashMap<Double, Integer> hm = new HashMap<Double, Integer>();
            
            for (int q=0;q<points.length;q++) {
                
                if (q==p) {
                    continue;
                }
                
                int[] j = points[q];
                
                double distance = Math.sqrt(Math.pow(j[0]-i[0], 2) + Math.pow(j[1]-i[1], 2));
                
                if (distance > 0) {
                    if (hm.containsKey(distance)) {
                        hm.put(distance, hm.get(distance) + 1);
                    } else {
                        hm.put(distance, 1);
                    }
                }
                
            }
            
            for (Double dist : hm.keySet()) {
                int occ = hm.get(dist);
                if (occ > 1) {
                    answer = answer + ((occ) * (occ - 1));
                }
            }
        }
        
        return answer;
    }
}
class Solution {
public:
    int numberOfBoomerangs(vector<vector<int>>& points) {

        int cnt = 0, n = points.size();
        for(int i = 0; i < n; i++)
        {
            map<int, int> mp;
            for(int j = 0; j < n; j++)
            {
                if(i == j)
                    continue;

                int tmp = findDistance(points[i], points[j]);
                if(mp.find(tmp) != mp.end())
                    cnt += mp[tmp] * 2; // 2 is multiplied bcoz the order of j & k can be k & j also

                mp[tmp]++;
            }
        }

        return cnt;
    }

    int findDistance(vector<int> &p1, vector<int> &p2)
    {
        return (p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]);
    }
};
var numberOfBoomerangs = function(points) {
	const POINTS_LEN = points.length;
	let result = 0;

	for (let i = 0; i < POINTS_LEN; i++) {
		const hash = new Map();

		for (let j = 0; j < POINTS_LEN; j++) {
			if (i === j) continue;
			const [x1, y1] = points[i];
			const [x2, y2] = points[j];
			const dis = Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2);
			const value = hash.get(dis) ?? 0;

			if (value > 0) result += value * 2;
			hash.set(dis, value + 1);
		}
	}

	return result;
};
Number of Boomerangs