Problem:
 Score : 200 points    Problem Statement There are N points in a D -dimensional space.  The coordinates of the i -th point are (X_{i1}, X_{i2}, ..., X_{iD}) .  The distance between two points with coordinates (y_1, y_2, ..., y_D) and (z_1, z_2, ..., z_D) is \sqrt{(y_1 - z_1)^2 + (y_2 - z_2)^2 + ... + (y_D - z_D)^2} .  How many pairs (i, j)  (i < j) are there such that the distance between the i -th point and the j -th point is an integer?      Constraints  All values in input are integers.  2 \leq N \leq 10  1 \leq D \leq 10  -20 \leq X_{ij} \leq 20  No two given points have the same coordinates. That is, if i \neq j , there exists k such that X_{ik} \neq X_{jk} .         Input Input is given from Standard Input in the following format:  N  D  X_{11}  X_{12}  ...  X_{1D}  X_{21}  X_{22}  ...  X_{2D}  \vdots  X_{N1}  X_{N2}  ...  X_{ND}       Output Print the number of pairs (i, j)  (i < j) such that the distance between the i -th point and the j -th point is an integer.        Sample Input 1 3 2
1 2
5 5
-2 8      Sample Output 1 1  The number of pairs with an integer distance is one, as follows:   The distance between the first point and the second point is \sqrt{|1-5|^2 + |2-5|^2} = 5 , which is an integer.  The distance between the second point and the third point is \sqrt{|5-(-2)|^2 + |5-8|^2} = \sqrt{58} , which is not an integer.  The distance between the third point and the first point is \sqrt{|-2-1|^2+|8-2|^2} = 3\sqrt{5} , which is not an integer.        Sample Input 2 3 4
-3 7 8 2
-12 1 10 2
-2 8 9 3      Sample Output 2 2       Sample Input 3 5 1
1
2
3
4
5      Sample Output 3 10

Solution (Python):
N, D = [int(x) for x in input().split()]
X = [input() for i in range(N)]
answer = 0
for i in range(N):
    for j in reversed(range(N)):
        if i == j:
            break
        else:
            answer_list = []
            X_list = [int(x) for x in X[i].split()]
            X_list_rev = [int(x) for x in X[j].split()]
            for k in range(D):
                answer_list.append(abs(X_list[k] - X_list_rev[k])**2)
            if sum(answer_list)**0.5 % 1 == 0:
                answer += 1
print(answer)

Solution (Python):
n,d = map(int,input().split())
pnt = [list(map(int,input().split())) for _ in range(n)]
 
def dst(i, j):
    a = pnt[i]
    b = pnt[j]
    ret = 0
    for p, q in zip(a, b):
        ret += (p - q) ** 2
    r = int(ret ** (0.5))
    if r ** 2 == ret:
        return True
    else:
        return False
 
ret = 0
for i in range(n):
    for j in range(i + 1, n):
        tmp = dst(i, j)
        if tmp:
            ret += 1
print(ret)

Solution (Python):
import  math
N,D = map(int, input().split(' '))
x = [list(map(int,input().split(' '))) for i in range(N)]

result = 0

for i in range(len(x)):

    for i1 in range(i,len(x)):

        tmp1 = x[i]
        tmp2 = x[i1]

        ans = 0
        for i2 in range(len(tmp1)):
            ans = ans + (tmp1[i2]-tmp2[i2])**2
        ans = math.sqrt(ans)

        if ans.is_integer() and 0 < ans:
            result  = result + 1
print(result)

Solution (Python):
n,d=map(int,input().split())
x=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        a=[]
        for y,z in zip(x[i],x[j]):
            q=(y-z)**2
            a.append(q)
        ans+=((sum(a))**0.5).is_integer()

print(ans)

Solution (Python):

from itertools import combinations

n, d = [int(s) for s in input().split()]

x = []
for _ in range(n):
    x.append([int(s) for s in input().split()])

pairs = list(combinations(x, 2))
the_number_of_pairs = 0



for i in range(len(pairs)):
    distance = 0

    for j in range(d):
        distance += (abs(pairs[i][0][j] - pairs[i][1][j])) ** 2
    
    distance = distance ** 0.5

    if distance == int(distance):

        the_number_of_pairs += 1

