Problem:
 Score : 200 points    Problem Statement There are N points in a D -dimensional space.  The coordinates of the i -th point are (X_{i1}, X_{i2}, ..., X_{iD}) .  The distance between two points with coordinates (y_1, y_2, ..., y_D) and (z_1, z_2, ..., z_D) is \sqrt{(y_1 - z_1)^2 + (y_2 - z_2)^2 + ... + (y_D - z_D)^2} .  How many pairs (i, j)  (i < j) are there such that the distance between the i -th point and the j -th point is an integer?      Constraints  All values in input are integers.  2 \leq N \leq 10  1 \leq D \leq 10  -20 \leq X_{ij} \leq 20  No two given points have the same coordinates. That is, if i \neq j , there exists k such that X_{ik} \neq X_{jk} .         Input Input is given from Standard Input in the following format:  N  D  X_{11}  X_{12}  ...  X_{1D}  X_{21}  X_{22}  ...  X_{2D}  \vdots  X_{N1}  X_{N2}  ...  X_{ND}       Output Print the number of pairs (i, j)  (i < j) such that the distance between the i -th point and the j -th point is an integer.        Sample Input 1 3 2
1 2
5 5
-2 8      Sample Output 1 1  The number of pairs with an integer distance is one, as follows:   The distance between the first point and the second point is \sqrt{|1-5|^2 + |2-5|^2} = 5 , which is an integer.  The distance between the second point and the third point is \sqrt{|5-(-2)|^2 + |5-8|^2} = \sqrt{58} , which is not an integer.  The distance between the third point and the first point is \sqrt{|-2-1|^2+|8-2|^2} = 3\sqrt{5} , which is not an integer.        Sample Input 2 3 4
-3 7 8 2
-12 1 10 2
-2 8 9 3      Sample Output 2 2       Sample Input 3 5 1
1
2
3
4
5      Sample Output 3 10

Solution (Python):
import math

def is_int(s):
  if s.is_integer():
  	return int(s)
  else:
  	s

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

A = [list(map(int, input().split())) for _ in range(n)]
ans=0

for i in range(n):
	for j in range(i+1,n):
		sum = 0
		for k in range(d):
			sum+=(A[i][k]-A[j][k])**2
		q=is_int(math.sqrt(sum))
		
		
		if isinstance(q, int):
			ans+=1
print(ans)

Solution (Python):
import math
N,D=map(int,input().split())
A=[]
count=0
total=0
L=0
for i in range(N):
    B=list(map(int,input().split()))
    A.append(B)

for i in range(N):
    for k in range(i+1,N):
        for j in range(D):
            total +=(A[i][j]-A[k][j])*(A[i][j]-A[k][j])
        
        L=math.floor(math.sqrt(total))
        
        
        if math.sqrt(total)==L:
            count +=1
        total=0
print(count)

Solution (Python):
import math
N,D = map(int,input().split(" "))
c = 0
def ds(one,two):
    temp = 0
    for i in range(D):
        temp += abs(one[i] - two[i])**2
    return math.sqrt(temp)

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

dist_mt = []
for i in range(N):
    temp = []
    for j in range(N):
        if i == j:
            el = 0
        else:
            el = ds(list[i],list[j]) 
        temp.append(el)     
    dist_mt.append(temp)

for i in range(N):
    for j in range(N):
        if i != j and dist_mt[i][j].is_integer() == True:
            c += 1
print(int(c/2))

Solution (Python):
import numpy as np

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

from scipy.spatial import distance
smm = distance.cdist(xlist, xlist)

c = 0
for i in smm.flatten():
  if i != 0 and i.is_integer():
  	c += 1

print(int(c/2))

Solution (Python):
import math
import numpy as np

N, D = map(int, input().split())
p = [[int(i) for i in input().split()] for i in range(N)]
X = np.array(p)
count = 0
for i in range(N):
    j = i + 1
    while(j < N):
        test = X[i] - X[j]
        dist = math.sqrt(sum(test * test))
        if(dist.is_integer()):
            count += 1
        j += 1
print(count)

Solution (Python):
import math

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

        r = math.sqrt(r2)
        ans += r.is_integer()

print(ans)

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)
print(sum([np.linalg.norm(x[i]-x[j]).is_integer() for i in range(N-1) for j in range(i+1,N)]))

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

