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 _ in range(N)]
cnt = 0
for i in range(N):
    for j in range(i+1, N):
        if np.linalg.norm(np.array(X[i])-np.array(X[j])).is_integer():
            cnt += 1
print(cnt)

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

for i in range(n):
    xlist = list(map(int,input().split(" ")))
    clist.append(xlist)

def dis(ylist,zlist):
    distance = 0
    for i in range(d):
        distance += (ylist[i] - zlist[i]) ** 2
    sqdis = math.sqrt(distance)
    return(sqdis)

countdis = 0

for i in range(n-1):
    for j in range(i+1,n):
        if dis(clist[i],clist[j]) % 1 == 0:
            countdis += 1

print(countdis)

Solution (Python):
import itertools

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

combi=list(itertools.combinations([i for i in range(N)],2 ))

ans=0

for c in combi:
	temp=0
	for d in range(D):
		temp+=(X[c[0]][d]-X[c[1]][d])**2
	temp=temp**.5
	if float.is_integer(temp):ans+=1

print(ans)

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

def check_dist(i, j):
  quad = sum([(xi - xj) * (xi - xj) for xi,xj in zip(X[i], X[j])])
  dist = 1
  while dist * dist <= quad:
    if dist * dist == quad:
      return True
    dist += 1
  return False

count = 0
for i in range(N-1):
  for j in range(i+1, N):
    count += check_dist(i, j)
print(count)

Solution (Python):
import math

N,D = map(int,input().split())
L = []
ans = 0 
for _ in range(N):
  X = list(map(int,input().split()))
  L.append(X)
for i in range(N - 1):
  for j in range(i + 1,N):
    con = 0
    for k in range(D):
      con += (L[i][k] - L[j][k]) ** 2
    if  int(math.sqrt(con)) ** 2 == con:
      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)]
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        tmp=0
        for k in range(d):
            tmp+=(x[i][k]-x[j][k])**2
        if math.sqrt(tmp)==int(math.sqrt(tmp)):
            ans+=1
print(ans)

Solution (Python):
N,D=map(int,input().split())
X=[list(map(int,input().split())) for _ in range(N)]
ans = 0
from itertools import combinations
from os import kill
for i, j in combinations(range(N), 2):
    d = sum([(X[i][k]-X[j][k])**2 for k in range(D)])
    if int(d**0.5) == d**0.5:
        ans += 1
print(ans)

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

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

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

square_list = set([i*i for i in range(40*40*10+1)])

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

print(cnt)

Solution (Python):
import sys
import numpy as np
import collections as cl
import itertools as it

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(100000)

n, d = map(int, input().split())
x = []
for _ in range(n):
    x.append(list(map(int, input().split())))
cnt = 0
for i, j in  it.combinations(x, 2):
    di = 0
    for k in range(d):
        di += (i[k]-j[k])**2
    di = di**(1/2)
    if di.is_integer():
        cnt += 1
print(cnt)

Solution (Python):
import math

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

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

counter = 0
ary_len = len(ary)
for i in range(ary_len - 1):
    for j in range(i+1,ary_len):
        tmp = 0
        for k in range(D):
            tmp += pow(abs(ary[i][k]-ary[j][k]),2)
        if math.sqrt(tmp) % 1 == 0:
            counter += 1
print(counter)

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

Xarray = [list(map(int, input().split())) for _ 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 += abs(Xarray[i][k] - Xarray[j][k]) ** 2
        
        if math.sqrt(sum).is_integer():
            ans += 1

print(ans)

Solution (Python):
N,D = map(int,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):
        L = 0
        for k in range(D):
            L += (X[i][k] - X[j][k]) ** 2
        M = L ** 0.5
        if(M == int(M)):
            ans += 1

print(ans)

Solution (Python):
import itertools
import numpy as np
N,D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]
count=0
for i in itertools.combinations(X,2):
  if np.linalg.norm(list(map(lambda x,y:abs(x-y),i[0],i[1])))%1==0:count+=1
print(count)

Solution (Python):
import itertools
import math

n,d = map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]
q = list(itertools.combinations(range(n),2))
cnt = 0
for i in range(len(q)):
    ans = 0
    for j in range(d):
        ans += (x[q[i][0]][j] - x[q[i][1]][j])**2
    ans = math.sqrt(ans)
    if ans == int(ans):
        cnt += 1