print(the_number_of_pairs)

Solution (Python):
import sys
input=sys.stdin.readline
n,d=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]


cnt=0
def abc(n,m,i,res):
    global cnt,x,d
    if i==d:
        return res
    else:
        res=abc(n,m,i+1,res+(x[m][i]-x[n][i])**2)
    return res

for i in range(n-1):
    for j in range(i+1,n):
        a=abc(i,j,0,0)**0.5
        if int(a)==a:
            cnt+=1
print(cnt)

Solution (Python):
n, d = map(int, input().split())
x = [list(map(int, input().split())) for item in range(n)]
cnt = 0
for i in range(len(x)):
    for j in range(i+1, len(x)):
        tmp = 0
        for k in range(d):
            tmp += (x[i][k] - x[j][k])**2
        if tmp ** 0.5 == int(tmp ** 0.5):
            cnt += 1
print(cnt)

Solution (Python):
from math import sqrt

N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]


count = 0
for n1 in range(N - 1):
    for n2 in range(n1 + 1, N):
        summary = 0
        for d in range(D):
            summary += (X[n1][d] - X[n2][d]) ** 2
        if sqrt(summary).is_integer():
            count += 1
print(count)

Solution (Python):
import math
N,D=map(int,input().split()) 
P=0
Q=0
X= [list(map(int, input().split())) for t in range(N)]
for i in range(N-1):
  for j in range(i+1,N):
    for k in range(D):
      P=P+(X[i][k]-X[j][k])**2
    if int(math.sqrt(P))==math.sqrt(P):
      Q=Q+1
    P=0
print(Q)

Solution (Python):
N,D = map(int,input().split())
X=[]
for i in range(N):
  X +=[[int(x) for x in input().split()]]

count = 0  
  
for i in range(N-1):
  for j in range(i+1,N):
    P = 0
    for k in range(D):
      P +=(X[i][k]-X[j][k])**2
    Q=P**0.5
    if Q == int(Q):
      count += 1
print(count)

Solution (Python):
import math
n,d=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
p=0
for i in range(0,n-1):
  for j in range(i+1,n):
    q=0
    for k in range(0,d):
      q+=(a[i][k]-a[j][k])**2
    if int(math.sqrt(q))==math.sqrt(q):
      p+=1
print(p)

Solution (Python):
import math
n, d  = map(int, input().split())
c = [0] * n
for i in range(n):
    c[i] = list(map(int, input().split()))

ans = 0
for i in range(n):
    for j in range(i+1, n):
        dis = 0
        for k in range(d):
            dis += (c[i][k] - c[j][k])**2
        if math.sqrt(dis) % 1 == 0:
            ans += 1

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
import numpy as np
def print_ans(N, D, dr):
    """Test Case
    >>> print_ans(3, 2, [[1, 2], [5, 5], [-2, 8]])
    1
    >>> print_ans(3, 4, [[-3, 7, 8, 2], [-12, 1, 10, 2], [-2, 8, 9, 3]])
    2
    >>> print_ans(5, 1, [[1],[2],[3],[4],[5]])
    10
    """
    dr = [np.array(d) for d in dr]
    ans = 0
    for i in range(N-1):
        for k in range(i + 1, N):
            multi_ar = dr[i] - dr[k] 
            abs_tmp = float(np.sum(multi_ar ** 2) ** (1/2))
            if(abs_tmp.is_integer()):
                ans += 1
    print(ans)



if __name__ == '__main__':
    N, D = map(int, input().rstrip().split())
    dr = [list(map(int, input().rstrip().split())) for _ in range(N)]
    print_ans(N, D, dr)

Solution (Python):

import sys

import math








def main():
    n, d = [int(x) for x in sys.stdin.readline().split()]
    x = [tuple(int(x) for x in sys.stdin.readline().split()) for _ in range(n)]

    count = 0
    for i in range(n-1):
        for j in range(1, (n-1)-i+1):
            dist = sum([ (x[i+j][k] - x[i][k]) ** 2 for k in range(d)]) ** 0.5
            if dist == math.floor(dist):
                count += 1

    print(count)
    
if __name__ == "__main__":
    main()

Solution (Python):
from collections import defaultdict,deque, Counter
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

