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 numpy as np

N, D = map(int, input().split())
X = [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):
        dist = np.linalg.norm(np.array(X[i]) - np.array(X[j]))
        if dist % 1 == 0:
            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)]
ans = 0

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


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

    return math.sqrt(sqr_length)


lengthes = list()

for i in range(n-1):
    p = x[i]
    for j in range(i+1, n):
        q = x[j]

        lengthes.append(calc_length(d, p, q))

ans = 0
for i in range(len(lengthes)):
    if isinstance(lengthes[i], int):
        ans += 1
    else:
        if lengthes[i].is_integer():
            ans += 1


print(ans)

Solution (Python):
import math

n, d = map(int, input().split())
x = [[0]*d for _ in range(n)]
ans = 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):
    count = 0
    for k in range(d):
      count += (x[i][k]-x[j][k])**2
    if math.sqrt(count).is_integer():
      ans += 1

print(ans)

Solution (Python):
perfect_squares = set(i**2 for i in range(1, 128))

n, d = (int(x) for x in input().split())
points = []
for _ in range(n):
  points.append([int(x) for x in input().split()])
ans = 0
for i in range(n-1):
  for j in range(n-i-1):
    nn = 0
    for dim in range(d):
        nn += (points[i][dim] - points[j+1+i][dim]) ** 2
    if nn in perfect_squares:
        ans += 1
print(ans)

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

Solution (Python):
import math

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

    count = 0
    array = []
    for i in range(n):
        array.append([int(x) for x in input().split()])

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


if __name__ == '__main__':
    main()

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

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


res=0

for i in range(N):
        for j in range(i+1,N):
                dist=0
                for d in range(D):
                        dist += (S[i][d] - S[j][d])**2

                if (dist ** 0.5).is_integer():
                        res+=1


print(res)

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

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

Solution (Python):
def calc(y,z):
    flag=0
    LL=0
    for i in range(D):
        LL +=(y[i] - z[i])**2
    L =LL**0.5
    if L == int(L) :
        flag=1
    return(flag)


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

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

    cnt=0
for i in range(N-1):
        for j in range(i+1,N):
                cnt += calc(X[i],X[j])
                
print(cnt)

Solution (Python):
N,D=map(int,input().split())
L=[list(map(int,input().split())) for i in range(N)]
n=0
for i in range(N):
  for j in range(i):
    DD=0
    for k in range(D):
      DD+=(L[i][k]-L[j][k])**2
    if any(n**2==DD for n in range(1,128)):
      n+=1
print(n)

Solution (Python):
import sys

def solve():
    n,d = map(int, input().split())
    l = [list(map(int, X.split())) for X in sys.stdin.readlines()]
    count = 0
    for i in range(n):
        Y = l[i]
        for Z in l[i+1:]:
            total = 0
            for y,z in zip(Y,Z):
                total += (y-z)**2
            d = total**0.5
            if d == int(d):
                count += 1
    return count

if __name__ == '__main__':
    print(solve())

Solution (Python):
def solve():
    n,d = map(int, input().split())
    l = [[int(x) for x in input().split()] for _ in range(n)]
    count = 0
    for i in range(n):
        Y = l[i]
        for Z in l[i+1:]:
            total = 0
            for y,z in zip(Y,Z):
                total += (y-z)**2
            d = total**0.5
            if d == int(d):
                count += 1
    return count

if __name__ == '__main__':
    print(solve())

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

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

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

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

print(dist_int)

Solution (Python):
n,d=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]
def l1(a,b,d):
    s=0
    for i in range(d):
        s+=(a[i]-b[i])**2
    return s**0.5
cnt=0
for i in range(n):
    for j in range(i,n):
        
        if l1(x[i],x[j],d)!=0 and l1(x[i],x[j],d)%1==0:
            cnt+=1
print(cnt)

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

Solution (Python):
def solve():
    n,d = map(int, input().split())
    L = [[int(x) for x in input().split()] for _ in range(n)]
    count = 0
    for i in range(n):
        y = L[i]
        for z in L[i+1:]:
            total = 0
            for a,b in zip(y,z):
                total += (a-b)**2
            if total**0.5 == int(total**0.5):
                count += 1
    return count
    
if __name__ == '__main__':
    print(solve())

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

