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 = map(int,input().split())

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


count = 0
for i in range(N):
	for j in range(N):
		if i >= j:
			continue
		
		tmp = 0
		for d in range(D):
			
			tmp += ((Xss[i][d]-Xss[j][d])**2)
			
		tmp = tmp**(1/2)
		
		
		if float.is_integer(tmp):
			count += 1
			
print(count)

Solution (Python):
N,D = map(int,input().split())
x = [[int(i) for i in input().split()] for i in range(N)]
count = 0
for i in range(N-1):
    for j in range(i+1,N):
        list_c = [(x2-x1)**2 for (x2,x1) in zip(x[j],x[i])]
        a=sum(list_c)**0.5
        if a.is_integer() == True:
            count += 1
print(count)

Solution (Python):
n,d = [int(_) for _ in input().split()]
x = [[int(_) for _ 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
        for k in range(1,200):
            if dist == k**2:
                ans += 1
                break
        dist = 0
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()))

chk = 0
cnt = 0


for i in range(n-1):
    for k in range(i+1,n):
        for j in range(d):
            
            chk += (abs(x[i][j]-x[k][j]))**2
        chk = chk**0.5
        
        if chk.is_integer():
            cnt+=1
        chk = 0

print(cnt)

Solution (Python):
import math

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

c = 0

for i in range(n):
    for j in range(i+1, n):
        s = sum([(y - z)**2 for (y, z) in zip(x[i], x[j])])
        if int(math.sqrt(s))**2 == s:
            c += 1
print(c)

Solution (Python):
import math
def calc(aL, bL):
  des2 = 0
  for (a, b) in zip(aL, bL):

    des2 += abs(a-b) * abs(a-b)
  return math.sqrt(des2)

n, d = map(int, input().split())
aList = list()
for _ in range(n):
  if d != 1:
    aList.append(list(map(int, input().split())))
  else:
    aList.append(int(input()))
  
count = 0
for aIdx in range(0, len(aList)):
  for bIdx in range(aIdx+1, len(aList)):

    if aIdx == bIdx:
      continue
    if d != 1:
      des = calc(aList[aIdx], aList[bIdx])
    else:
      des = math.sqrt(abs(aList[aIdx] - aList[bIdx])*(abs(aList[aIdx] - aList[bIdx])))
    if des % 1 == 0:
      count += 1
print(count)

Solution (Python):
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):
        diff = 0
        for k in range(D):
            diff += (X[i][k] - X[j][k])**2
        if (diff**(1/2)).is_integer():
            count += 1
print(count)

Solution (Python):
def f(a):

	return a**0.5==int(a**0.5)

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

def g(a,b):

	ret=0

	for i in range(0,d):

		ret+=(a[i]-b[i])**2

	return ret

	

	

ans=0

a=[]

for i in range(0,n):

	a.append(list(map(int,input().split())))

	for j in range(0,i):

		if f(g(a[i],a[j])):

			ans+=1

print(ans)

Solution (Python):
import math

a,b = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(a)]
co = 0
for i in range(0,a-1):
    for j in range(i+1,a):
        t = 0
        for k in range(b):
            t += pow(abs(l[i][k]-l[j][k]),2)
        if(math.sqrt(t).is_integer()):
            co = co+1

print(co)

Solution (Python):
def f(D, Y, Z):
    temp = 0
    for i in range(D):
        temp+= (Y[i]-Z[i])**2
    return temp**(1/2)

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

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

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        if f(D, axis[i], axis[j]).is_integer():
            cnt+=1

print(cnt)

Solution (Python):
import sys
import math
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
ra = lambda: list(map(int, sys.stdin.readline().split()))

n, d = ra()
x = []
for i in range(n):
    l = ra()
    x.append(l)

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

print(ans)

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

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

x = [ [] for x in range(n) ]

count = 0

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

for i in range(n):
  for j in range(n)[i+1:]:
    s = 0
    for k in range(d):
      s += (x[i][k] - x[j][k])**2
    r=int(s**0.5)
    if s == r**2 :
      count += 1
print(count)

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

count = 0
distance = 0

for i in range(N-1):
    for j in range(i+1,N):
      distance = 0
      for k in range(D):
        distance += pow(X[i][k] - X[j][k],2)
      distance = math.sqrt(distance)
      f = distance - int(distance)
      if f == 0.0:
        count += 1
            