def is_square(integer):
    root = math.sqrt(integer)
    return integer == int(root + 0.5) ** 2

ans = 0
[n,d] = inpl()
Xmatrix = [inpl() for _ in range(n)]
npXmatrix = np.array(Xmatrix)
for i in range(n):
    for j in range(i+1,n):
        if is_square(((npXmatrix[i]-npXmatrix[j])**2).sum()):
            ans += 1
print(ans)

Solution (Python):
import numpy as np
from math import sqrt
N, D = map(int, input().split())
Xlist = [np.array(list(map(int, input().split()))) for _ in range(N)]
counter = 0
for i in range(N):
    for j in range(i + 1, N):
        dis = sqrt(np.sum((Xlist[i] - Xlist[j])**2))
        if int(dis) == dis:
            counter += 1
print(counter)

Solution (Python):
import math
N,D = map(int,input().split())
X_ = [0] * N
X = [0]*N
for i in range(N):
    X_[i] = input().split()
for i in range(len(X_)):
    X[i] = [int(j) for j in X_[i]]
cnt = 0
for i in range(N-1):
    for j in range(i+1,N):
        l2 = 0
        for k in range(D):
            l2 += (X[i][k]-X[j][k])**2 
        if math.sqrt(l2) == int(math.sqrt(l2)):
            cnt += 1
            
print(cnt)

Solution (Python):
import math
N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
a = 0
ans = 0

for x1 in range(0, N):
  for x2 in range(x1+1, N):
    for i in range(0, D):
      a += (X[x1][i]-X[x2][i])**2
    if math.sqrt(a).is_integer():
      ans += 1
    a = 0
print(ans)

Solution (Python):
import math 
N,D = map(int,input().split())
X=[]
count=0
for i in range(N):
    x = list(map(int,input().split()))
    X.append(x)
for i in range(N-1):
    for j in range(i+1,N):
        s = 0
        for k in range(D):
            s += (X[i][k]-X[j][k])**2
        if math.sqrt(s).is_integer():
            count += 1
print(count)

Solution (Python):
import numpy as np
import itertools

N,D=map(int,input().split(' '))
X = np.zeros(shape=(N,D))
for i in range(N):
  X[i]=np.array(list(map(int,input().split(' '))))

def distance(v1,v2):
  return np.linalg.norm(v1-v2)

res=0
C=itertools.combinations(list(range(N)),2)
for c in C:
  res+=distance(X[c[0]],X[c[1]]).is_integer()
print(res)

Solution (Python):
import math
N, D = map(int, input().split())
X = []
c = 0
for i in range(N):
    x = list(map(int, input().split()))
    X.append(x)
for i in range(N - 1):
    for j in range(i + 1, N):
        s = 0
        for k in range(D):
            s += (X[i][k] - X[j][k]) ** 2
        if math.sqrt(s).is_integer():
            c += 1
print(c)

Solution (Python):
import math

n, d = list(map(int, input().split()))
x = [[0] * d] * n

for i in range(n):
    x[i] = list(map(int, input().split()))

ans = 0

for i in range(n):
    for j in range((i + 1), n, 1):
        diffs = 0

        for k in range(d):
            diffs += (x[i][k] - x[j][k]) ** 2

        dist = math.sqrt(diffs)
        if (math.floor(dist) == math.ceil(dist)):
            ans += 1

print(ans)

Solution (Python):
import math

N ,D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

ans = 0

for i in range(N-1):
    for j in range(i+1, N):
        x_sq = 0
        for k in range(D):
            x_sq += (X[i][k] - X[j][k])**2
        x_sq = math.sqrt(x_sq)
        if x_sq.is_integer():ans += 1
          
print(ans)

Solution (Python):
import math

N, D = map(int, input().split())
X = []
for _ in range(N):
    X.append(list(map(int, input().split())))

ans = 0

for i in range(N):
    for j in range(i + 1, N):
        dist = 0
        for k in range(D):
            dist += (X[i][k] - X[j][k]) ** 2
        if dist == (math.floor(math.sqrt(dist))) ** 2:
            ans += 1
print(ans)

Solution (Python):