ans = 0
for i in range(N):
    for j in range(i+1, N):
        s = 0
        for d in range(D):
            s += (array[i][d]-array[j][d]) ** 2
        if s ** (1/2) % 1 == 0:
            ans += 1

print(ans)

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

count = 0
for i in range(len(X)):
	for j in range(i + 1, len(X)):
		power = 0
		for idx in range(len(X[i])):
			power += (X[i][idx] - X[j][idx])**2
		if(abs(int(math.sqrt(power))**2 - power ) < 0.001):
			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)]
ans=0
for i in range(1,N+1):
    x=0
    for j in range(i,N):

        x=sum(list(map(lambda x,y:(x-y)**2,X[i-1],X[j])))
        if math.sqrt(x)==int(math.sqrt(x)):
            ans+=1


        
print(ans)

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(0,N):
    for j in range(0,N):
        if i >= j:
            pass
        else:
           dif = [(y-x)**2 for (x,y) in zip(X[i],X[j])]
           J = sum(dif)**(1/2)
           if J.is_integer():
               cnt += 1
print(cnt)

Solution (Python):
n,d=(int(x) for x in input().split())
x=[ [int(x) for x in input().split()] for i in range(n)]
c=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
    dis=sum**0.5
    if dis.is_integer():
      c+=1
print(c)

Solution (Python):
import numpy as np

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

for n in range(N):
    L = list(map(int, input().split()))
    X.append(L)
X = np.array(X)
ans = -N

def distance(np_1, np_2):
    dif = np_1 - np_2
    dif_sq = np.square(dif)
    dist_sq = np.sum(dif_sq)
    dist = np.sqrt(dist_sq)
    return dist


for n in range(N):
    for i in range(n,N):
        x = distance(X[n], X[i])

        if x.is_integer():
            ans += 1

print(ans)

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

from math import sqrt
b = []
for i in range(0,N):
  b.append([int(x) for x in input().split()])


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

cnt = 0
for l in range(0,N-1):
  for k in range(l+1,N):
    if distance(b[l],b[k],D)-int(distance(b[l],b[k],D))==0:
      cnt += 1
print(cnt)

Solution (Python):
import math as m

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

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

print(ans)

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

X = [[0 for i in range(D)]for j in range(N)]

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

cnt = 0
for i in range(N):
	for j in range(i+1, N):
		lo = 0
		for k in range(D):
			lo += (X[j][k] - X[i][k])**2
		k = 0
		while k <= lo:
			if k*k == lo:
				cnt += 1
			k += 1

print(cnt)

Solution (Python):
import math
n, d = map(int, input().split())
x = [[int(e) for e in input().split()] for _ in range(n)]
result = 0
for i in range(n - 1):
  for j in range(i + 1, n):
    t = math.sqrt(sum((x[i][k] - x[j][k]) * (x[i][k] - x[j][k]) for k in range(d)))
    if t == math.ceil(t):
      result += 1
print(result)

Solution (Python):
import numpy as np

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

X = np.atleast_3d(X)
L = np.linalg.norm(X - X.T, axis=1)
c = (np.count_nonzero(L == L.astype(int)) - N) // 2

print(c)

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

Solution (Python):
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):
        d=sum((t[0]-t[1])**2 for t in zip(X[i],X[j]))
        for k in range(int(d**0.5)+1):
            if k**2==d:
                cnt+=1
print(cnt)

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

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-1):
    for j in range(i+1,n):
        d2=0
        for l in range(d):
            d2+=(x[i][l]-x[j][l])**2
        d2=int(d2)
        for k in range(1,d2//2+2):
            if d2==k**2:
                ans+=1
                break
 
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-1):
    for j in range(i+1,n):
        d2=0
        for l in range(d):
            d2+=(x[i][l]-x[j][l])**2
        d2=int(d2)
        for k in range(1,d2//2+2):
            if d2==k**2:
                ans+=1
                break

print(ans)

Solution (Python):
import math
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):
            c=0
            for k in range(d):
                  c+=(x[i][k]-x[j][k])**2
            if math.sqrt(c)==int(math.sqrt(c)):
                  count+=1
print(count)

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

