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):
import math
n, d = map(int, input().split())
coos = []
cnt = 0
chk = 0
for i in range(0, n):
    coo = list(map(int, input().split()))
    coos.append(coo)
for i in range(n-1):
    for j in range(i+1, n):
        chk = 0
        for k in range(d):
            chk += (coos[i][k] - coos[j][k])**2
        chk = math.sqrt(chk)
        if chk.is_integer() == True:
            cnt+=1
        else:
            continue
print(cnt)

Solution (Python):
def examA():
    N, A, B = LI()
    ans = min(A*N,B)
    print(ans)
    return

def examB():
    N, D = LI()
    X = [LI() for _ in range(N)]
    ans = 0
    for i,j in itertools.combinations(X,2):
        cur = 0
        for k in range(D):
            cur += (i[k]-j[k])**2
        cur **=0.5
        if cur==int(cur):
            ans +=1
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examB()

Solution (Python):
import math
import itertools


def calcDist(row1, row2):
    n_dist = 0
    for d in range(D):
        dist = abs(row1[d] - row2[d])
        n_dist += dist ** 2
    return n_dist

N, D = map(int, input().split())

dimentions = []

for i in range(N):
    row = list(map(int, input().split()))
    dimentions.append(row)
    
dim_combinations = itertools.combinations(dimentions, 2)

all_dist = []

for pair in dim_combinations:
    n_dist = calcDist(pair[0], pair[1])
    all_dist.append(math.sqrt(n_dist))

cnt = 0
for dist in all_dist:
    if dist.is_integer():
        cnt += 1
        
print(cnt)

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

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

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


if __name__ == '__main__':
    main()

Solution (Python):
N, *L,  = [list(map(int, s.split())) for s in open(0)]
cnt = 0
for i in range(len(L) - 1):
    for j in range(i+1, len(L)):
        dist = 0
        for d in range(N[1]):
            dist += (L[i][d] - L[j][d]) ** 2
        if (dist ** (0.5)) % 1 == 0:
            cnt += 1
print(cnt)

Solution (Python):
import math
import sys
input = sys.stdin.readline

def Euclid_dist(tpl1, tpl2):
    if len(tpl1) != len(tpl2): raise TypeError("The length differs between tpl1 and tpl2")
    sum = 0
    for i in range(len(tpl1)):
        sum += pow(tpl1[i]-tpl2[i], 2)
    return math.sqrt(sum)

N, D = map(int,input().split())
li_X = [list(map(int, input().split())) for _ in range(N)]
count = 0
for i in range(N):
    for j in range(i+1, N):
        if Euclid_dist(li_X[i], li_X[j]).is_integer():
            count += 1
print(count)

Solution (Python):
import math

def distance(X1, X2):
    res = 0
    for x1, x2 in zip(X1, X2):
        res += pow(x1-x2, 2)
    return math.sqrt(res)

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-1):
    for j in range(i+1, N):
        d = distance(X[i], X[j])
        if d.is_integer():
            ans += 1
print(ans)

Solution (Python):
n,d=map(int,input().split())
l=[]
s=0
for _ in range(n):
    l.append(list(map(int,input().split())))
for i in range(n-1):
    for j in range(i+1,n):
        x=0
        for k in range(d):
            x+=(l[i][k]-l[j][k])**2
        x=x**.5
        y=int(x)
        if x==y:
            s+=1
print(s)

Solution (Python):
from scipy.spatial import distance
import itertools

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

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

combi = list(itertools.combinations(x, 2))

ans = 0
for i in range(len(combi)):
    dis = distance.euclidean(combi[i][0], combi[i][1])
    if dis.is_integer():
        ans += 1

print(ans)

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

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

print(count)

Solution (Python):
import math

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

cnt=0
for i in range(n-1):
	for j in range(i+1,n):
		a=0
		for dd in range(d):
			a += abs(lst[i][dd] - lst[j][dd])**2    	
		aa=math.sqrt(a)
		if aa.is_integer():
			cnt += 1
print(cnt)

Solution (Python):
N, D = map(int, input().split())
X = []

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