import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    N, D = map(int, input().split())
    X_l = [[int(x) for x in input().split()] for _ in range(N)]

    import math

    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            s = 0
            for k in range(D):
                s = s + (X_l[i][k] - X_l[j][k])**2
            r = math.floor(math.sqrt(s))
            if (s - r**2) == 0:
                ans = ans + 1
    
    print(ans)



    


if __name__ == '__main__':
    main()

Solution (Python):
n,d=map(int,input().split())
a=[[int(i) for i in input().split()] for n in range(n)]
cnt=0
import math
for x,i in enumerate(a):
    for j in a[x+1:]:
        tmp=0
        for k in range(d):
            tmp+=(i[k]-j[k])**2
        num=math.sqrt(tmp)
        if num.is_integer()==True:
            cnt+=1
print(cnt)

Solution (Python):
from itertools import combinations
a,(n,d)=0,list(map(int,input().split()))
for i in [sum([abs(i[0][j]-i[1][j])**2for j in range(d)])**0.5for i in list(combinations([list(map(int,input().split()))for i in range(n)],2))]:
  if i.is_integer():a+=1
print(a)

Solution (Python):
from itertools import combinations
a,(n,d)=0,list(map(int,input().split()))
for i in [sum([abs(i[0][j]-i[1][j])**2for j in range(d)])**0.5for i in list(combinations([list(map(int,input().split()))for i in range(n)],2))]:
  if i.is_integer():a+=1
print(a)

Solution (Python):
from math import sqrt


def solve():
    N, D = map(int, input().split())
    x_l = [0 for _ in range(N)]
    for i in range(N):
        x_l[i] = list(map(int, input().split()))
    ans = 0

    for i in range(N-1):
        for j in range(i+1, N):
            distance = 0
            for k in range(D):
                distance += (x_l[i][k] - x_l[j][k]) ** 2
            distance = sqrt(distance)
            if distance.is_integer():
                ans += 1

    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
n, d = map(int, input().split())
ls_x = [[int(i) for i in input().split()] for i in range(n)]

cub_of_ds = 0
cnt = 0

for i in range(n):
    for j in range(i+1, n):
        for k in range(d):
            cub_of_ds += (ls_x[i][k] - ls_x[j][k])**2
        if ((cub_of_ds)**(1/2)).is_integer() == True:
            cnt += 1
        cub_of_ds = 0
        
print(cnt)

Solution (Python):
n, d = map(int, input().split())
ls_x = [[int(i) for i in input().split()] for i in range(n)]

cub_of_ds = 0
cnt = 0

for i in range(n):
    for j in range(n):
        for k in range(d):
            cub_of_ds += (ls_x[i][k] - ls_x[j][k])**2
        if (((cub_of_ds)**(1/2)).is_integer() == True) and (i > j):
            cnt += 1
        cub_of_ds = 0
        
print(cnt)

Solution (Python):
import numpy as np

n, d = map(int,input().split())
li = []
for i in range(n):
    li.append(list(map(int,input().split())))

li = np.array(li)
count = 0

for i in range(n-1):
    for j in range(i+1,n):
         x = np.linalg.norm(li[i]-li[j])
         if float.is_integer(x):
             count += 1

print(count)

Solution (Python):
import math

n, d = map(int, input().split())
p = []
for i in range(n):
    p.append(list(map(int, input().split())))

cnt = 0
    
for i in range(n-1):
    for j in range(i+1, n):
        L=0
        for k in range(d):
            L += (p[i][k] - p[j][k])**2
        L = math.sqrt(L)
        if L.is_integer() == True:
            cnt+=1

print(cnt)