Solution (Python):
n,d=map(int,input().split())
ans=0
x=[]
y=[]
check=0
e=0
for i in range(n):
    x.append(input())
    x[i]=x[i].split()
    for j in range(d):
        x[i][j]=int(x[i][j])
for z in range(1,n):
    for l in range(n-z):
        for k in range(d):
            e=x[l][k]-x[l+z][k]
            check+=e**2
        q=int(check**0.5)
        if q**2==check:
            ans+=1
            check=0
        else:
            check=0
print(ans)

Solution (Python):
import math


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

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


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

print(ans)

Solution (Python):
n,d = map(int,input().split())
x = [[int(e) for e in input().split()] for _ in range(n)]
count = 0
for i in range(n):
  for j in range(i+1,n):
    kyori = 0
    for k in range(d):
      kyori += (x[i][k]-x[j][k])**2
    for h in range(1,kyori+1):
      if (h*h==kyori):
        count += 1
        break
print(count)

Solution (Python):
import sys
import math
def input():
    return sys.stdin.readline()[:-1]

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

X = []

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

def nolm(x, y):
    s = len(x)
    total = 0
    for i in range(s):
        total += (x[i] - y[i]) ** 2
    return math.sqrt(total)

ans = 0

for n in range(N-1):
    for i in range(n+1, N):
        if nolm(X[n], X[i]).is_integer():
            ans += 1

print(ans)

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

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

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

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

Solution (Python):
line = input()

N = int(line.split()[0])
D = int(line.split()[1])

matrix = []
for dim_cnt in range(N):
    line = input()
    vector = []
    for cnt in range(D):
        elm = int(line.split()[cnt])
        vector.append(elm)
    matrix.append(vector)

check_list = []
for i in range(N-1):
    for elm in range(N-i-1):
        j = i + elm + 1
        check_list.append((i, j))

int_cnt = 0
for check_point in check_list:
    i_vector = matrix[check_point[0]]
    j_vector = matrix[check_point[1]]
    sq_sum = 0
    for dim_cnt in range(D):
        sq_elm = (i_vector[dim_cnt] - j_vector[dim_cnt])**2
        sq_sum = sq_sum + sq_elm
    dist = sq_sum**0.5
    if dist.is_integer():
        int_cnt += 1
print(int_cnt)

Solution (Python):
n, d = map(int,input().split())
x = [list(map(int, input().split())) for _ in range(n)]
dist = lambda y, z : sum([(y_ - z_)**2 for y_,z_ in zip(y, z)]) ** 0.5
ret = 0
for i in range(n-1):
    for j in range(i+1, n):
        if i==j:
            continue
        distance = dist(x[i], x[j])
        if distance - int(distance)==0:
            ret += 1
print(ret)

Solution (Python):
import math


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


n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
cnt = 0
for i in range(n):
    for k in range(n):
        if i < k:
            dis = 0
            for j in range(d):
                dis += abs(x[i][j] - x[k][j])**2
            jud = math.sqrt(dis)
            if is_integer_num(jud):
                cnt += 1
print(cnt)

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

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

print(cnt)

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

def dist(y,z):
    tmp = 0
    for k in range(D):
        tmp += (y[k] - z[k])**2
    return (tmp**0.5).is_integer()

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        if dist(X[i], X[j]):
            ans += 1

print(ans)

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

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

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

print(ans)

Solution (Python):
N ,D = map(int, input().split())
X = []
tmp = []
ans = []
fans = 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):
        if D == 1:
            tmp.append((X[i][0]-X[j][0])**2)
        else:
            for k in range(D):
                tmp.append((X[i][k]-X[j][k])**2)
        ans.append(sum(tmp)**0.5)
        tmp = []
for A in ans:
    if A.is_integer():
        fans += 1
print(fans)

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):
    for j in range(N-i-1):
        s=0
        for I,J in zip(X[i],X[j+i+1]):
            s+=(I-J)**2
        if (int(s**.5))**2 == s:
            ans+=1
print(ans)

Solution (Python):
import sys
import math
N, D = map(int, sys.stdin.readline().split())
L = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

cnt = 0
for i in range(N-1):
    for ie in range(i+1, N):
        tmp = 0
        for j in range(D):
            tmp +=(L[i][j] - L[ie][j])**2
        if math.sqrt(tmp) == int(math.sqrt(tmp)):
            cnt +=1