def dist(a, b):
    d = 0
    for i in range(D):
        d += (a[i] - b[i])**2
    return d


dists = []
for i in range(N):
    for j in range(i + 1, N):
        dists.append(dist(X[i], X[j]))

v = [i**2 for i in range(1000)]

ans = 0
for d in dists:
    if d in v:
        ans += 1
print(ans)

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

cnt=0

for i in range(n-1):
  for j in range(i+1,n):
    X=0
    for k in range(d):
      X+=(A[i][k]-A[j][k])**2
    if (X**0.5)==((X**0.5)//1):    
      cnt+=1
print(cnt)

Solution (Python):
n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        sum = 0
        for k in range(d):
            sum += (x[i][k] - x[j][k]) ** 2
        for k in range(200):
            if k ** 2 == sum:
                ans += 1
                break
print(ans)

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

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

ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        sum = 0
        for k in range(d):
            sum += (lst[i][k] - lst[j][k]) ** 2
        if int(sum ** 0.5) ** 2 == sum:
            ans += 1

print(ans)

Solution (Python):
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 j in range(i+1,n):
        f = 0
        for k in range(d):
            f += (x[i][k]-x[j][k])**2

        m = 1
        while m*m < f:
            m += 1
        if m*m == f:
            ans += 1

print(ans)

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

x = []
a = 0
ans = 0

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

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
        else:
            if sqrt(a).is_integer() == True:
                ans += 1
            a = 0

print(ans)

Solution (Python):
import numpy as np

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

cnt = 0
for i in range(1, N):
    A = np.sqrt(np.sum(np.square(X[i:] - X[i - 1]), axis=1))
    cnt += np.count_nonzero(A % 1 == 0)

print(cnt)

Solution (Python):

import itertools
import math

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

ans = 0
for (i, j) in itertools.combinations(range(n), 2):
    leng = 0
    for k in range(d):
        leng += (l[i][k] - l[j][k]) ** 2
    if math.sqrt(leng) % 1 == 0:
        ans += 1
print(ans)

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

count=0
for i in range(n):
    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(num**.5)**2:
            count+=1

print(count)

Solution (Python):
from itertools import combinations
from math import sqrt
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
print(len(list(filter(lambda x: x==float(int(x)), map(lambda t: sqrt(sum(map(lambda y,z: (y-z)**2, t[0], t[1]))), combinations(X, 2))))))

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

Solution (Python):
n,d = map(int,input().split())
x = [0]*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) :
        a = 0
        for k in range(d) :
            a += (x[i][k] - x[j][k])**2
        a = a**0.5
        if int(a) == a :
            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)]
cnt = 0
for i in range(n):
	for j in range(i+1,n):
		a = 0
		for k in range(d):
			a += (x[i][k] - x[j][k])**2
		b = math.sqrt(a)
		if b == int(b):
			cnt += 1
print (cnt)

Solution (Python):
from math import sqrt
n,d=map(int,input().split())
l=[list(map(float,input().split())) for i in range(n)]
nums=[i for i in range(n-1)]
fa=[i for i in range(d)]
cnt=0
ans=0
t=[]
for i in nums:
  for j in l[i+1:]:
    cnt=0
    for k in fa:
      cnt+=(l[i][k]-j[k])**2
    cnt=sqrt(cnt)
    t.append(cnt)
for v in t:
  if(v.is_integer()):
    ans+=1
print(ans)

Solution (Python):
import math

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

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

cnt = 0
sum = 0

for i in range(n-1):

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

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

        if ((sum**0.5).is_integer()):
            cnt += 1
        sum = 0

print(cnt)

Solution (Python):
import math

N, D = map(int, input().split())

point = []
cnt = 0

for _ in range(N):
    point.append(list(map(int, input().split())))

def calc_dist(x, y):
    dist = 0
    for xx, yy in zip(x, y):
        dist += ((xx - yy) ** 2)
    return math.sqrt(dist)

for i in range(N):
    for j in range(i+1, N):
        dist = calc_dist(point[i], point[j])

        if int(dist) == dist:
            cnt += 1
print(cnt)

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

ans=0
kyori=0