def distance(vec1,vec2,D):
    ans = 0
    for i in range(D):
        ans = ans + abs(vec1[i]- vec2[i]) * abs(vec1[i] - vec2[i])
    return ans
count = 0
for i in range(N):
    for j in range(i,N):
        dis = distance(Vector[i],Vector[j],D)
        dis = dis**0.5
        if i == j:
            continue
        if abs(dis- int(dis)) < 0.000000000001:
            count = count + 1

print(count)

Solution (Python):
def main():
    import sys
    import math
    input = sys.stdin.readline
 
    n, d = [int(i) for i in input().split()]
    
    table = [[int(i) for i in input().split()] for n in range(n)]
 
    count = 0
    
    for i in range(n):
        for j in range(i+1, n):
            temp = 0
            for x in range(d):
                temp += (table[i][x] - table[j][x]) ** 2
          
            rt = math.sqrt(temp)
            if rt.is_integer():
                count += 1
    
    print(count)
    
if __name__ == '__main__':
    main()

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

def dist(y,z):
	summ = 0
	for i in range(d):
		summ += (y[i]-z[i])**2
	return summ**(1/2)
	
ans_list = []
for ii in range(n):
	for jj in range(n):
		if ii < jj:
			dis = dist(x[ii],x[jj])
			if dis.is_integer():
				ans_list.append(dis)
print(len(ans_list))

Solution (Python):
import itertools
import math

N, D = [int(x) for x in input().strip().split()]
if D == 1:
    print(int(N*(N-1)/2))
else:
    points = []
    for data in range(N):
        points.append([int(x) for x in input().strip().split()])

    result = 0
    for p1,p2 in itertools.combinations(points, 2):
        distance = 0
        for y,z in zip(p1,p2):
            distance += (y - z) ** 2
        
        distance = math.sqrt(distance)
        if distance.is_integer(): result += 1    
    print(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):
        d2 = 0
        for k in range(d):
            d2 += (x[i][k] - x[j][k])**2
        dist = int(d2**0.5)
        if dist * dist == d2:
            ans += 1
print(ans)

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

Solution (Python):

import numpy as np


if __name__ == '__main__':
    n,d  = list(map(int, input().split(" ")))

    coord_list = []
    count = 0
    for i in range(n):
        new_coord = list(map(int, input().split(" ")))
        if coord_list != None:
            for coord in coord_list:
                norm = np.linalg.norm(np.array(coord) - np.array(new_coord))
                if float.is_integer(norm) == True:
                    count += 1
            coord_list.append(new_coord)
        else:
            coord_list = [new_coord]
    print(count)

Solution (Python):
import sys
p = [[int(t) for t in r.split(' ')] for r in sys.stdin.read().split('\n') if r != '']
N, D = p[0]
count = 0
for i in range(1, N):
    for j in range(i + 1, N + 1):
        s = sum(map(lambda t: (t[0]-t[1])**2, [i for i in zip(p[i], p[j])]))
        if int(s**0.5)**2 == s:
            count += 1
print(count)

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

from math import sqrt

res = 0
for i in range(n-1):
    for j in range(i+1, n):
        r2 = sum([(points[i][k]-points[j][k])**2 for k in range(d)])
        if r2 == int(sqrt(r2))**2:
            res += 1
print(res)

Solution (Python):


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

cnt = 0
for i in range(N-1):
    p1 = cor[i]
    for j in range(1, N-i):
        p2 = cor[i+j]
        tmp = 0
        for k in range(D):
            tmp += (p1[k] - p2[k]) ** 2
        if float.is_integer(tmp ** 0.5):
            cnt += 1

print(cnt)

Solution (Python):
import sys
import math


def main():
    N, D = [int(s) for s in sys.stdin.readline().strip().split()]
    X = []
    for i in range(N):
        Xi = [int(s) for s in sys.stdin.readline().strip().split()]
        X.append(Xi)

    sqrts = set()
    sqrts.add(0)

    ans = 0
    for i in range(N-1):
        for j in range(i+1, N):
            dist_sq = sum([(X[i][k] - X[j][k]) ** 2 for k in range(D)])
            if dist_sq in sqrts:
                ans += 1
            else:
                if math.floor(math.sqrt(dist_sq)) == math.ceil(math.sqrt(dist_sq)):
                    ans += 1
                    sqrts.add(dist_sq)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import math

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

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