Solution (Python):
N,D = map(int,(input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
Sum = 0
d = [0]*(N*(N-1)//2)
t = 0
for i in range(N-1):
    for j in range(i+1,N):
        for s in range(D):
            d[t] += abs(X[i][s]-X[j][s])**2
        d[t] = pow(d[t],0.5)
        if d[t].is_integer():
            Sum += 1
        t += 1
print(Sum)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    def check(i,j):
        if(i>=j): return False
        d=sum((X[i][k]-X[j][k])**2 for k in range(D))**.5
        return d==int(d)

    n,D=map(int,input().split())
    X=[list(map(int,input().split())) for _ in range(n)]
    from itertools import product
    print(sum(check(i,j) for i,j in product(range(n),repeat=2)))
resolve()

Solution (Python):



n,d = map(int,input().split())

xll = []
for _ in range(n):
    xl = list(map(int,input().split()))
    xll.append(xl)
    
ans = 0
for i in range(n):
    for j in range(i+1, n):
        tmp = 0
        for x1, x2 in zip(xll[i], xll[j]):
            tmp += (x1-x2)**2
        tmp = tmp ** (1/2)
        if tmp == int(tmp):
            ans += 1
print(ans)

Solution (Python):
import math

n,d = map(int,input().split())
x = []
for i in range(n):
    x.append(list(map(int,input().split())))

count = 0
for i in range(n):
    for j in range(i+1,n):
        sum = 0
        for k in range(d):
            sum += (x[i][k]-x[j][k])**2
        if math.sqrt(sum).is_integer():
            count += 1
print(count)

Solution (Python):
from math import sqrt
from itertools import combinations


def main(n, d, x):
    ans = 0
    for a, b in combinations(x, 2):
        r = 0
        for c, d in zip(a, b):
            r += abs(c - d)**2

        if sqrt(r).is_integer():
            ans += 1

    print(ans)


if __name__ == '__main__':
    n, d = map(int, input().split())
    x = [list(map(int, input().split())) for _ in range(n)]

    main(n,d,x)

Solution (Python):
N,D = map( int, input().split() )
distance = []
c = 0
for i in range(N):
    a = list( map( int, input().split() ) )
    distance.append(a)

for i in range(N):
    for j in range(i+1,N):
        t = 0
        ans = 0
        for k in range(D):
            t += ( distance[i][k] - distance[j][k] )**2
        ans = t**(1/2)
        if ans.is_integer():
            c += 1
print(c)

Solution (Python):
from sys import stdin

n, d = map(int, input().split())
x = []
for i in range(n):
        x.append(list(map(int,input().split())))

ans = 0
for i in range(n):
  for k in range(i+1, n):
    tmp = 0
    for j in range(d):
        tmp += (x[i][j] - x[k][j])**2
    if tmp**(1/2)%1 == 0:
        ans += 1
print(ans)

Solution (Python):
import unittest


class TestB(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think([[1, 2], [5, 5], [-2, 8]]), 1)

    def test_2(self):
        self.assertEqual(think([[-3, 7, 8, 2], [-12, 1, 10, 2], [-2, 8, 9, 3]]), 2)

    def test_3(self):
        self.assertEqual(think([[1], [2], [3], [4], [5]]), 10)


def solve():
    x = read()
    result = think(x)
    write(result)


def read():
    n, d = read_int(2)
    x = []
    for _ in range(n):
        if d == 1:
            x.append([read_int(1)[0]])
        else:
            x.append(read_int(d))
    return x


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(x):
    n = len(x)
    max_d = 10
    max_x, min_x = 20, -20
    set_of_square_of_dist = create_set_of_square_of_dist(max_d, max_x, min_x)

    count = 0
    for i in range(n):
        for j in range(i + 1, n):
            square_of_dist = calc_square_of_dist(x[i], x[j])
            if square_of_dist in set_of_square_of_dist:
                count += 1
    return count


def write(result):
    print(result)


def create_set_of_square_of_dist(max_d, max_x, min_x):
    max_diff = max_x - min_x
    max_square_of_sum = (max_diff ** 2) * max_d

    set_of_square_of_dist = set()
    i = 0
    while True:
        if i ** 2 > max_square_of_sum:
            break
        set_of_square_of_dist.add(i ** 2)
        i += 1
    return set_of_square_of_dist


def calc_square_of_dist(x_1, x_2):
    diff_x = [0 for x in range(len(x_1))]
    for i in range(len(x_1)):
        diff_x[i] = x_1[i] - x_2[i]

    return sum([x ** 2 for x in diff_x])


if __name__ == '__main__':
    
    solve()

Solution (Python):
import math
import sys
def input(): return sys.stdin.readline().strip()

def main():
    n,d=map(int,input().split())
    xx=[]
    for _ in range(n):
        xx.append(list(map(int,input().split())))
    c = 0
    for i in range(n):
        for j in range(i+1,n): 
            dist=math.sqrt(sum((xx[j][k]-xx[i][k])**2 for k in range(d)))
            if dist-int(dist) == 0:
                c+=1
    print(c)

main()

Solution (Python):
nd = list(map(int, input().split()))
xnd = []
for _ in range(nd[0]):
    xnd.append(list(map(int, input().split())))
    
    
    
import math
count = 0
for i in range(nd[0] - 1):
    for i_2 in range(i+1, nd[0], 1):
        xSum = 0
        for j in range(nd[1]):
            xSum += (xnd[i][j] - xnd[i_2][j]) ** 2
        ans = math.sqrt(xSum)
        if ans == int(ans):
            count += 1
print(count)

Solution (Python):
import numpy as np


N, D = list(map(int, input().split()))
X = [list(map(int, input().split())) for i in range(N)]

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        dis = np.linalg.norm(np.array(X[i]) - np.array(X[j]))
        if dis - int(dis) < 0.00000001:
            ans += 1
print(ans)

Solution (Python):
import math
n, d = map(int,input().split())

xi=[]
for i in range(n):
    xi.append(list(map(int, input().split())))



ans=0

for i in range(n):
    for j in range(i+1, n):
        tmp=0
        for k in range(d):
            tmp=tmp+(xi[i][k]-xi[j][k])**2
        if math.sqrt(tmp).is_integer():
            ans= ans+1

print(ans)

Solution (Python):
import math

n, d = map(int, input().split())
x = []

def check_distance(vec1, vec2):
  ssum = 0
  root = 0
  for i in range(len(vec1)):
    ssum += (abs(vec1[i]-vec2[i])**2)
    root = math.sqrt(ssum)
  return root.is_integer()


ans = 0
for i in range(n):
  x.append(list(map(int, input().split())))
  
for i in range(n):
  for j in range(n):
    if i == j:
      continue
    if check_distance(x[i], x[j]):
      ans += 1
      
print(ans//2)

Solution (Python):
from itertools import combinations

n, D = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(n)]
cnt = 0


for a, b in combinations(ls, 2):
    l = 0
    for d in range(D):
        l += (a[d]-b[d])**2
    if l ** 0.5 == int(l ** 0.5):
        cnt += 1

print(cnt)

Solution (Python):
import itertools

n, D = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(n)]
cnt = 0

i1 = [int(i) for i in range(n)]
i2 = itertools.combinations(i1, 2)

for a, b in i2:
    l = 0
    for d in range(D):
        l += (ls[a][d]-ls[b][d])**2
    if l ** 0.5 == int(l ** 0.5):
        cnt += 1

print(cnt)

Solution (Python):
import math
N, D = map(int, input().split())
t = []
for i in range(N):
    t.append(list(map(int, input().split())))
count = 0
sum = 0
for i in range(0, N-1):
    for j in range(i + 1, N):
      for d in range(D):
        sum += pow(t[i][d] - t[j][d], 2)
        sqrt = math.sqrt(sum)
      if sqrt == int(sqrt):
        count += 1
      sum = 0
      sqrt = 0
print(count)

Solution (Python):
import math
n,d = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(n)]
ans = 0
for i in range(n-1):
  for j in range(i+1,n):
    num = 0
    for k in range(d):
      num += (x[i][k]-x[j][k])**2
    if num == int(math.sqrt(num))**2:
      ans += 1
    else:
      continue
print(ans)

Solution (Python):
import math

tmp = list(map(int, input().split()))
n = tmp[0]
d = tmp[1]

x = [[0] * d for i in range(n)]
for i in range(n):
  tmp = list(map(int, input().split()))
  for j in range(d):
    x[i][j] = tmp[j]

cnt = 0
for i in range(n):
  for j in range(i+1, n):
    len = 0
    for k in range(d):
      len += (x[i][k] - x[j][k]) ** 2
    len = math.sqrt(len)

    if len.is_integer():
      cnt += 1

print (cnt)

Solution (Python):
N, D = map(int, input().split())
t = []
for i in range(N):
    t.append(list(map(int, input().split())))
ans = 0
s = 0
for i in range(N):
    for j in range(i+1, N):
        for k in range(D):
            s += (t[i][k]-t[j][k])**2
        if (s ** 0.5).is_integer():
            ans += 1
        s = 0
print(ans)

Solution (Python):
n,d=map(int,input().split(" "))
s=[list(map(int,input().split(" "))) for i in range(0,n)]
from math import*

co=0
for i in range(0,n-1):
    for j in range(i+1,n):
        combi=[abs(x-y)**2 for (x,y)in zip(s[i],s[j])]
        if sqrt(sum(combi))%1==0:
            co+=1
print(co)

Solution (Python):
from itertools import combinations
import numpy as np
N,D = map(int,input().split())
X = []
for i in range(N):
    X.append(np.array(list(map(int,input().split()))))
comb = list(combinations(list(range(N)),2))
count = 0
for i in range(len(comb)):
    dist = (sum(list(np.power(X[comb[i][0]]-X[comb[i][1]],2))))**(1/2)
    if int(dist) == dist:
        count += 1
print(count)

Solution (Python):
n,d = map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]