print(cnt)

Solution (Python):
n,d = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(n)]
ans = 0
from math import sqrt
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
    if sqrt(dis) == int(sqrt(dis)):
      ans += 1
print(ans)

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

Solution (Python):
import math
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()))

cnt = 0

for i in range(n-1):
    for j in range(i+1, n):
        dist= 0
        for k in range(d):
            dist += (X[i][k]-X[j][k])**2
        
        if math.sqrt(dist) == int(math.sqrt(dist)):
            cnt += 1
        
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()))
  
def f(i):
  return (i**0.5-int(i**0.5))==0.0
  
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
    ans+=1 if f(dist) else 0
print(ans)

Solution (Python):

import sys
input=sys.stdin.readline
import itertools
import math
import numpy as np

def main():
    numbers=[]
    
    n,m = map(int,input().split())
    
    numbers=np.array([list(map(int,input().split())) for _ in range(n)])
    ans=0
    length=0
    count=0

    for idx,pair in enumerate(itertools.combinations(numbers,2)):
        tmp_A=np.array(pair[0])
        tmp_B=np.array(pair[1])
        length=(tmp_A-tmp_B)**2
        ans=math.sqrt(sum(length))
        if ans.is_integer()==True:
            count+=1
        else:
            continue
    print(count)



if __name__=="__main__":
    main()

Solution (Python):
n,d = map(int,input().split())
import numpy as np
xlist = [list(map(int,input().split())) for i in range(n)]
xarray = np.array(xlist)
ans = 0
for i in range(n):
  for j in range(i+1,n):
    if np.linalg.norm(xarray[i]-xarray[j]).is_integer():
      ans+=1
print(ans)

Solution (Python):
n,d = map(int,input().split())
import numpy as np
xlist = [list(map(int,input().split())) for i in range(n)]
xarray = np.array(xlist)
ans = 0
for i in range(n):
  for j in range(i+1,n):
    if np.linalg.norm(xarray[i]-xarray[j])==int(np.linalg.norm(xarray[i]-xarray[j])):
      ans+=1
print(ans)

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

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

    return ans

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):
        if dist(X[i],X[j]).is_integer():
            count += 1

print(count)

Solution (Python):
import math

def colcu (bli,ali,D):
    num = 0
    for i in range(D):
        num += (bli[i] - ali[i]) ** 2
    return math.sqrt(num)

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

an = 0
for i in range(N-1):
 for t in range(i+1,N):
     if colcu(pli[i],pli[t],D).is_integer():
         an += 1
print(an)

Solution (Python):
import  math

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

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

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

print(ans)

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

cnt = 0
for comb in itertools.combinations(N_List,2):
    ans = 0
    for k in range(D):
        ans += (ND_List[comb[0]][k] - ND_List[comb[1]][k])**2
    ans =ans**0.5
    if ans.is_integer():
        cnt += 1
print(cnt)

Solution (Python):

from math import sqrt

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

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

    print(ans)

if __name__ == "__main__":
    main()

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

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


def distance(xx,d,i,j):
    ans = 0
    for u in range(d):
        ans+=((xx[i][u]-xx[j][u])**2)
    if math.sqrt(ans).is_integer():
         return 1
    else :
        return 0
    
count =0
for i in range(n):
    for j in range(i+1,n):
        count += distance(xx,d,i,j)
print (count)

Solution (Python):
n,d=map(int,input().split())
x=[]
for i in range(n):
    p=list(map(int,input().split()))
    x.append(p)
ans=0
for i in range(len(x)-1):
    for j in range(i+1,len(x)):
        dis=0
        for k in range(d):
            dis+=(x[i][k]-x[j][k])**2
        if int(dis**(1/2))==dis**(1/2):
            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):
        d = 0
        for k in range(D):
            d += (X[i][k] - X[j][k])**2
        d = d**(1/2)
        if int(d) == d:
            ans +=1

print(ans)

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

def check(i, j):
    dis = 0
    for k in range(D):
        dis += (X[i][k] - X[j][k])**2
    
    if int(math.sqrt(dis))**2 == dis:
        return 1
    else:
        return 0

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

Solution (Python):
import sys
import math

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