print(count)

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


def calc(i,j):
    dist2d = [x**2 for x in range(500)]
    ci = field[i]
    cj = field[j]
    dist2 = [(di-dj)**2 for di,dj in zip(ci,cj)] 

    
    if sum(dist2) in dist2d:
        return True
    else:
        return False

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

print(ans)

Solution (Python):

import math

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

count = 0

for i in range(N):
    for j in range(N):
        d = math.sqrt(sum(map(lambda x,y : abs(x-y) * abs(x-y) , X[i],X[j])))
        if d - int(d) == 0 and d != 0.0:
            count += 1
count = count /2

print(int(count))

Solution (Python):
import math

N,D = map(int, input().split())
idx = [list(map(int, input().split())) for i in range(N)]
count = 0
Sum = 0

for i in range(N-1):
    for j in range(i+1,N):
        for k in range(D):
            Sum = Sum + (idx[i][k]-idx[j][k])**2 
        distance = math.sqrt(Sum)
            
        if distance == round(distance):
            count += 1
        Sum = 0

print(count)

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

def calc_distant(p,q):
	sco = 0
	for i in range(d):
		sco += (p[i]-q[i])**2
	return sco

num=[]
for i in range(n-1):
	for j in range(i+1,n):
		num.append(calc_distant(lst[i],lst[j]))

def joukon(m):
	if float.is_integer(m**(0.5)):
		return 1
	else:
		return 0

lust = []
for i in num:
	lust.append(joukon(i))
print(sum(lust))

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

count = 0
sum_max  = (40**2) * d
int_list = [ i**2 for i in range(int(math.sqrt(sum_max))) ]

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

print(count)

Solution (Python):
def distance(a, b, d):
    res = 0
    for i in range(d):
        res += (a[i] - b[i]) ** 2
    res **= 0.5
    return res

n, d = [int(i) for i in input().split()]
dot = []
for i in range(n):
    dot.append([int(i) for i in input().split()])
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        di = distance(dot[i], dot[j], d)
        if abs(int(di) - di) < 0.0001:
            ans += 1
print(ans)

Solution (Python):
import numpy as np
N, D = list(map(int, input().split(' ')))
v = []
for n in range(N):
    v.append(list(map(int, input().split(' '))))
vec = np.array(v)
c = 0
for i in range(N):
    for j in range(i+1, N):
        if np.linalg.norm(vec[i]-vec[j]) % 1 == 0:
            c += 1
print(c)

Solution (Python):
n,d = map(int, input().split())
import numpy as np
import itertools
x = np.array([np.array(list(map(int, input().split()))) for _ in range(n)])
count = 0
for i,j in itertools.combinations(x,2):
  k = np.sqrt(np.sum(np.square(i-j)))
  if k==int(k):
    count += 1
    
print(count)

Solution (Python):
import math

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

count = 0

for i in range(N):
    
    for k in range(i+1,N):
        sum = 0

        for j in range(D):

            sum += (List[i][j] - List[k][j]) ** 2

        result = math.sqrt(sum)

        if result.is_integer() == True:
            count += 1

print(count)

Solution (Python):
import numpy as np
A = []
B = 0
N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
for i in range(N):
  X[i] = np.array(X[i])
for i in range(N):
  for j in range(N):
    if np.linalg.norm(X[i]-X[j]) // 1 == np.linalg.norm(X[i]-X[j]):
      B = B + 1