print(cnt)

Solution (Python):
import numpy as np

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

X = []
X = np.vstack([input().split() for i in range(N)])

count = 0

for i in range(N - 1):
  for j in range(N - (i + 1)):
    r = 0
    for k in range(D):
      r += (int(X[i, k]) - int(X[i + (j + 1), k])) ** 2
  
    if np.sqrt(r).is_integer():
      count += 1
    
print(count)

Solution (Python):
import itertools

n, d = map(int, input().split())
xs = [list(map(int, input().split())) for _ in range(n)]
sq_num = set([i**2 for i in range(128)])

cnt = 0
for x1, x2 in itertools.combinations(xs, 2):
    distance_sq = sum(map(lambda xx: (xx[0]-xx[1])**2, zip(x1, x2)))
    if distance_sq in sq_num:
        cnt += 1
print(cnt)

Solution (Python):
from math import sqrt

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

l = []
result = 0

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

for i in range(N):
  for j in range(i + 1, N):
    dist = sqrt(sum( [(l[i][d] - l[j][d]) ** 2 for d in range(D)] ))
    if(dist % 1 == 0):
      result += 1
  
print(result)

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

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):
        dist = 0
        for d in range(D):
            dist += (X[i][d]-X[j][d])*(X[i][d]-X[j][d])
        for r in range(1, 200):
            if dist == r*r:
                ans += 1
                break

print(ans)

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n, d = list(map(int, input().rstrip('\n').split()))
    x = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    cnt = 0
    for i1, v1 in enumerate(x):
        for i2, v2 in enumerate(x):
            if i1 < i2:
                t = 0
                for i in range(d):
                    t += (abs(v1[i] - v2[i]) ** 2)
                if t ** 0.5 == int(t ** 0.5):
                    cnt += 1
    print(cnt)


if __name__ == '__main__':
    slove()

Solution (Python):
n,d = map(int, input().split())
xd = [(list(int(_) for _ in input().split())) for i in range(n)]
ans =0
for i in range(n):
  x1 = xd[i]
  for j in range(i+1,n):
    x2 = xd[j]
    dis =0
    for x,y in zip(x1,x2):
      dis += (y-x) **2
    k = dis **0.5

    if int(k)**2 ==dis:
      ans +=1
print(ans)

Solution (Python):
n, d = (int(x) for x in input().split())
X = [[int(x) for x in input().split(" ")] for _ in range(n)]
ans = 0
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 (s ** 0.5).is_integer(): ans += 1
print(ans)

