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 itertools

n, d = map(int, input().split())
x = [input().split() for x in range(n)]
l = list(itertools.combinations(x, 2))

ans = 0
for i in l:
    tmp = 0
    for j in range(d):
        tmp += (int(i[0][j]) - int(i[1][j])) ** 2
    if (tmp ** 0.5).is_integer():
        ans += 1


print(ans)

Solution (Python):

import math

S = 0

C = 0

n = input().split()

N = int(n[0])
D = int(n[1])

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

for N1 in range(N):
  for N2 in range(N):
    if N1 < N2:
      for i in range(D):
        S = S + (int(X[N1][i]) - int(X[N2][i])) ** 2
      S = math.sqrt(S)
      
      decimal, integer = math.modf(S)
      if decimal == 0:
        C = C + 1
      S = 0
print(C)

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

Solution (Python):
N,D = map(int,input().split())
b = [input().split() for l in range(N)]
count = 0
for i in range(N):
    y = b[0]
    del b[0]
    for j in range(len(b)):
        x = 0
        for k in range(D):
            x += (int(y[k]) - int(b[j][k]))**2
        if (x**.5)%1 == 0:
            count+=1
print(count)

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

n = 0
for i in range(N):
  for j in range(i+1, N):
    dist = np.linalg.norm(X[i]-X[j])
    if dist.is_integer():
      n += 1

print(n)

Solution (Python):
temp=input().split()
N=int(temp[0])
D=int(temp[1])

points=[]
for i in range(N):
  temp=input().split()
  points.append([int(temp[x]) for x in range(D)])
  
counter=0
for i in range(N):
  for j in range(i+1, N):
    l=pow(sum([pow(points[i][x]-points[j][x], 2) for x in range(D)]), 1/2)
    if l.is_integer():
      counter+=1
      
print(counter)

Solution (Python):
a,b = map(int,input().split())
c = [list(map(int,input().split())) for j in range(a)]
ans = 0
for l in range(a-1):
    for k in range(l+1,a):
        d = [(x-y)**2 for (x, y) in zip(c[l], c[k])]
        g = sum(d)
        s = g**0.5
        if s.is_integer():
            ans += 1
print(ans)

Solution (Python):
import math

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

Solution (Python):
import numpy as np

def is_int_distance(xi, xj):
    R2 = 0
    for i in range(len(xi)):
        R2 += (xi[i]-xj[i])**2
    if np.sqrt(R2) == float(int(np.sqrt(R2))):
        return 1
    else:
        return 0

if __name__=="__main__":
    N, D = map(int, input().split(' '))
    X = [[None for _ in range(D)] for _ in range(N)]

    for i in range(N):
        for j, t in enumerate(map(int, input().split(' '))):
            X[i][j]=t
    count = 0
    for i in range(N):
        for di in range(1, N - i):
            count += is_int_distance(X[i], X[i+di])
    
    print(count)

Solution (Python):
import itertools
import math

def q37(n, d, x):
    count = 0
    for i in itertools.combinations(x, 2):
        c = 0
        for l in range(d):
            c += (i[0][l] - i[1][l])**2

        if math.sqrt(c).is_integer():
            count += 1
        
    return count

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

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

print(q37(N, D, x))

Solution (Python):
n,d =  map(int,input().split())
Xnd = [list(map(int,input().split())) for _ in range(n)]
def cal(a,b):
  len2 = 0
  for i in range(d):
    len2 += (Xnd[a][i]-Xnd[b][i])**2 
  leng = len2 ** (0.5)
  return leng

cnt = 0
for i in range(n-1):
  for j in range(i+1,n):
    if cal(i,j).is_integer():
      cnt+=1
print(cnt)

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

list1=[[0]*N[1]] *N[0]

for i in range(N[0]):
 list1[i]=list(map(int,input().split()))
 
count=0
for i in range(N[0]):
 for j in range(N[0]-i-1):
   d=0
   for k in range(N[1]):
     d=d+(list1[i][k]-list1[j+i+1][k])**2
   if d**(1/2)==int(d**(1/2)):     
      count=count+1      
print(count)

Solution (Python):
import math

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

for i in range(0, n):
  row = list(map(int, input().split()))
  x.append(row)
  
count = 0
for i in range(0, n):
  for j in range(i+1, n):
    tmp_list = map(lambda x, y: (x - y)**2, x[i], x[j])
    result = math.sqrt(sum(tmp_list))

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