print((B-N)//2)

Solution (Python):

import math

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


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

res = 0
for i in range(N-1):
    for j in range(i+1, N):
        res = res + (1 if distance(X[i], X[j]).is_integer() else 0)
        
print(res)

Solution (Python):
import sys, math

a = [int(i) for i in input().split()]
N = a[0]
D = a[1]
X = []
for i in range(N):
  tmp = [int(i) for i in input().split()]
  X.append(tmp)

if D == 1:
  print(int(N*(N-1)/2))
  sys.exit(0)

count = 0
for n in range(0,N-1):
  for nn in range(n+1,N):
    result = 0
    for d in range(D):
      tmp = (X[n][d]-X[nn][d])**2
      result+=tmp
    result = math.sqrt(result)
    
    if result.is_integer():
      count+=1;
print(int(count))

Solution (Python):
import itertools

n,d=map(int, input().split()) 
x=[list(map(int, input().split()))  for i in range(n)]
v=[]
a=0
count=0
for i in itertools.combinations(x,r=2):
    for j in range(d):
        a+=(i[0][j]-i[1][j])**2
    v.append(a)
    a=0
c=round(n*(n-1)/2)
for i in range(c):
    if (v[i]**(1/2)).is_integer():
        count+=1
print(count)

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

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

final_ans=0

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

for i in range(0,N-1,1):
    for j in range(i+1,N,1):
        res = 0
        for k in range(0,D,1):
            res = res + (X[i][k] - X[j][k]) ** 2
        res = res ** 0.5
        if is_integer_num(res):
            final_ans = final_ans+1
print(final_ans)

Solution (Python):
import numpy as np


def main():
	n, d = [int(x) for x in input().split()]
	l = []
	for val in range(n):
		l.append([int(x) for x in input().split()])
	a = np.array(l)
	
	l = []
	for i, v1 in enumerate(a):
		for v2 in a[i:]:
			D = np.linalg.norm(v1 - v2)
			l.append(D)
	res = map(lambda x: float.is_integer(x), l)
	print(len([f for f in list(res) if f == True]) - n)

if __name__ == "__main__":
	main()

Solution (Python):
import math as ma

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

  return ma.sqrt(r)

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

ret = 0
for i in range(N):
  for j in range(i+1, N):
    d = dist(X[i], X[j], D)
    if (d == int(d)):
      ret = ret + 1

print(ret)

Solution (Python):
import math

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

x = [[]]*N
for l in range(N):
    x[l] = list(map(int, input().split()))

count = 0
for i in range(N):
    for j in range(i+1, N):
        dis = 0
        for d in range(D):
            dis += (x[i][d] - x[j][d])**2
        if math.sqrt(dis).is_integer():
            count += 1

print(count)

Solution (Python):
from sys import stdin
N, D = [int(x) for x in stdin.readline().rstrip().split()]
X = [stdin.readline().rstrip().split() for _ in range(N)]
count = 0
for i in range(0, N):
    for j in range(i+1, N):
        distance = 0
        for k in range(0, D):
            distance += abs(int(X[i][k]) - int(X[j][k])) ** 2
        distance = distance ** 0.5
        if(distance.is_integer()):
            count += 1
print(count)

Solution (Python):
import itertools
import math
answer = 0
N,D = map(int,input().split())
X_list=[]
for i in range(N):
  X_list.append(list(map(int,input().split())))
for v in itertools.combinations(range(N),2):
  sum_2 = 0
  for j in range(D):
    sum_2 += (X_list[v[0]][j] - X_list[v[1]][j])**2
  if math.sqrt(sum_2).is_integer():
    answer += 1
print (answer)

Solution (Python):



import math

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

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

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

Solution (Python):
n,d = map(int,input().split())
x1,x2,x3,x4,x5,x6,x7,x8,x9,x10 = [],[],[],[],[],[],[],[],[],[]
all_x = [x1,x2,x3,x4,x5,x6,x7,x8,x9,x10]

import math

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


t = 0
for i in range(n):
    for k in range(n):
        if i < k:
            y = 0
            for j in range(d):
                y += (all_x[i][j] - all_x[k][j])**2
            z = math.sqrt(y)
            if z - int(z) == 0:
                t += 1

print(t)

Solution (Python):
import math
n, d = 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-1):
    for j in range(i+1, n):
        dis = 0
        for k in range(d):
            dis += abs(x[i][k] - x[j][k])*abs(x[i][k] - x[j][k])
        a, _ = math.modf(math.sqrt(dis))
        if a == 0:
            ans += 1
print(ans)

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

Solution (Python):
import numpy as np
n,d= map(int,input().split())
a=[]
for i in range(n):
    l=list(map(int,input().split()))
    a.append(l)
ans=0


for j in range(n):
    for k in range(n):
        bb=0
        for l in range(d):
            bb+=abs(a[j][l]-a[k][l])**2
        sq=np.sqrt(bb)
        if sq.is_integer():
            ans+=1
print(int((ans-n)/2))

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

listA=[]
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;