import numpy as np

def dist(a,b):
  arr_a=np.array(a)
  arr_b=np.array(b)
  return np.sqrt(np.sum((arr_a - arr_b)  ** 2))

count = 0

for i in range(n-1):
  for j in range(i+1,n):
    if dist(x[i],x[j]).is_integer():
      count += 1
print(count)

Solution (Python):
from math import sqrt
n,d=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]

ans=0
tmp=0

for i in range(n):
  for j in range(i+1, n):
    xi,xj = x[i],x[j]
    for k in range(d):
      tmp += (xi[k]-xj[k]) ** 2  
    if sqrt(tmp)%1==0:
      tmp=0
      ans += 1
    else:
      tmp=0

print(ans)

Solution (Python):
from math import sqrt
N, D = map(int, input().split())
X = []
for _ in range(N):
    X.append( list( map(int, input().split()) ) )

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        dist = 0
        for k in range(D):
            dist += (X[i][k]-X[j][k])**2
        dist = sqrt(dist)
        if dist % 1 == 0:
            cnt += 1
print(cnt)

Solution (Python):


import math
def main():
    N,D = map(int, input().split())
    Dimention = [ [int(s) for s in input().split()] for i in range(N)]
    result = 0
    for i, y in enumerate(Dimention):
        for j, z in enumerate(Dimention):
            if i == j or i > j:
                continue
            kei = 0
            for num in range(D):
                kou = y[num] - z[num]
                kou = kou**2
                kei += kou
            if math.sqrt(kei).is_integer():
                result += 1
    print(result)