print(count)

Solution (Python):
import numpy as np
(n,d)=(int(x)for x in input().split())

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

flag = 0

for i in range (n):
    for j in range (n):  
        if (j<=i) :
            continue
        
        a = X[i][0:d]  
        b = X[j][0:d]

        tmp = 0
        for k in range (d):
            tmp = tmp + ( a [k] - b [k] ) ** 2
            
        r = np.sqrt (tmp)

        if r%1 == 0.0 :
            flag = flag + 1
            
        a.clear()
        b.clear()

print (flag)

Solution (Python):
import math

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

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

Solution (Python):
from math import sqrt

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

def dis(a,b):
    ret = 0
    for i in range(len(a)):
        ret += (a[i] - b[i]) ** 2
    return sqrt(ret)

ans = 0
for i in range(n):
    for j in range(i+1, n):
        dd = dis(x[i], x[j])
        if int(dd) == dd:
            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())))

def dist(a, b):
    d = 0.0
    for i in range(len(a)):
        d += (a[i] - b[i]) ** 2
    return d ** .5

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

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

        if int(math.sqrt(c))**2 == c:
            b += 1
print(b)

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

Solution (Python):
import math

N,D = (int(i) for i in input().split())
X =[]
for i in range(N):
    X.append([int(j) for j in input().split()])
count = 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
        dist = math.sqrt(dist)
        if dist % 1 == 0 :
            count += 1

print(count)

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

def main():
	n, D = map(int, input().strip().split())
	s = [[] for _ in range(n)]
	for i in range(n):
		s[i] = list(map(int, input().strip().split()))
	ans = 0
	for i in range(n-1):
		for j in range(i+1, n):
			d = 0
			for k in range(D):
				d += (s[i][k] - s[j][k])**2
			dist = sqrt(d)
			if int(dist) == dist:
				ans += 1
	print(ans)
if __name__ == '__main__':
	main()

Solution (Python):
import numpy as np

def distance(p1, p2):
    sum = 0
    for y, z in zip(p1, p2):
        sum += (z - y) ** 2
    return np.sqrt(sum)

N, D = [int(x) for x in input().split(" ")]
X = []
for i in range(N):
    X.append([int(x) for x in input().split(" ")])
X = np.array(X)
eps = 1e-6

count = 0
for i in range(N):
    p1 = X[i, :]
    for j in range(i + 1, N):
        p2 = X[j, :]
        if (distance(p1, p2) - round(distance(p1, p2))) ** 2 < eps:
            count += 1

print(count)

Solution (Python):
import numpy as np

def main():
    N, D = list(map(int, input().split()))
    X = []
    for i in range(N):
	    line = [int(a) for a in input().split()]
	    X.append(line)
    X_np = np.array(X)

    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            if(is_dist_int(X_np, D, i, j)):
                ans += 1
    print(ans)

def is_dist_int(X_np, D, i, j):
    dif = np.sum(np.square(np.abs(X_np[i] - X_np[j])))
    dis = np.sqrt(dif)
    return dis.is_integer()

main()

Solution (Python):


from math import sqrt
n, d = map(int, input().split())
data = list(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 += (data[i][k] - data[j][k]) ** 2
        if tmp == int(sqrt(tmp)) ** 2:
            ans += 1


print(ans)

Solution (Python):

import math

def check_dist(pt0, pt1):

	d = 0.0
	for k in range(len(pt0)):
		d += (pt0[k] - pt1[k]) ** 2
	d = math.sqrt(d)

	return d.is_integer()

N, D = map(lambda x: int(x), input().split(" "))

pts = []

for i in range(N):
	pt = list(map(lambda x: int(x), input().split(" ")))
	pts.append(pt)

count = 0

for i in range(0, N-1):
	for j in range(i+1, N):
		if check_dist(pts[i], pts[j]):
			count += 1

print(count)

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

print(sum((sum(i**2 for i in array(s)-array(t))**0.5).is_integer()for s,t in combinations(a,2)))

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

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

cnt=0
for i in range(N-1):
  temp_point_list = point_list[i+1:,:].copy()
  temp_point_list = temp_point_list - point_list[i,:]
  temp_point_list = np.sqrt(np.sum(temp_point_list*temp_point_list, axis=1))
  for i in range(temp_point_list.shape[0]):
    if temp_point_list[i] == int(temp_point_list[i]):
      cnt+=1
      
print(cnt)

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

c = 0

grid = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    grid.append(array)
    
for j in range(N-1):
  for l in range(j,N-1):
      d=0
      for k in range(D):
          d += (grid[j][k] - grid[l+1][k]) ** 2
      d = math.sqrt(d)
      if d.is_integer() == True:
  	    c += 1

print(c)

Solution (Python):
import itertools

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

def good_distance(x, y):
  return (sum(map(lambda a, b: (a-b)**2, x, y))) ** 0.5

ans = 0

for i in itertools.combinations(list(range(n)), 2):
  a, b = x[int(i[0])], x[int(i[1])]
  if str(good_distance(a, b))[-1] == "0":
    ans += 1

print(ans)

Solution (Python):
from math import sqrt
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):
        distance = 0
        for k in range(D):
            distance += pow(abs(X[i][k] - X[j][k]), 2)
        if int(sqrt(distance)) == sqrt(distance):
            cnt += 1