idx1 = 0
cnt = 0
for idx1 in range(N):
  idx2 = idx1 + 1
  for idx2 in range(idx1 + 1 , N):
    idx3 = 0
    dis_sq = 0
    dis = 0
    for idx3 in range(D):
      dis_sq += ( listA[idx1][idx3] - listA[idx2][idx3] )** 2
    dis = float(dis_sq ** (1/2))
    if dis - int(dis) == 0:
      cnt += 1

print(cnt)

Solution (Python):
import math

n, d = map(int, input().split())
x = [tuple(map(int, input().split())) for i in range(n)]
count = 0
for i in range(n):
  for j in range(i+1, n):
    distance = 0
    for k in range(d):
      distance += (x[i][k] - x[j][k]) ** 2
    if math.sqrt(distance).is_integer():
      count += 1

print(count)

Solution (Python):
import numpy as np
import cmath
N, D = map(int,input().split())
zas = []
for i in range(0,N):
    za = input().split()
    zai = [int(s) for s in za]
    zai = np.array(zai)
    zas.append(zai)

count = 0
for j in range(0,N-1):
    for k in range(j+1,N):
        zad = zas[j]-zas[k]
        za2 = zad*zad
        zasq = (np.sum(za2))**0.5
        if(zasq.is_integer()):
            count = count + 1

print(count)

Solution (Python):
import numpy as np

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

count = 0
for i in range(N):
    a = np.array(table[i])
    for j in range(i+1, N):
        b = np.array(table[j])
        u = b - a
        if np.linalg.norm(u).is_integer():
            count += 1

print(count)

Solution (Python):
from sys import stdin
import numpy as np
import itertools
N,D = [int(x) for x in stdin.readline().rstrip().split()]
data = []
for _ in range(N):
    data.append([int(x) for x in stdin.readline().rstrip().split()] + [_])

ans = 0
for j in list(itertools.product(data,repeat=2)):
    tot = 0
    
    for k,l in zip(j[0][:D] , j[1][:D]):
        tot += abs(k-l)**2
        
    if j[0][-1] < j[1][-1]:
        if np.sqrt(tot).is_integer():
            ans += 1
print(ans)

Solution (Python):
import math
z=[]
ans=0
sumsum=0
N,D=(int(x) for x in input().split())
for i in range(N):
    a=input().split()
    
    z.append(a)


for i in range(N):
    for j in range(i,N):
        for k in range(D):
            sumsum=sumsum+(int(z[i][k])-int(z[j][k]))**2
        if sumsum!=0 and math.sqrt(sumsum)%1==0:
            ans=ans+1
        sumsum=0

print(ans)

Solution (Python):




from sys import stdin
import math
N,D  = [int(x) for x in stdin.readline().rstrip().split()]

all_point = []
total_sq = 0
cnt = 0

for i in range(N):
    X  = [int(x) for x in stdin.readline().rstrip().split()]
    all_point.append(X)

for i in range(N):
    for j in range(i+1,N):
        total_sq = 0
        for k in range(D):
            total_sq += (all_point[i][k] - all_point[j][k])**2
        distance = math.sqrt(total_sq)
        if math.floor(distance) == math.ceil(distance):
            cnt += 1

print(cnt)

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

list = []
for i in range(N):
    list.append(input().split(" "))

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

print(count)

Solution (Python):
import math

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

ans=0

for i in range(n-1):
    for k in range(i+1,n):
        temp=0.0
        for j in range(d):
            temp+=(dl[i][j]-dl[k][j])*(dl[i][j]-dl[k][j])
        tempr=math.sqrt(temp)
        if tempr.is_integer():
            ans+=1

print(ans)

Solution (Python):
import numpy as np
N, D = map(int, input().split())
X = [0] * N 
counter = 0

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

for i in range(N):
  for j in range(N):
    distance = np.linalg.norm(X[i] - X[j])
    if distance.is_integer():
      counter += 1

print(int((counter-N)/2))

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

Solution (Python):


import math






def func(I,J,D):
    tmp = 0
    for x in range(D):
        tmp = tmp + (I[x]-J[x]) * (I[x]-J[x])
    return tmp

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


ans = 0
tmp = 0
for i in range(N):
    for j in range(i+1,N):
        if float.is_integer(math.sqrt(func(X[i],X[j],D))):
            ans = ans+1

print(ans)

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

count=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 math.floor(math.sqrt(dist))**2 == dist:
            count+=1
print(count)

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

mylist = []
for i in range(N):
  mylist += [input().split()]

