<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>

class Solution:
    def numberOfBoomerangs(self, points: List[List[int]]) -> int:
        def dist(p1, p2):
            return math.sqrt(pow((p2[0] - p1[0]), 2) + pow((p2[1] - p1[1]), 2))

        #-----------------
        # def print_mat(mat):
        #     output_string = '\t' + '\t'.join([repr(x) for x in points])
        #     output_string += '\n'

        #     for index, row in enumerate(mat):
        #         output_string += f"{points[index]}\t "
        #         for column in row:
        #             output_string += f" {column}\t"
                
        #         output_string +="\n"
        #     print(output_string)

        #-----------------
        output = 0
        num_points = len(points)
        dist_mat = [[0 for _ in range(num_points)] for _ in range(num_points)]  
        
        for i in range(num_points):
            for j in range(i+1, num_points):
                if not dist_mat[i][j]: dist_mat[i][j] = dist_mat[j][i] = dist(points[i], points[j])

        # print_mat(dist_mat)

        for i in range(num_points):
            dist_mat[i] = [dist_mat[i].count(x) for x in dist_mat[i]]

            for j in range(num_points):
                if dist_mat[i][j] > 1: output += dist_mat[i][j] - 1

        # print_mat(dist_mat)


        return output
        
22400