def dist(y, z):
    ret = 0
    for i, j in zip(y, z):
        ret += (i-j)**2
    return math.sqrt(ret)

cnt = 0
for x in X:
    for y in X:
        if dist(x, y) % 1 == 0:
            cnt += 1
    cnt -= 1
print(cnt//2)

Solution (Python):
import sys
from math import sqrt


def dist(x, d, i, j):
    res = 0
    for k in range(d):
        res += (x[i][k] - x[j][k]) ** 2
    return res


def main():
    input = sys.stdin.buffer.readline
    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):
            if sqrt(dist(x, d, i, j)).is_integer():
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from math import sqrt

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

XS = [list(int(i) for i in input().split()) for _ in range(N)]

cnt = 0
for i in range(N):
  for j in range(i+1, N):
    if sqrt(sum((y - z) ** 2 for y, z in zip(XS[i], XS[j]))).is_integer():
      cnt += 1
      
print(cnt)

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

Solution (Python):
N,D = (int(x) for x in input().split())
X = [None]*N
for i in range(N):
  X[i] = [float(x) for x in input().split()]
count = 0
for i in range(N-1):
  for j in range(i+1,N):
    sq = [(X[i][k]-X[j][k])**2 for k in range(D)]
    dist = sum(sq)**0.5
    if dist == int(dist):
      count += 1
print(count)

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

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

count = 0
d_2 = 0
d = 0

for i in range(1, N):
    for j in range(0, i):
        d_2 = 0
        d = 0
        for k in range(D):
            d_2 += (float(X[i][k]) - float(X[j][k]))**2
        d = d_2**(1/2)
        if d.is_integer() == True:
            count += 1

print("{}".format(count))

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

Solution (Python):
n,d = map(int,input().split())
data = [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 += (int(data[i][k]) - int(data[j][k])) **2
        temp = sum ** 0.5
        if  temp.is_integer() == True:
            ans += 1
print(ans)

Solution (Python):
import numpy as np
import math
n, d = map(int,input().split())
x_l = [ np.array(list(map(int, input().split()))) for _ in range(n)  ]

ans = 0
p = set()
for i,x in enumerate(x_l):
    for j,y in enumerate(x_l):
        if i != j:
            if str(min([i,j]))+'_'+str(max([i,j])) not in p:
                d = math.sqrt(sum((x-y)**2))
                if d.is_integer():
                    ans += 1
                    p.add(str(min([i,j]))+'_'+str(max([i,j])))
print(ans)

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=0
        for k in range(D):
            d+=(X[i][k]-X[j][k])**2
        for l in range(1000):
            if l**2==d:
                ans+=1
                break
print(ans)

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

Solution (Python):
import math
n, d = map(int,input().split())
lst = []
for i in range(n):
    x = list(map(int,input().split()))
    lst.append(x)
def check (lst, a, b):
    tmp = 0
    for i in range(len(lst[a])):
        tmp = tmp + (lst[a][i] - lst[b][i])**2
    tmp = math.sqrt(tmp)
    if (tmp//1 == tmp):
        return (1)
    else:
        return (0)
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        ans = ans + check(lst, i, j)
print(ans)

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

import math

def dist(x,y):
    tmp=0
    for i in range(d):
        tmp+=(x[i]-y[i])**2
    return math.sqrt(tmp)

ans=0
import itertools
for seq in itertools.combinations(range(n),2):
    if dist(x[seq[0]],x[seq[1]]).is_integer():
        ans+=1
print(ans)

Solution (Python):
n ,d = map(int, input().split())
t = []
ans = 0

for i in range(n):
  c = list(map(int,input().split()))
  t.append(c)
  
for k in range(0, n-1):
  for j in range(k+1, n):
    sumsum = 0 
    for l in range(d):
      sumsum += (t[k][l]-t[j][l])**2
    dis = sumsum**(1/2)
    
    if dis.is_integer() == True:
        ans += 1
print(ans)

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

def how_far(a,b):
  x = 0
  for s in range(0,d):
    x += (a[s] - b[s]) ** 2
  x = x ** (1/2)
  return x
count = 0
for i in range(n-1):
  for j in range(i+1,n):
    kyori = how_far(p[i],p[j])
    true_kyori = int(kyori)
    if kyori == true_kyori:
      count += 1
      
print(count)

Solution (Python):
import itertools

n, d = map(int, input().split())
points = []
for _ in range(n):
  point = list(map(int, input().split()))
  points.append(point)

combinations = list(itertools.combinations(points, 2))
dist_lists = []
ans = 0
for comb in combinations:
  A = comb[0]
  B = comb[1]

  tmp = 0
  for j in range(len(A)):
    tmp += (B[j] - A[j])**2
  
  distance = tmp**(0.5)

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

Solution (Python):
from itertools import combinations
n,d = map(int,input().split())
L = list(list(map(int,input().split())) for _ in range(n))
C = list(combinations(L,2))
ans = 0
for i in range(len(C)):
  total = 0
  for a,b in zip(C[i][0],C[i][1]):
    total += abs(a - b)**2
  
  if (total**0.5)%1 == 0:
    ans += 1
print(ans)

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

cnt = 0
for i in list(itertools.combinations(X, 2)):
    ans = 0
    for j in range(D):
        ans += abs((i[0][j] - i[1][j])**2)
    if math.sqrt(ans).is_integer():
        cnt += 1
print(cnt)

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

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

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

print(cnt)

Solution (Python):
import math
n,d=map(int,input().split())
x=[[int(x) for x in input().split()]for _ in range(n)]
cnt=0
for i in range(n):
    for j in range(i+1,n):
        sum=0
        for a,b in zip(x[i],x[j]):
            sum+=(a-b)*(a-b)
        if math.sqrt(sum).is_integer():
            cnt+=1
print(cnt)

Solution (Python):
import numpy as np
from scipy.special import comb
n,d=map(int,input().split())
x=[]
total=0
for i in range(n):
    x.append(list(map(int,input().split())))
for i in range(n):
    for j in range(n):
        if i!=j:
            a=np.array(x[i])
            b=np.array(x[j])
            u=b-a
            if np.linalg.norm(u)==int(np.linalg.norm(u)):
                total+=1
print(int(total/2))

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):
  for j in range(i+1, N):
    dis = 0
    for d in range(D):
      dis += (X[i][d] - X[j][d])**2
    dis = math.sqrt(dis)
    ans += dis.is_integer()

print(ans)

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

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

Solution (Python):
import math

def calc(num, list1, list2):
  s = 0
  for i in range(num):
    s += (list1[i] - list2[i]) ** 2
  d = math.sqrt(s)
  return d

N, D = map(int, input().split())
L = []
ans = 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):
    c = calc(D, L[i], L[j])
    if c.is_integer():
      ans += 1