ans = 0

for i in range(N-1):
    l = 0
    for j in range(i+1, N):
        sum = 0
        for k in range(D):
            t = (X[i][k] - X[j][k])**2
            sum += t
        l = math.sqrt(sum)
        if l.is_integer():
            ans += 1

print(ans)

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

Solution (Python):
import math

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

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

Solution (Python):
import math
"""
def distance(a,b):
    ans=0
    for (i,j) in zip(a,b):
        ans+=(i-j)**2
    return math.sqrt(ans)
"""
n,d=map(int,input().split())
x=[]
for j in range(n):
    tmp=list(map(int,input().split()))
    x.append(tmp)

count=0
for i in range(n-1):
    for j in range(i+1,n):
        ans=0
        for (a,b) in zip(x[i],x[j]):
            ans+=(a-b)**2
        if math.sqrt(ans).is_integer():
            count+=1

print(count)

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

def dis(y,z,dim):
  sum = 0
  for i in range(dim):
    sum += (y[i] - z[i])**2

  return sum**(1/2)

count = 0

for i in range(n-1):
  for j in range(i+1, n):
      distance = dis(point[i], point[j], d)
      if distance == int(distance):
          count += 1

print(count)

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

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

X = []

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


def kyori(x, y, D):
    sum = 0
    for i in range(D):
        sum += (x[i] - y[i]) * (x[i] - y[i])
    return math.sqrt(sum)


count = 0
for i in range(N):
    for j in range(N):
        if i < j:
            if float.is_integer(kyori(X[i], X[j], D)):
                count += 1

print(count)

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

ans = 0
temp = 0

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


for i in range(1,N):
    for j in range(i):
        temp = 0
        for k in range(D):
            temp += (C[i][k] - C[j][k])**2
        dis = math.sqrt(temp)
        if is_integer_num(dis):
            ans += 1 

print(ans)

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

Solution (Python):


import math
import sys
import itertools
import numpy as np



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


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

answer = 0
for j in range(n):
    for i in range(j):
        dist2 = 0
        for k in range(d):
            dist2 += (x[i][k]-x[j][k]) * (x[i][k]-x[j][k])

        dist = math.sqrt(dist2)


        if round(dist)*dist == dist2:
            answer += 1

print(answer)

Solution (Python):
import numpy as np

hoge = input().split()
N = int(hoge[0])
D = int(hoge[1])
X = []
hage = []
for i in range(N):
  huga = input().split()
  for j in range(D):
    hage.append(int(huga[j]))
  X.append(hage)
  hage = []

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

Solution (Python):

n,d=map(int,input().split())
x=[]
for _ in range(n):
    x.append(list(map(int,input().split())))
count=0
distance=0
for i in range(n):
    for j in range(i+1,n):
        distance=[(x[i][m]-x[j][m])**2 for m in range(d)]
        if sum(distance)**(1/2)==int(sum(distance)**(1/2)):
            count=count+1
print(count)

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

Solution (Python):
from sys import stdin
import math
import itertools

N, K = [int(x) for x in stdin.readline().rstrip().split()]
data = [stdin.readline().rstrip().split() for _ in range(N)]
for idx in range(N):
    data[idx] = [int(n) for n in data[idx]]

data_tmp = list(itertools.combinations(data,2))
cnt = 0
for idx, item in enumerate(data_tmp):
    dst = 0
    for n in range(K):
        dst = dst + pow(item[0][n] - item[1][n], 2)
    dst = math.sqrt(dst)
    i = int(dst)
    f = dst - i
    if f == 0.0:
        cnt = cnt + 1
print(cnt)

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

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

XVS = []

for _ in range(N):
    XV = tuple(map(int, input().split()))
    XVS.append(XV)

C = 0
for i, j in combinations(range(N), 2):
    D2 = 0
    for d in range(D):
        D2 += (XVS[i][d] - XVS[j][d]) ** 2
    D1 = sqrt(D2)
    if D1.is_integer():
        C += 1

print(C)

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

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

def euclidian(l1, l2): 
    d = 0
    for i in range(D):
        d += (l1[i] - l2[i])**2
    return d**0.5

for i in range(N):
    for j in range(i+1, N):
        list_1 = X_list[i]
        list_2 = X_list[j]
        if euclidian(list_1, list_2).is_integer():
            result += 1