Solution (Python):
n, d = (int(x) for x in 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(n - i - 1):
        dis_sq = 0
        for k in range(d):
            dis_sq += (X[i][k] - X[i+j+1][k]) ** 2
        dis = dis_sq ** 0.5
        if dis.is_integer():
            ans += 1
print(ans)

Solution (Python):

from math import sqrt
N, D = map(int, input().split())
lst = [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 = 0
        for k in range(D):
            dis += (lst[i][k] - lst[j][k]) ** 2
        r = sqrt(dis)
        if r == int(r):
            ans += 1

print(ans)

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

Solution (Python):
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):
    Y=0
    for k in range(D):
      Y+=(X[i][k]-X[j][k])**2
    for l in range(1,int(Y)+1):
      if l**2==Y:
        count+=1
      elif l**2>Y:
        break
print(count)

Solution (Python):
from itertools import combinations
import math

L = list(map(int, input().split()))
N = L[0]
D = L[1]

X = []

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

count = 0

for x in combinations(X,2):
	tmp = 0
	for j in range(D):
		tmp += (x[0][j]-x[1][j]) ** 2
		dist = math.sqrt(tmp)
	if dist % 1 == 0:
			count += 1
			
print(count)

Solution (Python):
import numpy as np
import itertools

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

ans = 0

for u, v in itertools.combinations(X,2):
  d = ((u - v) * (u - v)).sum()
  d2 = int(d ** 0.5)
  
  if d2 ** 2 == d:
    ans += 1
    
print(ans)

Solution (Python):
import math


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

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

print(c)

Solution (Python):
N, D = map(int, input().split())
items = []
for i in range(N):
    items.append(tuple(map(int, input().split())))
ans = 0
from itertools import combinations

for x in combinations([i for i in range(N)] , 2):
    tmp = 0
    for k in range(D):
        tmp += (items[x[0]][k] - items[x[1]][k]) ** 2
    if pow(tmp, 0.5) % 1 == 0:
        ans += 1
print(ans)

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

Solution (Python):
N, D = map(int, input().split())
items = []
for i in range(N):
    items.append(tuple(map(int, input().split())))
ans = 0
for i in range(N):
    for j in range(i+1, N):
        if i == j:
            continue
        tmp = 0
        for k in range(D):
            tmp += (items[i][k] - items[j][k]) ** 2
        if pow(tmp, 0.5) % 1 == 0:
            ans += 1
print(ans)

Solution (Python):
def main():
    n, d, *x = map(int, open(0).read().split())

    cnt = 0
    for j in range(n):
        for i in range(j):
            y = x[i*d:(i+1)*d]
            z = x[j*d:(j+1)*d]
            dist_double = 0
            for cur_y, cur_z in zip(y, z):
                dist_double += (cur_y - cur_z) ** 2
            dist = int(dist_double ** 0.5 + 0.99)
            if dist ** 2 == dist_double:
                cnt += 1

    ans = cnt
    print(ans)
    return()

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n, d, *x = map(int, open(0).read().split())

    cnt = 0
    for j in range(n):
        for i in range(j):
            y = x[i*d:(i+1)*d]
            z = x[j*d:(j+1)*d]
            dist_double = 0
            for cur_y, cur_z in zip(y, z):
                dist_double += (cur_y - cur_z) ** 2
            dist = int(dist_double ** 0.5 + 0.5)
            if dist ** 2 == dist_double:
                cnt += 1

    ans = cnt
    print(ans)
    return()

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n, d, *x = map(int, open(0).read().split())

    cnt = 0
    for i in range(n-1):
        for j in range(i+1, n):
            y = x[i*d:(i+1)*d]
            z = x[j*d:(j+1)*d]
            dist_double = 0
            for cur_y, cur_z in zip(y, z):
                dist_double += (cur_y - cur_z) ** 2
            dist = int(dist_double ** 0.5 + 0.5)
            if dist ** 2 == dist_double:
                cnt += 1

    ans = cnt
    print(ans)
    return()

if __name__ == '__main__':
    main()

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

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

int_length_count = 0
for i in range(N):
    ref_ppint = points[i]
    for j in range(i+1,N):
        tar_point = points[j]
        distans_of_coordinate = [x - y for (x,y) in zip(ref_ppint, tar_point)]
        squared_distans_of_coordinate =list(map(lambda x: x ** 2, distans_of_coordinate))
        if (sum(squared_distans_of_coordinate) ** .5).is_integer():
            int_length_count += 1
print(int_length_count)

Solution (Python):
import math

def main():
    n, d, *x = map(int, open(0).read().split())

    cnt = 0
    for i in range(n-1):
        for j in range(i+1, n):
            y = x[i*d:(i+1)*d]
            z = x[j*d:(j+1)*d]
            dist = 0
            for cur_y, cur_z in zip(y, z):
                dist += (cur_y - cur_z) ** 2
            dist = math.sqrt(dist)
            if dist == int(dist):
                cnt += 1

    ans = cnt
    print(ans)
    return()

if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np

N, D = map(int , input().split())
X = [list(map(int , input().split())) for _ in range(N)]
X = np.array(X)
cnt = 0
for i in range(N - 1):
    for j in range(i + 1 , N):
        dis = np.linalg.norm(X[i] - X[j])
        if dis.is_integer():
            cnt += 1
print(cnt)

Solution (Python):
n,d = map(int, input().split())
xd = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n):
  x1 = xd[i]
  for j in range(i+1,n):
    x2 = xd[j]
    dist = 0
    for x,y in zip(x1,x2):
      dist += (y-x) ** 2
    k = dist ** 0.5
    
    if int(k) ** 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)]

r = 0
for i in range(n):
  for j in range(i + 1,n):
    a = 0
    if i != j:
      for k in range(d):
        a += (x[i][k] - x[j][k]) ** 2
      a = math.sqrt(a)
      
      if a % 1 == 0:
        r += 1
print(r)