UHCC1 P5 - Binary Triangles

View as PDF

Submit solution


Points: 7 (partial)
Time limit: 2.5s
Java 4.0s
PyPy 2 4.0s
PyPy 3 4.0s
Memory limit: 256M

Author:
Problem types

Rain loves triangles, especially equilateral ones. Thus, Rain has N points in M-dimensional space where each coordinate point is either 0 or 1, and he wants you to calculate the number of equilateral triangles with vertices on the points. The distance between two points is the usual Euclidean distance.

The Euclidean distance between points a=(a_1,a_2,\dots,a_M),b=(b_1,b_2,\dots,b_M) is \sqrt{(a_1-b_1)^2+(a_2-b_2)^2+\dots+(a_M-b_M)^2}.

Constraints

The points are pairwise-distinct.

1\leq N\leq 400

1\leq M\leq 5 \times 10^4

a_{ij} \in \{0, 1\}

Subtask 1 [80%]

1\leq N,M\leq 400

Subtask 2 [20%]

No additional constraints.

Input Specification

The first line contains two integers N and M.

The next N lines each represent a point a_i. Each line has M integers a_{i1},\ldots,a_{iM}, representing the coordinates of the point.

Output Specification

Output the number of equilateral triangles where each vertex is a given point.

Sample Input

4 3
0 0 1
1 0 0
0 1 0
0 1 1

Sample Output

1

Explanation for Sample

Only the first 3 points form an equilateral triangle.


Comments

There are no comments at the moment.