print(result)

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

Solution (Python):
import math

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

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

print(count)

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

ans = 0
import math
for i in range(N):
    for x in X_list[i+1:]:
        result = 0
        for j in range(D):
            result += (X_list[i][j]- x[j]) ** 2
        if math.sqrt(result).is_integer():
            
            
            ans +=1

print(ans)

Solution (Python):
import math

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


def solve(n, d, x_matrix):
    result = 0
    for i in range(n):
        for j in range(n - i -1):
            distance = math.sqrt(sum([(p1 - p2) ** 2 for p1, p2 in zip(x_matrix[i], x_matrix[j + i + 1])]))
            if distance == int(distance):
                result += 1
    return result


def main():
    n, d, x_matrix = input_from_console()
    print(solve(n, d, x_matrix))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  
        check_cases()
    else:
        main()

Solution (Python):

import decimal
import math
n,d = list(map(int,input().split()))
x = [list(map(lambda x:decimal.Decimal(int(x)),input().split())) for i in range(n)]

def calc_distance(arr1,arr2):
    return math.sqrt(sum(list(map(lambda x,y:(x-y)**2,arr1,arr2))))
ret = 0
for i in range(n):
    for j in range(i):
        if calc_distance(x[i],x[j])%1==0.0:
            ret+=1
print(ret)

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

cnt = 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
        dis = dis**0.5
        if dis == int(dis):
            cnt += 1
print(cnt)

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)
count=0
for i in range(n):
  for j in range(i+1,n):
    f=np.dot((x[i,:]-x[j,:]),(x[i,:]-x[j,:]))**0.5
    if f.is_integer():
      count+=1
print(count)

Solution (Python):
from math import sqrt
n,d =(int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(n)]

tmp = []
sum = 0
for i in range(n):
    for j in range(n):
        if j != i:
            for a in range(d):
                sum += abs(x[i][a]-x[j][a])**2
            tmp.append(sum)
            sum = 0
ans = 0
for i in tmp:
    if sqrt(i).is_integer(): ans += 1