for i in range(N-1):
    
  for j in range(i+1,N):
    
    for k in range(D):
      kyori+=(zahyo[i][k]-zahyo[j][k])**2
    if (kyori**0.5).is_integer():
      ans+=1
      
    kyori=0
    
print(ans)

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

a=list(range(N))
b=list(itertools.combinations(a,2))

sum=0
count=0

for i in range(len(b)):
    for j in range(D):
        sum+=(X[b[i][0]][j]-X[b[i][1]][j])**2
    if sum**(1/2)%1!=0:
        sum=0
    else:
        count+=1
        sum=0

print(count)

Solution (Python):
import math

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

distance = 0
count = 0
for i in range(n-1):
    for j in range(i+1, n):
        combined1 = [x - y for (x, y) in zip(x[i], x[j])]
        distance = math.sqrt(sum(list(map(lambda x: x**2, combined1))))
        if distance%1 == 0:
            count += 1

print(count)

Solution (Python):
import itertools
import math
n, d = map(int, input().split())
l = list()
for i in range(n):
    l.append(list(map(int, input().split())))
a = list(itertools.combinations(l, 2))
count = 0
for i in range(len(a)):
    x = 0
    for j in range(d):
        x += (a[i][0][j]-a[i][1][j])**2
    if math.sqrt(x).is_integer():
        count += 1
print(count)

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

def dis(P1,P2):
  ans=0
  for i in range(len(P1)):
    ans+=(P1[i]-P2[i])**2
  ans=ans**0.5
  return ans

cnt=0
for i in range(n):
  for j in range(i+1,n):
    if dis(P[i],P[j])%1==0:
      cnt+=1
print(cnt)

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

cnt = 0
x = 0

for i in range(N-1):
    for j in range(i+1,N):
        for k in range(D):
            x += (x_list[i][k]-x_list[j][k])**2
        if (x**0.5).is_integer():
            cnt += 1
        x = 0

print(cnt)

Solution (Python):
def main():
	import itertools
	
	n,d = map(int,input().split())
	
	List = [list(map(int,input().split())) for i in range(n)]
	
	combi = list(range(n))
	
	ans = 0
	for v in itertools.combinations(combi, 2):
		
		
		
		di = 0
		for i in range(d):
			
			
			
			di += (List[v[0]][i] - List[v[1]][i])**2
			
			
			
		
		di = di**0.5
		
		
		if di == int(di):
			ans += 1
			
		else:
			ans += 0
	print(ans)



	

if __name__ == "__main__":
	main()

Solution (Python):
N, D = map(int, input().split())
X = []
ans = 0

for i in range(N):
    Xi = list(map(int, input().split()))
    X.append(Xi)
    
for i in range(N-1):
    for j in range(i+1, N):
        dis_sq = 0
        for d in range(D):
            dis_sq += (X[i][d]-X[j][d]) ** 2
        dis = dis_sq ** 0.5

        if dis.is_integer():
            ans += 1
print(ans)

Solution (Python):
import math

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

ans = 0
for i in range(n):
    for j in range(n):
        t0 = 0
        for k in range(d):
            t0 += pow(p[i][k]-p[j][k],2)
        t  = math.sqrt(t0)
        if t.is_integer() and t != 0:
            ans += 1
print(ans//2)

Solution (Python):
n,d=map(int,input().split())
x=[[0]*d for _ in range(n)]
count=0

for i in range(n):
    x[i]=list(map(int,input().split()))
for i in range(n-1):
    for j in range(i+1,n):
        kyori=0
        for k in range(d):
            kyori+=(x[i][k]-x[j][k])**2
        a=int(kyori**0.5)
        if a**2==kyori:
            count+=1
print(count)

Solution (Python):
import math
n,d=map(int,input().split())
v=[list(map(int,input().split())) for i in range(n)]
e=0
for i in range(n-1):
    for j in range(i+1,n):
        c=0
        for g in range(d):
            c+=abs(v[i][g]-v[j][g])**2
        if math.sqrt(c)%1==0:
            e+=1
print(e)

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):
    s = 0
    for _y, _z in zip(y, z):
        s += abs(_y - _z)**2

    if (math.sqrt(s)).is_integer():
        ans += 1