print(ans)

Solution (Python):
import numpy as np

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


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


dot = 0
for i in range(N):
  for j in range(i, N):
    dis[i][j] = np.sqrt(dis[i][j])
    if dis[i][j].is_integer() and dis[i][j] != 0:
      dot += 1

print(dot)

Solution (Python):
def main():
    n, d = map(int, input().split())
    ps = [[*map(int, input().split())] for _ in range(n)]
    square = [i**2 for i in range(1, 127)]
    cnt = 0
    for i in range(n-1):
        for j in range(i+1, n):
            if sum([(ps[i][k] - ps[j][k]) ** 2 for k in range(d)]) in square:
                cnt += 1
    print(cnt)

if __name__ == "__main__":
    main()

Solution (Python):
import math


def main():
    n, d = map(int, input().split())
    Xs = [list(map(int, input().split())) for _ in range(n)]
    ans = 0

    for i, xi in enumerate(Xs):
        for xj in Xs[i+1:]:
            dis = 0
            for di in range(d):
                dis += (xi[di] - xj[di])**2

            if math.sqrt(dis) % 1 == 0:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

import math
n, d = (int(i) for i in input().split())
list_x = [[int(i) for i in input().split()] for j in range(0, n)]
count = 0
tmp = 0
for i in range(0, n):
    for j in range(i + 1, n):
        for k in range(0, d):
            tmp += pow(list_x[i][k] - list_x[j][k], 2)
        tmp = math.sqrt(tmp)
        if tmp.is_integer(): count += 1
        tmp = 0
print(count)

Solution (Python):
import math

def solve(y, z):
  res = 0
  for i in range(len(y)):
    res += (y[i]-z[i])**2
  return math.sqrt(res)

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):
    dist = solve(x[i], x[j])
    if int(dist) == dist: ans += 1