print(ans//2)

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

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

S=[n**2 for n in range(1,130)]

c=0

for i in range(N):
    for j in range(i,N):
        d=0
        for k in range(D):
            d+=(X[i][k]-X[j][k])**2
        for k in range(129):
            if d==S[k]:
                c+=1

print(c)

Solution (Python):
import numpy as np
import itertools

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

cnt = 0
for a, b in itertools.combinations(arr, 2):
    a = np.array(a)
    b = np.array(b)
    diff = a - b
    diff = diff ** 2
    distance = diff.sum() ** 0.5
    if distance == int(distance):
        cnt += 1
print(cnt)

Solution (Python):
import math
d=input().split()
N,D=int(d[0]),int(d[1])
l=[None]*N
for i in range(N):
  l[i]=input().split()
  for j in range(D):
    l[i][j]=int(l[i][j])
a=0
for i in range(N-1):
  for j in range(i+1,N):
    s=0
    for k in range(D):
      s+=(l[i][k]-l[j][k])**2
    if math.sqrt(s)==math.sqrt(s)//1:
      a+=1
print(a)

Solution (Python):
import numpy as np
import itertools
n, d = map(int, input().split())
arr = np.zeros((n, d))
ans = 0
for i in range(n):
  arr[i] = np.array(input().split())
for i in list(itertools.combinations(arr, 2)):
  u = i[0] - i[1]
  d = str(np.linalg.norm(u))
  if d[-1]=='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())))

ans = 0

def ks(x,y):
    p = 0
    for i in range(D):
        p += (x[i]-y[i])**2
    return p**(1/2)



for j in range(N):
    for k in range(N-j-1):
        l = ks(X[j], X[-k-1])
        if l % 1 == 0:
            ans += 1
print(ans)

Solution (Python):
a = input().split()
list_dist = []
for i in range(int(a[0])):
    b = input().split()
    b = [int(i) for i in b]
    list_dist.append(b)


count = 0
for i in range(int(a[0])):
    for u in range(i):
        list_kari = [list_dist[i][t]-list_dist[u][t]
                     for t in range(len(list_dist[i]))]
        num = sum([i ** 2 for i in list_kari])
        num = num**0.5
        if num.is_integer():
            count += 1
print(count)

Solution (Python):
import math

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

cnt = 0

for i in range(n):
    for j in range(n):
        if i ==j:
            continue
        dis_nijo = 0
        for k in range(d):
            dis_nijo += (l[i][k] - l[j][k]) **2
            dis = math.sqrt(dis_nijo)
        if dis ==int(dis):
            cnt += 1

print(cnt//2)

Solution (Python):
import numpy as np
n,d = map(int, input().split())
arr = np.empty((0,d), int)
for i in range(n):
  x = np.array(list(map(int, input().split()))).reshape(1,d)
  arr = np.append(arr, x, axis = 0)
lst = []
for i in range(1,n):
  for j in range(i):
    y = sum((arr[i]-arr[j])**2)**0.5
    if y%1 == 0:
      lst.append(y)
print(len(lst))

Solution (Python):
R = lambda: map(int, input().split())
sq = lambda x: int(x ** 0.5) ** 2 == x
d2 = lambda x, y: sum((u - v) ** 2 for u, v in zip(x, y)) 
n, d = R()
a = [tuple(R()) for _ in range(n)]
print(sum(sq(d2(a[i], a[j])) for i in range(n) for j in range(i)))

Solution (Python):
import queue

"""
N = int(input())



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

print(A)

"""

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

def dist(A,B,D):
	C = 0
	for i in range(D):
		C += (A[i]-B[i])**2
	return C**.5
ans = 0
for i in range(N-1):
	for j in  range(i+1, N):
		dis = dist(X[i],X[j],D)
		if dis == int(dis):
			ans += 1
print(ans)

Solution (Python):
import math
import numpy as np
n,d=map(int,input().split())
c=0
p=[list(map(int,input().split())) for _ in range(n)]
for i in range(n):
  for j in range(n-i):
    j+=i
    d1=np.array(p[i])
    d2=np.array(p[j])
    if i==j:
        continue
    q=math.sqrt(sum((d2-d1)**2))
    if q==int(q):
      c+=1
print(c)

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

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

print(ans)

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

def caldist(a, b, n):
    sum = 0
    for i in range(n):
        sum +=abs(a[i]-b[i])**2
    ans = sum**(0.5)
    return ans

c=0
for i in range(N-1):
    for j in range(i+1,N):
        ans = (caldist(X[i],X[j],D))
        if ans.is_integer():
            c+=1

print(c)

Solution (Python):
import math

n, d = [int(x) for x 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):
    for j in range(i,n):
        if (i == j):
            continue
        dist = 0
        for dd in range(d):
            dist += math.pow(x[i][dd] - x[j][dd], 2)
        dist = math.sqrt(dist)
        if dist == int(dist):
            count += 1
print(count)

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,201)]


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 = map(int,input().split(' '))
Xs = []
for i in range(N):
    Xs.append(np.array(list(map(int,input().split()))))

int_cnt = 0
for i in range(len(Xs)-1):
    for j in range(i+1,len(Xs)):
        X = Xs[i]-Xs[j]
        s = 0
        for k in range(D):
            s += X[k]**2
        if (s**(1/2)).is_integer() == True:
            int_cnt += 1
print('{}'.format(int_cnt))

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

Solution (Python):
import math
n,d=map(int,input().split())
x=[]
for i in range(n):
    s=list(map(int,input().split()))
    x+=[s]
rote=0
ans=0
for i in range(n):
    for j in range(n):
        for y in range(d):
            rote+=(x[i][y]-x[j][y])**2
        roteans=math.sqrt(rote)
        if rote==0:
            break
        elif roteans%1==0:
            ans+=1
        rote=0
print(ans)

Solution (Python):
import numpy as np
N,D = map(int,input().split())
XD = [list(map(int,input().split()))  for i in range(N)]
dis = 0
count = 0
for i in range(N):
    for j in range(N-i):
        if j == 0:
            continue
        for k in range(D):
            dis += (abs(XD[i][k]-XD[j+i][k]))**2
        if int(np.sqrt(dis)) == np.sqrt(dis):
            count += 1
        dis = 0

print(count)

Solution (Python):
import copy
import sys
from bisect import bisect_left, bisect_right
from collections import ChainMap, Counter, deque, defaultdict, namedtuple
from fractions import gcd
from heapq import heappop, heappush
from itertools import accumulate
from math import ceil, floor, sqrt
from operator import itemgetter