print(ans)

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

c = 0
for i in range(N):
    for j in range(N):
        if i < j:
            dist2 = 0
            for k in range(D):
                dist2 += (array[i][k] - array[j][k])**2
            dist = (dist2)**(1/2)
            if dist == int(dist):
                c += 1
print(c)

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

for i1 in range(N):
    for i2 in range(i1+1, N):
        total = 0
        for index in range(D):
            total += (XX[i1][index] - XX[i2][index])**2
        val = int(total ** (1/2))
        if total == val ** 2:
            ans += 1

print(ans)

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

for i1 in range(N):
    for i2 in range(i1+1, N):
        total = 0
        for index in range(D):
            total += (XX[i1][index] - XX[i2][index])**2
        val = total ** (1/2)
        if isinstance(val, complex):
            val = val.real
        if val.is_integer():
            ans += 1

print(ans)

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

for i1, zahyo_1 in enumerate(XX):
    for i2, zahyo_2 in enumerate(XX):
        if i1 == i2:
            continue
        total = 0
        for index in range(D):
            total += (zahyo_1[index] - zahyo_2[index])**2
        val = total ** (1/2)
        if isinstance(val, complex):
            val = val.real
        if val.is_integer():
            ans += 1

print(ans//2)

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


cnt = 0
for i in range(N-1):
  y = x_list[i]
  for j in range(i+1, N):
    z = x_list[j]
    d = (sum([ (y[k]-z[k])**2 for k in range(D) ])) ** 0.5
    if d % 1 == 0:
      cnt += 1
      
print(cnt)

Solution (Python):
import math

N, D = map(int, input().split())

dots = []
for i in range(N):
    dot = input().split()
    dot = [int(j) for j in dot]
    dots.append(dot)

combinations = []
for i in range(N):
    for j in range(N):
        if i != j:
            combinations.append([i, j])

combinations2 = []
for i in combinations:
    P = dots[i[0]]
    Q = dots[i[1]]
    r2 = 0
    for j in range(D):
        r2 += (P[j] - Q[j]) ** 2
    r = math.sqrt(r2)
    if r % 1 == 0:
        combinations2.append(i)

print(len(combinations2) // 2)

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):
    for j in range(i+1, N):
        d = sum([(y - z)**2 for y, z in zip(X[i], X[j])])**0.5
        if isinstance(d, int) or d.is_integer():
            ans += 1
print(ans)

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

sum=0
count=0
for x in range(0, N-1):
    for y in range(x+1, N):
        for z in range(D):
            sum +=abs((X[x][z]-X[y][z])*(X[x][z]-X[y][z]))

        sq=math.sqrt(sum)
        if(sq==int(sq)):
            count+=1
        sum=0

print(count)

Solution (Python):
import math
N,D = (int(i) for i in input().split())

X = []
for i in range(N):
  X.append([int(i) for i in input().split()])

count = 0

for i in range(N):
  for j in range(i+1,N):
    check_num = 0
    for k in range(len(X[i])):
      check_num += (X[i][k] - X[j][k])**2

    if float.is_integer(math.sqrt(check_num)):
      count += 1

print(count)

Solution (Python):
import math
n,d=map(int,input().split())
x=[list(map(int,input().split())) for _ in range(n)]
s=0
for i in range(n):
  for j in range(n):
    if i<=j:continue
    s+=math.sqrt(sum([(y-z)**2 for y,z in zip(x[i],x[j])])).is_integer()
print(s)

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

Solution (Python):
import math

N,D = map(int,input().split())

if D == 1:
    list_nd = [int(input()) for i in range(N)]
    print(N*(N-1)//2)


else:
    list_ND = [list(map(int,input().split())) for i in range(N)]

    count = 0

    for i in range(N):
        for j in range(i+1,N):
            s = 0

            for k in range(D):
                s += (list_ND[i][k] - list_ND[j][k])**2
    
            s = math.sqrt(s)

            if s.is_integer():
                count += 1

    print(count)

Solution (Python):
import math
a,b=map(int,input().split())
c=[[int(i) for i in input().split()] for i in range(a)]


count=0
sum1=0
sum1=0
for i in range(a):
    for z in range(i+1,a,1):
        for j in range(b):
            sum1+=(c[i][j]-c[z][j])**2
        
        if math.sqrt(sum1)%1.0==0:
            count+=1
        sum1=0
print (count)

Solution (Python):
import numpy as np

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

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

Solution (Python):

import math
def dist(x,y):
  result=0;
  for i in range(len(x)):
    result+=(x[i]-y[i])*(x[i]-y[i])
  return result
def isSquare(x):
  s=int(math.sqrt(x))
  return s*s==x

N,D=[int(i) for i in input().split()];
X=[[int(i) for i in input().split()]for j in range(N)];
ans=0;
for i in range(N):
  for j in range(i+1,N):
    if(isSquare(dist(X[i],X[j]))):
      ans+=1
print(ans)

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

dist=0
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        for k in range(d):
            dist+=(a[i][k]-a[j][k])**2
        dist=dist**0.5
        if(dist.is_integer()==True):
            ans+=1
        dist=0
print(ans)

Solution (Python):
import math

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

b = 0
ans = 0
for i in range(n):
  for j in range(i+1,n):
    for k in range(d):
      b+= (a[i][k] - a[j][k])**2
      
    b= math.sqrt(b)
    
    if b%1==0:
      ans += 1
    b = 0
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):
    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):