if __name__ == "__main__":
    main()

Solution (Python):

def main():
    N, D, *X = map(int, open(0).read().split())
    X = tuple(zip(*[iter(X)] * D))
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            r = sum(abs(a - b) ** 2 for a, b in zip(X[i], X[j]))
            ans += 1 if r ** 0.5 == int(r ** 0.5) else 0
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n, d = map(int, input().split())

x = [list(map(int, input().split())) for i in range(n)]
count = 0

for j in range(0, n-1):
    for k in range(j+1, n):
        sum = 0
        for i in range(0, d):
            sum = sum + (abs(x[j][i] - x[k][i]) ** 2)
        if sum**(1/2) % 1 == 0:
            count += 1

print(count)

Solution (Python):
import math

n,d=map(int,input().split())
x=[list(map(int,input().split()))for _ in range(n)]
ans=count=0

for i in range(n-1):
  for j in range(n-1-i):
    for k in range(d):
      count+=(x[i][k]-x[j+i+1][k])**2
    if math.sqrt(count).is_integer():
      ans+=1
    count=0

print(ans)

Solution (Python):
N, D = map(int, input().split())
X = [[int(x) for x in input().split()] for _ in range(N)]

ans = 0

for i in range(N):
	for j in range(i + 1, N):
		dist = 0
		for k in range(D):
			dist += (X[i][k] - X[j][k])**2
		if int(dist**0.5)**2 == dist: ans += 1

print(ans)

Solution (Python):
import math

N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
count = 0
dist = [0] * N
for k in range(N-1):
    for i in range(k+1,N):
        for j in range(D):
            dist[i] += (X[k][j] - X[i][j])** 2
        dist[i] = math.sqrt(dist[i])
        if dist[i].is_integer():
            count += 1
        dist[i]=0
print(count)