cnt = 0
for i in range(0, N):
  for j in range(0, N):
    if i != j and i < j:
      mysum = 0
      for k in range(D):
        mysum += (int(mylist[i][k])-int(mylist[j][k]))**2
      
      if (math.sqrt(mysum)).is_integer():
      	cnt += 1
print(cnt)

Solution (Python):
import numpy as np

list1 = list(map(int, input().split())) 
s = [list(map(int, input().split()))  for i in range(list1[0])]

dist = 0
num = 0

for a in range(list1[0]):
    for b in range(a+1,list1[0]):
        X = np.array(s[a])
        Y = np.array(s[b])
        dist = np.linalg.norm(X-Y, ord=2)
        if (dist.is_integer()):
            num = num + 1

print(num)

Solution (Python):
import math
N,D = [int(i) for i in input().split()]
X = [input().split() for i in range(N)]
cnt = 0
for i in range(N-1):
    for j in range(i+1,N):
        d = 0
        for k in range(D):
            d += (int(X[i][k])-int(X[j][k]))**2
        d = math.sqrt(d)
        if d%1==0:
            cnt+=1
print("{}".format(cnt))

Solution (Python):
from sys import stdin
import math
 

N, D = [int(x) for x in stdin.readline().rstrip().split()]

X = []
x = []
for i in range(0, N):
    x = [int(x) for x in stdin.readline().rstrip().split()]
    X.append(x)

count = 0
for i in range(0,N-1):
    for j in range(i+1,N):
        leng = 0
        for k in range(0,D):
            dist = X[i][k] - X[j][k]
            leng += (dist*dist)
        if leng == 1:
            count += 1
        else:
            for n in range(1,leng):
                if leng == n*n:
                    count += 1

    
print(count)

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

import numpy as np
def dist(X, Y, D):
    s2 = 0
    for i in range(D):
        s2 += (X[i] - Y[i]) * (X[i] - Y[i])
    s1 = int(np.sqrt(s2))
    if s2 == s1 * s1:
        return True
    return False

c = 0
for i in range(N):
    for j in range(i+1, N):
        if dist(data[i], data[j], D):
            c += 1
print("{}".format(c))

Solution (Python):
def distance(a, b):
    s = 0
    for i in range(len(a)):
        s += (a[i] - b[i]) ** 2

    return s ** 0.5

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

X = []

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

count = 0

for i in range(N):
    for j in range(i+1, N):
        if distance(X[i], X[j]).is_integer():
            count += 1

print(count)

Solution (Python):
n, d = map(int, input().split())
l = []
for _ in range(n):
    li = list(map(int, input().split()))
    l.append(li)
ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        dis = 0
        for di in range(d):
            dis += abs(l[j][di] - l[i][di]) ** 2
        dis_t = dis ** 0.5
        if dis_t.is_integer():
            ans += 1
print(ans)

Solution (Python):
import math

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

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

print(count)

Solution (Python):
import bisect
import sys
import math

verbose = False


def get_iv():
    args = sys.stdin.readline()
    argv = args.split()
    iargv = [int(arg) for arg in argv]
    return iargv


def get_fv():
    args = sys.stdin.readline()
    argv = args.split()
    iargv = [float(arg) for arg in argv]
    return iargv


def calc_dist(Lhs, Rhs):
    dist = 0
    for off in range(len(Lhs)):
        dx = Lhs[off] - Rhs[off]
        dist += dx * dx
    dist = math.sqrt(dist)
    return dist


def is_int(fl):
    ifl = int(fl + .5)
    df = abs(ifl - fl)
    return df < 1e-4


def num_sqare(N, X):
    rv = 0
    for i in range(N):
        for j in range(i + 1, N):
            dist = calc_dist(X[i], X[j])
            if is_int(dist):
                rv += 1
    return rv


def main():
    specs = get_iv()
    N = specs[0]
    D = specs[1]
    X = []
    for i in range(N):
        v = get_iv()
        X.append(v)
    rv = num_sqare(N, X)
    print(rv)


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
N, D = [int(i) for i in input().split()]

list_coord = list()
for i in range(N):
  list_coord.append([int(i) for i in input().split()])
arr_coord = np.array(list_coord)