print(ans)

Solution (Python):
import itertools

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

c = list(itertools.combinations(range(n), 2))
ans = 0
for a, b in c:
    dist = 0
    for j in range(d):
        dist += (x[a][j]-x[b][j])**2
    if dist**(1/2) % 1 == 0:
        ans += 1
print(ans)

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

Solution (Python):
N, D = map(int, input().split())
X = []
for _ in range(N):
    line = list(map(int, input().split()))
    X.append(line)
ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        dist2 = 0
        for k in range(D):
            dist2 += (X[i][k] - X[j][k])**2
        for l in range(200):
            if dist2 == l**2:
                ans += 1
                break
print(ans)

Solution (Python):
n, b = map(int, input().split())
xlist = [list(map(int, input().split())) for _ in range(n)]

from itertools import combinations
import numpy as np
xnumpy = np.array(xlist)
ans = 0
for y, z in combinations(xnumpy, 2):
    distance = ((y -z)**2).sum()
    for i in range((40**2)*10):
        if distance == i*i:
            ans += 1
print(ans)

Solution (Python):
import math
N,D=map(int,input().split())
sq=[list(map(int,input().split())) for i in range(N)]
ans=0
for j in range(N-1):
    for k in range(j+1,N):
        s=0
        for l in range(D):
            s+=(sq[j][l]-sq[k][l])**2
        if math.sqrt(s)%1==0.0:
            ans+=1
print(ans)

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

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

cnt=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 int(math.sqrt(s))**2==s:
      cnt+=1
      
print(cnt)

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




def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return float(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))




def main():
	n,d=MI()
	X=[LI() for _ in range(n)]
	
	ans=0

	for i in range(n-1):
		for j in range(i+1,n):
			k=0
			for x,y in zip(X[i],X[j]):
				k+=(x-y)**2
			
			if k**0.5==int(k**0.5):
				ans+=1

	print(ans)








if __name__ == "__main__":
	main()

Solution (Python):



import sys
from io import StringIO
import unittest
from math import sqrt


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 2
1 2
5 5
-2 8"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3 4
-3 7 8 2
-12 1 10 2
-2 8 9 3"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """5 1
1
2
3
4
5"""
        output = """10"""
        self.assertIO(input, output)


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

    ans = 0
    for i, x1 in enumerate(X):
        for x2 in X[i+1:]:
            tmp = 0
            for j in range(D):
                tmp += (x2[j]-x1[j])**2
            tmp = sqrt(tmp)
            if tmp.is_integer() == True:
                ans += 1

    print(ans)


if __name__ == "__main__":
    
    resolve()

Solution (Python):
from numpy import array
from numpy.linalg import norm
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):
    if norm(array(X[i])-array(X[j])).is_integer():
      ans += 1
print(ans)

Solution (Python):
import math

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

Solution (Python):
import math
import itertools

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

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

for i in itertools.combinations(L,2):
    y, z, dis = i[0], i[1], 0
    for a, b in zip(y, z):
        dis += (a-b)**2
    if math.sqrt(dis) == int(math.sqrt(dis)):
        cnt += 1

print(cnt)

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

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

seisu_count = 0
for l in range(N):

    for r in range(l+1, N):
        total = 0
        for z in range(D):
            y_z = abs(X[l][z] - X[r][z])
            y_z_2 = y_z * y_z
            total += y_z_2
        
        sqr_total = math.sqrt(total)
        if sqr_total.is_integer():
            seisu_count += 1

print(seisu_count)

Solution (Python):
import numpy as np
from itertools import combinations
n,d=map(int,input().split())
l= [np.array(input().split() ,dtype=np.int64) for _ in range(n)]
ans=0
dist=0
for a,b in combinations(l,2):
    dist=((a-b)**2).sum()
    for j in range(dist+1):
        if  j**2 == dist:
            ans+=1
            continue
print(ans)

Solution (Python):
n, d = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = 0
for i in range(n):
    for j in range(i + 1, n):
        s = 0
        for c, e in zip(a[i], a[j]):
            s += (c - e) ** 2
        if s ** 0.5 == int(s ** 0.5):
            b += 1
print(b)

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

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