Solution (Python):
import math
n, d = map(int, input().split())
v = []
ans = 0
for i in range(n):
  v.append(list(map(int, input().split())))
  
sq_list = [x**2 for x in range(int(40 * d ** 0.5))]

def square(list):
  return [x**2 for x in list]

def calc_distance(l1, l2):
  dif = [l1[i] - l2[i] for i in range(len(l1))]
  d = sum(square(dif))
  return d

for i in range(n - 1):
  for j in range(i + 1, n):
    temp = calc_distance(v[i], v[j])
    if temp in sq_list:
      ans += 1
print(ans)

Solution (Python):
import math

N,D=map(int,input().split())
X=[]
for i in range(N):
    x=list(map(int,input().split()))
    X.append(x)

def dist(R,L):
    P=0
    for z in range(D):
        P+=(R[z]-L[z])**2
    return math.sqrt(P)

count=0
for j in range(N-1):
    for k in range(j+1,N):
        
        
        if dist(X[j],X[k])==math.floor(dist(X[j],X[k])):
            count+=1

print(count)

Solution (Python):
import math
N ,D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]
ans = 0
LL = 0
for i in range(N):
  for j in range(i+1,N):
    for k in range(D):
      LL += (X[i][k]-X[j][k])**2
    L = math.sqrt(LL)
    if LL == int(L)**2:
      ans += 1
    L = 0
    LL = 0
print(ans)

Solution (Python):

n, d = map(int, input().split())

x = [list(map(int, input().split())) for _ in range(n)]


cnt = 0
a = 0
for i in range(n-1):
    for j in range(i+1, n):
        for k in range(d):
            a += (x[i][k]-x[j][k])**2
        if (a**0.5)%1 == 0:
            cnt += 1
            a = 0
        else:
            a = 0
print(cnt)

Solution (Python):
n,d=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]
count=0
su=0
for l in range(n-1):
    for i in range(l+1,n):
        for s in range(d):
            su+=(x[l][s]-x[i][s])**2
            
        if (su**0.5)%1==0:
            count+=1
            su=0
        else:
            su=0
print(count)

Solution (Python):
N, D = map(int, input().split())
X = [[] for _ in range(N)]
for i in range(N):
  X[i].append(list(map(int, input().split())))

import numpy as np
count = 0
X = np.array(X)
for i in range(N):
  for j in range(N-i-1):
    dist = np.linalg.norm(X[i]-X[N-j-1])
    if dist.is_integer():
      count += 1
print(count)

Solution (Python):
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        v = 0
        for k in range(D):
            v += (X[j][k] - X[i][k]) ** 2
        sr = v ** 0.5
        a = int(sr)
        b = a + 1
        if a * a == v or b * b == v:
            ans += 1

print(ans)

Solution (Python):
import math
n, d = map(int, input().split())
x = []
for _ in range(n):
    x.append(list(map(int, input().split())))

ans = 0
for i in range(n):
    for j in range(i+1, n):
        if math.sqrt(sum(list(map(lambda c: (c[0] - c[1])**2, zip(x[i], x[j]))))).is_integer():
            ans += 1
print(ans)

Solution (Python):
import itertools
import math
N, D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]
ans = 0
for Y, Z in itertools.combinations(X,2):
  tmp = 0
  for d in range(D):
    tmp += (Y[d] - Z[d]) ** 2
  if math.sqrt(tmp) % 1 == 0:
    ans += 1
print(ans)

Solution (Python):
import numpy as np

N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]

x = np.array(X)
dist_mat = np.linalg.norm(x[:, np.newaxis] - x, axis=-1)

count = 0
for i in dist_mat:
    for j in i:
        if j.is_integer():
            count += 1

print((count-N)//2)

Solution (Python):

"""
B - Good Distance
https://atcoder.jp/contests/abc133/tasks/abc133_b

"""
import sys
from itertools import combinations


def solve(points):
    ans = 0
    for p1, p2 in combinations(points, 2):
        d = sum([(a-b)**2 for a, b in zip(p1, p2)])
        ans += (d**0.5).is_integer()
    return ans


def main(args):
    n, d = map(int, input().split())
    points = [[int(x) for x in input().split()]  for _ in range(n)]
    ans = solve(points)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])