n,d=map(int,input().split())
X=[list(map(int,input().split())) for _ in range(n)]
c=0
for i in range(n-1):
    for j in range(i+1,n):
        for k in range(d):
            diff = sum([(s-t)**2 for s,t in zip(X[i],X[j])])
        if (diff**.5).is_integer():c += 1
print(c)

Solution (Python):


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-1):
    for j in range(i+1,N):
        temp=0
        for k in range(D):
            
            temp+=(X[i][k]-X[j][k])**2
        if temp**0.5==(temp**0.5)//1:
            ans+=1
            
            
print(ans)

Solution (Python):
n,d=map(int,input().split())
X=[list(map(int,input().split())) for _ in range(n)]
c=0
for i in range(n-1):
    for j in range(i+1,n):
        for k in range(d):
            diff = sum([(s-t)**2 for s,t in zip(X[i],X[j])])
        if (diff**.5).is_integer():c += 1
print(c)

Solution (Python):
import math

N,D=map(int,input().split())

x=[]
s=0
cnt=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):
    for k in range(D):
      s+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k])
    s=math.sqrt(s)
    
    if s==int(s):
      cnt+=1
    s=0
print(cnt)

Solution (Python):
def main():
    def dist(c1, c2):
        cur = 0
        for x1, x2 in zip(c1, c2):
            cur += (abs(x1-x2))**2
        return sqrt(cur)
    from math import sqrt
    N, D = (int(i) for i in input().split())
    c = [[int(i) for i in input().split()] for j in range(N)]
    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            if dist(c[i], c[j]).is_integer():
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n,d=map(int,input().split())
X=[]
diff=0
c=0
for _ in range(n):
    X.append(list(map(int,input().split())))
for i in range(n-1):
    for j in range(i+1,n):
        for k in range(d):
            diff += (X[i][k]-X[j][k])**2
        if (diff**.5).is_integer():c += 1
        diff=0
print(c)

Solution (Python):
N,D=map(int, input().split())
X=[list(map(int,input().split())) for i in range(N)]
from itertools import permutations, combinations,combinations_with_replacement,product

def dist(X,Y,D):
  ans = 0
  for i in range(D):
    ans += (X[i]-Y[i])**2
  ans = ans ** 0.5
  return ans

L = combinations(range(N), 2)
cnt = 0
for i in L:
  if (dist(X[i[0]],X[i[1]],D)).is_integer():
    cnt +=1
print(cnt)

Solution (Python):
import math
def resolve():
    n, d = list(map(int, input().split()))
    x = [list(map(int, input().split())) for _ in range(n)]
    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            d = math.sqrt(sum([(y-z)**2 for y,z in zip(x[i],x[j])]))
            if d.is_integer():
                ans += 1
    print(ans)