print(cnt)

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

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

cnt = 0
for i in range(n):
    for j in range(i+1,n):
        dis = 0
        for k in range(d):
            dis = dis + (x_list[i][k] - x_list[j][k])**2
        dis = dis **0.5
        if dis.is_integer():
            cnt = cnt + 1
        else:
            pass
print(cnt)

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








from math import sqrt

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

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

Solution (Python):
import math

matrix = input().split(" ")
points = []
for i in range(int(matrix[0])):
  points.append(input().split(" "))
  
counter = 0
for j in range(len(points)):
  for k in range(j+1, len(points)):
    result = 0
    for col_idx in range(int(matrix[1])):
      result += (int(points[j][col_idx]) - int(points[k][col_idx])) ** 2
    result = math.sqrt(result)
    if result.is_integer():
      counter += 1
      
print(counter)

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

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

count = 0
for i, j in itertools.combinations(l, 2):
    distance = 0
    for n in range(D):
        distance += (num[i][n] - num[j][n])**2
    if math.sqrt(distance).is_integer():
        count += 1

print(count)

Solution (Python):
def judge(x):
    for i in range(1000):
        if x==i**2:
            return True
    return False

def f(x,y):
    res = 0
    for i in range(len(x)):
        res += (x[i]-y[i])**2
    return res

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

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

ans = 0
for i in range(n):
    for j in range(i+1,n):
        if judge(f(a[i],a[j])):
            ans += 1
print(ans)

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

Solution (Python):
n,d = map(int, input().split())
array = [list(map(int, input().split())) for i in range(n)]
sqarray = [i**2 for i in range(130)]
count = 0

for i in range(n-1):
    for j in range(i+1, n):
        dis = sum([(array[i][k] - array[j][k])**2 for k in range(d)])
        if dis in sqarray:
            count += 1
            
print(count)

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

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

res = 0
for x1, x2 in combinations(X, 2):
  d2 = 0
  for x1_, x2_ in zip(x1, x2):
    d2 += (x1_-x2_)*(x1_-x2_)
  if sqrt(d2) - floor(sqrt(d2)) < 1e-6:
    res += 1
print(res)

Solution (Python):
import math
n, d = list(map(int,input().split(" ")))
ls = []
for i in range(n):
  ls.append(list(map(int,input().split(" "))))
ans = 0
for i in range(n):
  for j in range(i+1,n):
    dist = 0
    for k in range(d):
      dist += pow(ls[i][k]-ls[j][k], 2)
    dist = pow(dist ,0.5)
    if math.ceil(dist) == math.floor(dist):
      ans += 1
print(ans)

Solution (Python):
import math

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 range(n):
    for j in range(n):
        value = 0
        if i<j:
            for k in range(d):
                value += (x[i][k]-x[j][k])**2
            if math.sqrt(value)%1 == 0:
                cnt += 1
print(cnt)

Solution (Python):
import numpy as np
N,D = list(map(int, input().split()))
x = [input().split() for i in range(N)]
f = np.vectorize(int)
x = f(x)
ans =0
for i in range(N):
    j = i+1
    while j < N:
        sum = 0
        for k in range(D):
            sum += (x[i][k]-x[j][k])**2
        sum = sum**(0.5)
        if sum == int(sum):
            ans += 1
            
        j+=1
print(ans)

Solution (Python):
import math

N,D=map(int,input().split())
Z=[[int(x) for x in input().split()] for y in range(N)]

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