tolerance = 1e-30


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

    e = floor(sqrt(d)) ** 2

    return abs(d - e) < tolerance


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

    xs = [[int(x) for x in input().split(' ')] for _ in range(n)]

    count = 0

    for i in range(n):
        for j in range(i + 1, n):
            x = xs[i]
            y = xs[j]
            if is_dist_int(x, y):
                count += 1

    print(count)


if __name__ == '__main__':
    main()

Solution (Python):

import math

N, D = map(int, input().split())
p = [[0 for n in range(D)] for m in range(N)]


for i in range(N):
    input_line = input().split(' ')
    p_line = [int(s) for s in input_line]
    for j in range(D):
        p[i][j] = p_line[j]


cnt = 0
for i in range(N):
    for j in range(i,N):
        if i == j:
            continue

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

Solution (Python):
import numpy as np 

def main():
    n,d=map(int,input().split())
    
    x=[]
    for i in range(n):
        tmp=list(map(int,input().split()))
        x.append(np.array(tmp))
    
   

    cnt=0
    
    for k in range(n-1):
        for l in range(k+1,n):
            dist=np.sqrt(np.sum((x[k]-x[l])*(x[k]-x[l])))

            if float.is_integer(dist):
                cnt+=1

    print(cnt)

if __name__=="__main__":
    main()

Solution (Python):


import numpy as np


def main():

   in0 = input()

   IN = in0.split(' ')

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

   X = np.zeros((N,D))

   for i in range(N):
      in0 = input()
      IN = in0.split(' ')
      for j in range(D):
         X[i,j] = int(IN[j])


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

         dist = np.sqrt(dis)

         i_dist = int(dist)

         if((dist - i_dist)==0):
            cnt = cnt + 1


   print ("%s" % (cnt))




if __name__ == "__main__":
   main()

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

l = []

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





cnt = 0



for i in range(n) :

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

		s = 0
		
		for k in range(d):

			s += ( l[i][k] - l[j][k]) ** 2 
		result = s ** (1/2)

		if result.is_integer():
			cnt += 1

print(cnt)

Solution (Python):
import math

s = input().rstrip().split(' ')
N = int(s[0])
D = int(s[1])

cnt = 0
d_list = []

for i in range(N):
  d_list.append(input().rstrip().split(' '))

for i in range(N-1):
  for n in range(i+1, N):
    num = 0
    for d in range(D):
        num += (int(d_list[i][d]) - int(d_list[n][d])) ** 2
    
    test = math.sqrt(num)
    
    if test.is_integer():
      cnt += 1
    
print(cnt)

Solution (Python):
import math
import itertools

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

X = []

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

def kyori2jou(p1, p2):
    sum = 0
    for x1, x2 in itertools.zip_longest(p1, p2):
        sum += (x1 - x2) ** 2
    return sum

count = 0
for i in range(len(X)):
    for j in range(i+1, len(X)):
        p1 = X[i]
        p2 = X[j]
        if p1 == p2:
            continue
        k2 = kyori2jou(p1, p2)
        k1 = math.sqrt(k2)
        k1int = round(k1)
        if k2 == k1int**2:
            count += 1

print(count)

Solution (Python):
import numpy as np


def calc(mat: np.array) -> int:
    count = 0
    for alpha in range(mat.shape[0] - 1):
        for beta in range(alpha + 1, mat.shape[0]):
            distance = np.linalg.norm(mat[alpha] - mat[beta])
            if np.abs(distance - int(distance)) < 0.001:
                count += 1
    return count


def load_input_as_int_array():
    return [int(v) for v in input().split(" ")]


n, d = load_input_as_int_array()
mat = []
for i in range(n):
    raw = load_input_as_int_array()
    mat.append(raw)

mat_array = np.asarray(mat)
print(calc(mat_array))

Solution (Python):
def kyori(l1,l2):
    l=sum([(l1[i]-l2[i])**2 for i in range(len(l1))])
    if l**0.5==int(l**0.5):
        return 1
    else:
        return 0

def resolve():
    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):
            ans+=kyori(x[i],x[j])
    print(ans)
resolve()

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):
  for j in range(i+1, n):
    distance = math.sqrt(sum([
      (a - b) ** 2
      for a, b in zip(x[i], x[j])
    ]))
    if distance == int(distance):
      count += 1
print(count)

Solution (Python):

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

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