resolve()

Solution (Python):
n,d=map(int,input().split())
X=[[]*d for i in range(n)]
for i in range(n):
  X[i]=list(map(int,input().split()))
b=0
for i in range(n-1):
  for j in range(i+1,n):
    a=0
    for k in range(d):
      a=a+(X[i][k]-X[j][k])**2
      a=float(a)
    if a**(1/2)==int(a**(1/2)):
      b=b+1
print(b)

Solution (Python):
n,d=map(int,input().split())
x=[list(int(i) for i in input().split()) for _ in range(n)]
dis=0
ans=0
for i in x:
  for j in x:
    for k in range(d):
      dis+=(i[k]-j[k])*(i[k]-j[k])
    if dis**0.5%1==0:
      ans+=1
    dis=0
ans-=n
print(ans//2)

Solution (Python):

import sys
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')

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

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



ans = 0

import math

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





print(int(ans/2))

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

import numpy as np    

correct = 0

for i in range(N-1):
    for j in range(i+1 , N):
        x = np.array(X[i])
        y = np.array(X[j])
        z = sum(np.power((x - y), 2)) ** (1/2)
        
        if z % 1 == 0:
            correct += 1
    
print(correct)

Solution (Python):
import numpy as np

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

count = 0

for i in range( N-1 ):
    for j in range( i+1 , N ):
        distance = ( np.sum( ( X[i] - X[j] ) ** 2 ) ) ** ( 1/2 )
        if int(distance) == distance:
            count += 1
print(count)

Solution (Python):
import sys
input = sys.stdin.readline


def distance(X1, X2):
    r = 0
    for i in range(len(X1)):
        r += (X1[i] - X2[i]) ** 2
    return r ** 0.5


def main():
    N, D = map(int, input().split())
    X = [None for i in range(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):
            r = distance(X[i], X[j])
            if r.is_integer():
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
count = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        r = 0
        for k in range(D):
            r += (X[i][k] - X[j][k]) ** 2
        if r ** 0.5 % 1 == 0:
            count += 1
print(count)

Solution (Python):
import math
n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
l = []
for a in range(n-1):
        for b in range(a+1, n): 
                r = 0 
                for c in range(d):
                        r += (x[a][c] - x[b][c])**2
                l.append(math.sqrt(r))
print(sum(i.is_integer() for i in l))

Solution (Python):
import numpy as np

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

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

cnt = 0

for i in range(n-1):
    for j in range(i+1,n):
        total = 0
        
        
        for k in range(d):
            dis = (x[i][k] - x[j][k]) ** 2
            total += dis
        tdis = np.sqrt(total)
        idis = int(np.sqrt(total))
        if tdis == idis:
        
        
            cnt += 1

print(cnt)

Solution (Python):
import math

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

ND = list(map(int,input().split()))
N=ND[0]
D=ND[1]
X = [list(map(int,input().split())) for l in range(N)]
cnt=0
for i in range(N-1):
     for j in range(i+1,N):
         summary=0
         for k in range(D):
             summary=summary+(X[i][k]-X[j][k])*(X[i][k]-X[j][k])
         distance=math.sqrt(summary)
         if is_integer_num(distance):
             cnt=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)]
buf_1 = 0
buf_2 = 0

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

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

x = [[]] * n

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

ans = 0

for i in range(n-1):
  std_vertex = x[i]
  for j in range(i+1, n):
    other_vertex = x[j]
    tmp = 0
    for dim in range(d):
      tmp += (std_vertex[dim] - other_vertex[dim]) ** 2
    dist = math.sqrt(tmp)
    
    
    if dist % 1 == 0:
      ans += 1
  


print(ans)

Solution (Python):
import math
import itertools
N, D = map(int, input().split())

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

com = itertools.combinations(nums, 2)
ans =0
for c in com: 
    d = 0
    for y, z in zip(c[0], c[1]):
        d += abs(y - z) ** 2
    d = math.sqrt(d)
    ans += 1 if d == int(d) else 0

print(ans)