Solution (Python):
def is_distance_int(X, Y):
    _sum = 0
    for x, y in zip(X, Y):
        _sum += (x - y) ** 2
    distance = _sum ** 0.5
    return distance.is_integer()


def main():
    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):
            if is_distance_int(x[i], x[j]):
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()

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

N, D = map(int, input().split())
l = []
count = 0

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

  if i == 0:
    l.append(l_i)
    continue

  for l_j in l:
    arr = np.array(l_i) - np.array(l_j)
    if np.linalg.norm(arr).is_integer():
      count += 1

  l.append(l_i)

print(count)

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

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

x_list = []
for i in range(N):
    x = list(map(int,input().split()))
    x_list.append(x)
count = 0
for i in range(1, N + 1):
    for j in range(1, N + 1):
        if i >= j:
            continue
        distance2 = 0
        for num in range(D):
            distance2 += (x_list[i - 1][num] - x_list[j - 1][num]) ** 2
        if math.sqrt(distance2).is_integer():
            count += 1
            
print(count)

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

c=0
for i in range(n-1):
  for j in range(i+1,n):
    c+=(sum((a-b)**2 for a,b in zip(x[i],x[j]))**0.5).is_integer()

print(c)

Solution (Python):



def main():
    from math import sqrt

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

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

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

            if total == int(sqrt(total)) ** 2:
                count += 1

    print(count)


if __name__ == '__main__':
    main()

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

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

Solution (Python):
import math                                                                                              
INPUT_SENTENCES = 1                                                                                      
ss = [input() for i in range(INPUT_SENTENCES)][0].split(" ")                                             
N = int(ss[0])                                                                                           
D = int(ss[1])                                                                                           
INPUT_SENTENCES = N                                                                                      
ss = [input() for i in range(INPUT_SENTENCES)]                                                           
X = [[int(ii) for ii in ss[i].split(" ")] for i in range(N)]                                             
result = []                                                                                              
for i in range(N):                                                                                       
    for j in [ii for ii in range(N) if i < ii]:                                                          
        tmp = [(X[i][d] - X[j][d])*(X[i][d] - X[j][d]) for d in range(D)]                                
        if math.sqrt(sum(tmp)).is_integer():                                                             
            result.append(1)                                                                             
print(sum(result))

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

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

x = []

for i in range(n):
    x.append([int(j) for j in input().split()])

def are(a, b):
    sm = 0
    for i in range(len(a)):
        sm += (b[i] - a[i]) ** 2
    return sm ** 0.5 == int(sm ** 0.5)

c = 0
for i in range(len(x)):
    for j in range(i+1, len(x)):
        c += are(x[i], x[j])

print(c)

Solution (Python):
import math
N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
def cul_dis(x, y):
	sum = 0
	for i in range(len(x)):
		sum += (x[i]-y[i])**2
	return math.sqrt(sum)
cnt = 0
for i in range(len(X))[:-1]:
	for j in range(len(X))[i+1:]:
		dis = (cul_dis(X[i], X[j]))
		if (dis.is_integer()):
			cnt += 1
print(cnt)

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

print(c)

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

Solution (Python):
import math


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


def dist(xs, ys):
    ret = 0
    for x, y in zip(xs, ys):
        ret += (x - y) ** 2
    return math.sqrt(ret)


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

Solution (Python):
import math
inp = input().split(" ")
num = int(inp[0])
dim = int(inp[1])
points = []
int_count = 0

for i in range(0,num):
    inp = input().split(" ")
    points.append(inp)

for i in range(len(points)):
    for j in range(len(points)-i-1):
        l2 = 0
        for k in range(0,dim):
            l2 += (int(points[i][k]) - int(points[i+j+1][k]))**2
        l = math.sqrt(l2)
        if l.is_integer():
            int_count += 1

print(int_count)

Solution (Python):
import math
def dist(a, b):
  ans = 0
  for i in range(len(a)):
    ans += (a[i]- b[i]) ** 2
  return math.sqrt(ans)

n, d = (int(i) for i in input().split())  
x = []
for i in range(n):
  t = [int(j) for j in input().split()] 
  x.append(t)
  
ans = 0
for i in range(n):
  for j in range(n)[i+1:]:
 
    d = dist(x[i], x[j])
    if math.ceil(d) == d:
      ans += 1
print(ans)