cnt = 0
for i in range(N):
    for j in range(N-i-1):
        a = np.array(list_coord[i])
        b = np.array(list_coord[N-j-1])
        dist = (abs(np.sum((a-b)**2)))**0.5
        
        if dist.is_integer():
            cnt+=1
            
print(cnt)

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

Solution (Python):
def main():
  sum=0
  N,D=map(int,input().split())
  box=[]
  for i in range(N):
    box.append(list(map(int,input().split())))
  for i in range(N):
    for j in range(i+1,N):
    	sum+=check(box[i],box[j])
  print(sum)

def check(a,b):
  sum=0
  for i in range(len(a)):
    sum+=(a[i]-b[i])**2
  sum=sum**(1/2)
  if sum%1==0:
    return 1
  else:
    return 0
main()

Solution (Python):
import itertools

def kyori(Y,Z):
    sum = 0
    for i in range(D):
        sum+= (Y[i]-Z[i])**2
    return pow(sum,0.5)

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

candidList = list(itertools.combinations(X,2))
ans=0
for cand in candidList:
    if float.is_integer(kyori(cand[0],cand[1])):
        ans+=1
    else:
        continue

print(ans)

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

row = list()
count = 0
for i in range(N):
  x = [int(_) for _ in input().split()]
  if i == 0:
    row.append(x)
  else:
    for j in range(len(row)):
      dist = 0
      for k in range(D):
        dist += (row[j][k]-x[k])**2
      if (dist**0.5)-int(dist**0.5)==0:
      	count += 1
    row.append(x)
      
print(count)

Solution (Python):

import numpy

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

points = []
for i in range(n):
    p = [int(c) for c in input().split(' ')]
    points.append(p)

num_int = 0

for i in range(n):
    for j in range(n):
        if i != j:
            y = numpy.array(points[i])
            z = numpy.array(points[j])
            
            u = y - z
            
            dist = numpy.linalg.norm(u)

            if dist.is_integer():
                num_int += 1

print(num_int // 2)

Solution (Python):
from sys import stdin
import numpy as np
import math

N, D = [int(x) for x in stdin.readline().rstrip().split()]

X = list()
for y in range(N):
    X.append([int(z) for z in stdin.readline().rstrip().split()])

count = 0

for i in range(N):
    for j in range(N):
        if i >= j:
            continue
            
        
        
        s = sum((X[i][d] - X[j][d])**2 for d in range(D))
        distance = math.sqrt(s)

        
        if distance.is_integer():
            count += 1

print(count)

Solution (Python):
from math import sqrt

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

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

result = 0

for i in range(n):
    for j in range(i + 1, n):
        distance = 0
        for k in range(d):
            distance += abs(x[i][k] - x[j][k]) ** 2
        else:
            if distance == 0 or sqrt(distance).is_integer():
                result += 1

print(result)

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

def dist(arr1,arr2):
    tmp = 0
    for i in range(D):
        tmp += (arr1[i] - arr2[i])**2

    return math.sqrt(tmp)

for i in range(N):
    array.append(list(map(int,input().split())))

count = 0
for i in range(N-1):
    for j in range(i+1,N):
        a = dist(array[i],array[j])
        if a//1 == a:
            count += 1

print(count)

Solution (Python):
import numpy as np
N, D, = map(int, input().split())

points = []
tmp_p  = []

for i in range(N):
    tmp_p = list(map(int, input().split()))
    points.append(tmp_p)

points_arr = np.array(points)



param_result = 0
for param_start in range(N):
    

    for param_end in range(N):

        if  param_start >= param_end:
            
            
            
            pass

        else:
            
            

            dist = points_arr[param_start,] - points_arr[param_end,]
            res = np.linalg.norm(dist)
            

            if res.is_integer() is True:
                
                param_result += 1
            else:
                
                pass

print(param_result)

Solution (Python):
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):
        x_diff = []
        for k in range(len(x[i])):
            x_diff.append(x[i][k]-x[j][k])
        sq_x_diff = [i ** 2 for i in x_diff]
        sum_ = sum(sq_x_diff)**0.5
        if sum_.is_integer():
            cnt += 1
print(cnt)

Solution (Python):

import numpy as np

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

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

ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        dis = np.array(xl[i])-np.array(xl[j])
        squ = np.square(dis)
        su = np.sum(squ)
        sqr = np.sqrt(su)
        if sqr.is_integer():
            ans += 1

print(ans)