<p>You are given <code>n</code> <code>points</code> in the plane that are all <strong>distinct</strong>, where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>. A <strong>boomerang</strong> is a tuple of points <code>(i, j, k)</code> such that the distance between <code>i</code> and <code>j</code> equals the distance between <code>i</code> and <code>k</code> <strong>(the order of the tuple matters)</strong>.</p>

<p>Return <em>the number of boomerangs</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> points = [[0,0],[1,0],[2,0]]
<strong>Output:</strong> 2
<strong>Explanation:</strong> The two boomerangs are [[1,0],[0,0],[2,0]] and [[1,0],[2,0],[0,0]].
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> points = [[1,1],[2,2],[3,3]]
<strong>Output:</strong> 2
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> points = [[1,1]]
<strong>Output:</strong> 0
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>n == points.length</code></li>
	<li><code>1 &lt;= n &lt;= 500</code></li>
	<li><code>points[i].length == 2</code></li>
	<li><code>-10<sup>4</sup> &lt;= x<sub>i</sub>, y<sub>i</sub> &lt;= 10<sup>4</sup></code></li>
	<li>All the points are <strong>unique</strong>.</li>
</ul>

from collections import defaultdict
class Solution:
    def distance(self, x1, y1, x2, y2):
        return pow((x2-x1), 2) + pow((y2-y1), 2)

    def numberOfBoomerangs(self, points: List[List[int]]) -> int:
        # each will have 2 combinations ?
        # for 3 points if dist 
        # compute distances from each point -> (1,1) distances to each and evey other point -> n**2 solition and in the end np2, since each should be 2 more given a point and order matters

        distances_map = dict()

        for i in range(len(points)):
            x1, y1 = points[i][0], points[i][1]
            distances_map[(x1, y1)] = defaultdict(int)
            for j in range(len(points)):
                x2, y2 = points[j][0], points[j][1]
                if i != j:
                    d = self.distance(x1, y1, x2, y2)
                    distances_map[(x1, y1)][d] += 1
        # n p 2 is the solution here
    
        res = 0
        for key, value in distances_map.items():
            for dist, count in value.items():
                if count >= 2:
                    res += factorial(count) // factorial(count - 2)
        return res
    



33400