Solution (Python):
N,D = map(int,input().split(' '))
X = []
count = 0
for i in range(N):
  s = tuple(map(int,input().split(' ')))
  X.append(s)

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

Solution (Python):
import numpy as np

S      = input()
S      = S.split()
N      = int(S[0])
D      = int(S[1])
matrix = np.zeros([N, D])
count  = 0


for i in range(0, N, 1):
    X_vector = input()
    X_vector = X_vector.split()
    for j in range(0, D, 1):
        matrix[i][j] = int(X_vector[j])

for i in range(0, N, 1):
    a_vector = matrix[i]
    for j in range(i+1, N, 1):
        b_vector = matrix[j]
        length = np.linalg.norm(b_vector-a_vector)
        if length.is_integer():
            count = count + 1
print(count)

Solution (Python):


n,d=map(int,raw_input().split())
x=[map(int,raw_input().split()) for i in xrange(n)]
res=0
for i in xrange(n):
 for j in xrange(i+1,n):
  norm=0
  for k in xrange(d):
   norm+=pow((x[i][k]-x[j][k]),2)
  if int(norm**0.5+0.01)**2==norm:
   res+=1
print res

Solution (Python):
import numpy as np

n,d = (int(i) for i in input().split())  

e = np.array([[int(i) for i in input().split()] for i in range(n)] )

count = 0

for i in range(len(e)):
    for j in range(len(e) - i - 1):
        k = j + i + 1
        dist = np.sum((e[i] - e[k])**2)
        if dist**0.5 == int(dist**0.5):
            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 j in range(N):
    for i in range(j):
        distant2 = 0
        for k in range(D):
            distant2 += (X[j][k]-X[i][k])**2
        if math.sqrt(distant2) % 1 == 0:
            ans += 1

print(ans)

Solution (Python):
def calc_d2(p1, p2):
    d2 = 0
    for idx in range(len(p1)):
        d2 += (p1[idx]-p2[idx])**2
    return d2
    

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

x = list()
for i in range(n):
    x.append( list(map(int, input().split())) )
    
count = 0
for p1 in range(0, n-1):
    for p2 in range(p1+1, n):
        d2 = calc_d2(x[p1], x[p2])
        if int(d2**0.5) ** 2 == d2:
            count += 1

print(count)

Solution (Python):
import sys
import itertools
import math

def def1(l):
    
    res = []
    for i in range(len(l)):
        for j in range(i):
            res.append(abs(l[j] - l[i]) ** 2)
    return res

def main():
    input = sys.stdin.readline
    N, D = map(int, input().split())
    
    L = []
    L = [list(map(int, input().split())) for i in range(N)]
    
    L = list(zip(*L))
    
    l = [def1(v) for v in L]
    
    cnt = 0
    for v in list(zip(*l)):
        if float.is_integer(math.sqrt(sum(v))) : cnt = cnt + 1
            
    print (cnt)
        
if __name__ == '__main__':
    main()

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

Solution (Python):
import numpy as np
N, D = (int(x) for x in input().split())
points = []
for i in range(N):
    points.append(list(map(int, input().split())))
count = 0
for j in range(N):
    for i in range(j):
        if(i != j):
            pointi = np.array(points[i])
            pointj = np.array(points[j])
            if(np.linalg.norm(pointi - pointj) % 1 == 0):
                count += 1
        else:
            continue
print(count)

Solution (Python):
def B_GoodDistance():
    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 distance(x[i], x[j]):
                ans += 1
    print(ans)

def distance(y, z):
    from math import sqrt
    d = 0
    for i in range(len(y)):
        d += (y[i] - z[i]) * (y[i] - z[i])
    d = sqrt(d)
    return (d == d // 1)

if __name__ == "__main__":
    B_GoodDistance()

Solution (Python):
import math
N, D = map(int, input().split())
X = [list(map(int,input().split())) for _ in range(N)]
def distance(X,Y):
  ans = 0
  for i,j in zip(X,Y):
    ans += (i - j)**2
  return math.sqrt(ans)

count = 0
for i in range(N):
  for j in range(i+1,N):
    temp = distance(X[i],X[j])
    if temp == temp //1:
      count += 1
print(count)

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

Solution (Python):
N, D = map(int, input().split())
P = [list(map(int, 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 += (P[i][k]-P[j][k])**2
        t = t**(1/2)
        if t.is_integer():
            ans += 1
print(ans)