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

print(count)

Solution (Python):

import numpy as np

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

for i in range(n):
    x_ = list(map(int, input().split()))
    x.append(x_)
    
is_integer = 0
x = np.asarray(x)

for j in range(0,n,1):
    for i in range(0,j,1):
        diff  = (sum((x[i] - x[j]) ** 2)) ** (1 / 2)
        if diff.is_integer():
            is_integer += 1
            
print(is_integer)

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

cnt=0
for k in range(n):
    for j in range(k+1,n):
        dist=0
        for i in range(d):
            dist+=(x[k][i]-x[j][i])**2
        val=dist**0.5-dist**0.5//1
        if val==0:
            cnt+=1
print(cnt)

Solution (Python):



def xcheck(n):
	
    m = int(n**.5)
    return 1 if abs(m*m - n) < 1e-6 else 0





tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
n=hoge[0]
d=hoge[1]


listx = [[0 for i in range(d)] for j in range(n)]

for i in range(n):
	tmp = input().split()
	hoge = list(map(lambda a: int(a), tmp))
	
	for j in range(d):
		listx[i][j] = hoge[j]

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

		tmp=0
		for k in range(d):

			tmp += pow((listx[i][k]-listx[j][k]),2)





		sum += xcheck(tmp)

print(sum)

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

def distance(a, b):
    dis = 0
    for d in range(D):
        dis += (a[d] - b[d])**2
    return np.sqrt(dis)

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

ans = 0
for i in range(N):
    for j in range(i+1, N):
        if(i == j):
            continue
        dis = distance(points[i], points[j])
        ans += (dis % 1) == 0.0
print(ans)

Solution (Python):
import numpy as np
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(len(x)):
    for j in range(len(x)-i-1):
        dis = 0
        for k in range(D):
            dis += (x[i][k]-x[i+j+1][k])**2
        if (math.sqrt(dis).is_integer()):
            count += 1
print(count)

Solution (Python):
import numpy as np

N,D=map(int, input().split())
S = []
for _ in range(N):
    S.append(list(map(int, input().split())))
x=0
S=np.array(S)
for i in range(N):
    for j in range(i):
        t=np.linalg.norm(S[i]-S[j])
        if t == int(t):
            x+=1      
print(x)

Solution (Python):
import math

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

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

tmp = 0
cnt = 0

for i in range(N):
    for j in range(i+1,N):
        tmp = 0
        for d in range(D):
            tmp += math.pow(abs(X[i][d]-X[j][d]),2)
        tmp = math.sqrt(tmp)
        if tmp.is_integer():
            cnt += 1

print(cnt)

Solution (Python):
import math

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


all_list = []

for i in range(n):
    x = input()
    x = x.split(' ')

    
    
    x = [float(v) for v in x] 

    all_list.append(x)  



cnt = 0

for i in range(n):
    target = all_list[i]

    for j in range(n - (i + 1)):
        target2 = all_list[j + i + 1]

        
        sum_1 = [(target[q] - target2[q]) ** 2 for q in range(d)]
        sum_2 = sum(sum_1)
        dis = math.sqrt(sum_2)

        
        
        

        if dis.is_integer():
            cnt += 1

print(cnt)

Solution (Python):
import numpy as np
n,D=map(int,input().split())
a = [input().split() for l in range(n)]
c=0
d=0
for i in range(n):
  for j in range(i+1,n):
    d=0
    for t in range(D):
      d=d+(int(a[i-1][t-1])-int(a[j-1][t-1]))**2
    if np.sqrt(d)%1==0:
      c=c+1
print(c)

Solution (Python):

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

answer = 0
for u,v in itertools.combinations(X,2):
  d = ((u-v) * (u-v)).sum()
  dd = int(round(d**.5))
  if d == dd*dd:
    answer += 1

print(answer)

Solution (Python):
import numpy as np
n,d = map(int,input().split())
list=[list(map(int,input().split())) for i in range(n)]
arr_list = np.array(list)
count = 0
for i in range(n):
    for j in range(i+1,n):
        if(i != j):
            distance = 0.0
            for k in range(d):
                distance += (arr_list[i][k] - arr_list[j][k])**2
            if(distance > 0):
                result = np.sqrt(distance)
                if(result.is_integer()):
                    count += 1
print(count)

Solution (Python):
import math
N,D=map(int,input().split())
points = []
num = 0
for n in range(N):
    p = [ int(i) for i in input().split()]
    points.append(p)

for i in range(len(points)):
    for j in range(len(points) - i - 1):
        sum = 0
        for k in range(D):
            sum += (points[i][k]-points[i+j+1][k])**2
        if float.is_integer(math.sqrt(sum)):
            num += 1
print(num)

Solution (Python):
import math
N,D = map(int,input().split())
ans = 0
X_list = []
for a in range(N):
    X_list.append(list(map(int,input().split())))
for i in range(N):
    for j in range(i+1,N):
        rutononaka = 0
        for d in range(D):
            rutononaka += (X_list[i][d]-X_list[j][d])**2
        distance = math.sqrt(rutononaka)
        if distance == (distance//1):
            ans += 1
print(ans)

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

A = []
for i in range(n):
    for k in range(i + 1, n):
        tmp = 0
        for j in range(d):
            tmp += (L[i][j] - L[k][j]) ** 2
        A.append(pow(tmp, 0.5))

ans = 0

for i in A:
    if i.is_integer():
        ans += 1

print(ans)

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

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

cnt=0
for j in range(N-1):
  for k in range(j+1,N):
    wa=0
    for l in range(D):
      wa += (X[j][l]-X[k][l])**2
    result=wa**(1/2)
    if result.is_integer():
      cnt+=1

print(cnt)

Solution (Python):
import math
import itertools

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

X = [[0]*(D+1)]*(N+1)

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

def distance(x, y):
    dis = 0
    for d in range(D):
        dis += abs(x[d] - y[d]) ** 2
    
    return math.sqrt(dis).is_integer()
    
distance(X[1], X[2])

count = 0

for c in itertools.combinations(list(range(N)), 2):
    if distance(X[c[0]], X[c[1]]):
        count += 1
        
print(count)

Solution (Python):



import sys
import math

input = sys.stdin.readline

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

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

main()

Solution (Python):
_input = [i for i in open(0).read().split('\n') if i]
n, d = [int(i) for i in _input[0].split()]
x_list = [[int(i) for i in x.split()]for x in _input[1:]]
x_list2 = x_list[:]

import math

count = 0
for x1 in x_list:
    for x2 in x_list2:
        dist = math.sqrt(sum((x1[i]-x2[i])**2 for i in range(d)))
        if int(dist) == 0:
            continue
        if dist.is_integer():
            count += 1

print(count//2)

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

for i in range(n):
    for j in range(n):
        if i <  j:
            x = 0
            for k in range(d):
                x += (li[i][k] - li[j][k]) ** 2
            li2.append(x)
for a in li2:
    for i in range(1,a//2 + 2):
        if a == i**2:
            cnt += 1
print(cnt)

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

import numpy as np

res=0

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

print(res)

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


for i in range(n-1):
    for j in range(i+1,n):
        count1 = 0
        for s in range(d):
            count1 += (alllist[i][s]-alllist[j][s])**2
        if math.sqrt(count1) == int(math.sqrt(count1)):
            count += 1
print(count)

Solution (Python):
import math
def dist_is_int(x, y):
  d2 = 0
  for i in range(len(x)):
    diff = x[i] - y[i]
    d2 += diff * diff
  
  cand = int(math.sqrt(d2))
  return cand * cand == d2

n, d = [int(v) for v in input().split()]
x_s = [[int(v) for v in input().split()] for _ in range(n)]

ans = 0
for i in range(n):
  for j in range(i + 1, n):
    if dist_is_int(x_s[i], x_s[j]):
      ans += 1
print(ans)

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

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


for i in range(len(p_list)):
    for j in range(i+1, len(p_list)):
        dis = 0
        for k in range(d):
            dis += (p_list[i][k] - p_list[j][k]) ** 2
        
        t_dis = math.sqrt(dis)
        
        if round(t_dis) == t_dis:
            ans += 1

print(ans)

Solution (Python):
import math

def dis(n,x,y):
    distance = 0
    for i in range(len(x)):
        distance += (x[i]-y[i])*(x[i]-y[i])
    
    return math.sqrt(distance)



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

ans = 0
for i in range(n):
    for j in range(i+1,n):
        
        
        if(dis(d,x[i],x[j]).is_integer()):
            ans += 1
print(ans)

Solution (Python):
import math
n,d = map(int,input().split())
positions = [list(map(int,input().split())) for _ in range(n)]
ans = 0
for i in range(n):
    for j in range(n):
        pre = 0
        if i == j:
            continue
        for k in range(d):
            pre += abs(positions[j][k]-positions[i][k])**2
            
                
        pre = math.sqrt(pre)
        if pre % 1 == 0:
            pre = int(pre)
        
        if isinstance(pre,int):
            ans += 1
print(ans//2)

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

for i in range(N):
    for j in range(i+1,N):
        tmp = 0
        for k in range(D):
            tmp += abs(x[i][k]-x[j][k])**2
        tmp = tmp**0.5
        if tmp.is_integer() == True:
            count += 1
print(count)

Solution (Python):
import math
def goodDistance():
	N, D = map(int, input().split())
	X = [0] * (N + 1)
	for i in range(1, N + 1):
		X[i] =  list(map(int, input().split()))
	count = 0
	
	for i in range(1, N + 1):
		for j in range(i + 1, N + 1):
			sum = 0
			for k in range(0, D):
				sum += abs(X[i][k] - X[j][k]) ** 2
				distance = math.sqrt(sum)
			
			if distance.is_integer():
				count += 1
	print(count)

goodDistance()

Solution (Python):
import math

inp_1 = input().split()
n = int(inp_1[0])
d = int(inp_1[1])

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

def kyori(x_list,y_list):
    dim = len(x_list)
    kyori_nibeki = 0
    for i in range(dim):
        kyori_nibeki = kyori_nibeki + (x_list[i] - y_list[i])**2
    return math.sqrt(kyori_nibeki)


count = 0
for i in range(n):
    for j in range(n):
        if j > i:
            kyori_compare = kyori(input_matrix[i],input_matrix[j])
            if kyori_compare ==  math.floor(kyori_compare):
                count = count + 1

print(count)

Solution (Python):
import math

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

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

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

print(ans)

Solution (Python):
import math
n,d = list(map(int,input().split()))
x = []
result = 0
def func(i,j):
        pythagoras= 0
        for k in range(d):
                pythagoras += (i[k]-j[k])*(i[k]-j[k])
        if math.sqrt(pythagoras)%1 == 0:
                return True
        else:
                return False

for i in range(n):
        x.append(list(map(int,input().split())))
for i in range(n):
        for j in range(i+1,n):
                if func(x[i],x[j]): 
                        result += 1
print(result)

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

list = []
for i in range(n):
  a = [int(i) for i in input().split()] 
  list.append(a)
count = 0
for i in range(n):
  for j in range(n):
    if j > i:
      root = 0
      root2 = 0
      for k in range(d):
        tmp = (list[i][k] - list[j][k])*(list[i][k] - list[j][k])
        root = root + tmp
      root3 = math.sqrt(root)
      if root3.is_integer():
           count = count +1
print(count)

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

def calc(arr1, arr2):
    tmp = 0
    for i, j in zip(arr1, arr2):
        tmp += abs(i - j) ** 2
    if str(tmp ** 0.5).split('.')[1] == '0':
        return 1
    return 0

for i in range(n):
    for j in range(i+1, n):
        ans += calc(x[i], x[j])

print(ans)

Solution (Python):
import math

i = list(map(int, input().split(" ")))
n = i[0]
d = i[1]
x = []
total = 0

for x_n in range(n):
    xx = list(map(int, input().split(" ")))
    x.append(xx)

for x_n in range(len(x)):
    a = x[x_n]
    for x_d in range(x_n+1, len(x)):
        b = x[x_d]
        t = [(aa - bb)**2 for aa, bb in zip(a, b)]
        t = math.sqrt(sum(t))
        if t.is_integer():
            total += 1
print(total)

Solution (Python):

N,D=map(int,input().split())
x=[]
for i in range(N):
    z=list(map(int,input().split()))
    x.append(z)
count=0
for i in range(N):
    for j in range(N-i-1):
        d=0
        for k in range(D):

            d+=(x[i][k]-x[j+i+1][k])**2
        d=d**(0.5)

        
        if d%1==0:
            
            count+=1
print(count)

Solution (Python):
import numpy as np

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

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

X=np.array(X)
result=0
for i in range(N-1):
    for j in range(i+1,N):
        diff=X[i]-X[j]
        distance=np.sum(np.square(diff))
        if int(np.sqrt(distance))==np.sqrt(distance):
            result+=1

print(result)

Solution (Python):
import math

N,D = map(int, input().split())
points = []
for i in range(N):
    points.append(list(map(int, input().split())))
count = 0
for i in range(N):
    for j in range(i + 1, N):
        b = []
        for k in range(D):
            b.append((points[i][k] - points[j][k])**2)
        b = sum(b)
        b = math.sqrt(b)
        if int(b) == b:
            count += 1

print(count)

Solution (Python):
import math

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

all_d = []

for i in range(N-1):
  for j in range(N-1-i):
    nijo = []
    nijo_sum = 0
    for k in range(D):
      nijo.append((points[i][k]-points[i+j+1][k])**2)
    for k in range(D):
      nijo_sum += nijo[k]
    all_d.append(math.sqrt(nijo_sum))

  
count = 0
for i in range(len(all_d)):
  if (all_d[i]%1) == 0:
    count += 1
print(count)

Solution (Python):
import math
n,d = map(int,input().split())
counter = 0
x = []
tmp = 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):
        if tmp != 0:
            tmp = 0
        for k in range(d):
            tmp +=(abs(x[i][k] - x[j][k]))**2
        if float.is_integer(math.sqrt(tmp)):
            counter +=1
print(counter)

Solution (Python):
N, D = list(map(int, input().split()))
X = []
for _ in range(N):
    x = list(map(int, input().split()))
    X.append(x)
ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        s = [xi - xj for xi, xj in zip(X[i], X[j])]
        e = [ss**2 for ss in s]
        t = sum(e)
        for k in range(40*40*D+1):
            if t == k**2:
                ans += 1
                break
print(ans)

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

count = 0
for j in range(n-1):
    for k in range(n-j-1):
        dis = 0
        for l in range(d):
            dis += abs(x[j][l] - x[j+k+1][l]) ** 2

        if math.ceil(math.sqrt(dis)) == int(math.sqrt(dis)):
            count += 1

print(count)

Solution (Python):
import numpy as np
import itertools

if __name__ == "__main__":
    n = list(map(int, input().split()))
    l = [np.array(list(map(int, input().split()))) for i in range(n[0])]

    n = 0

    for v in itertools.combinations(l, 2):
        
        distance = np.linalg.norm((v[0] - v[1]), ord=2)
        
        
        if distance % 1 == 0:
            n += 1

    print(n)

Solution (Python):
import sys
inputs = sys.stdin.readlines()
N, D = map(int, inputs[0].split())
x_list = []
for x in inputs[1:]:
    x_list.append(list(map(int, x.split())))
    
from itertools import combinations
from math import sqrt, floor
count = 0
for i, j in combinations(range(N), 2):
    s = 0
    for k in range(D):
        s += (x_list[i][k] - x_list[j][k]) ** 2
    if floor(sqrt(s)) ** 2 == s:
        count += 1
        
print(count)

Solution (Python):
import math

n, d = tuple([int(s) for s in input().split()])
x = [[0]*d for i in range(n)]

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

cnt_fit = 0

for i in range(n-1):
    for j in range(i+1, n):
        sumd = 0
        for k in range(d):
            sumd += (x[i][k] - x[j][k]) ** 2
        sumd = math.sqrt(sumd)
        if sumd - int(sumd) == 0.0:
            cnt_fit += 1

print(cnt_fit)

Solution (Python):
import numpy as np

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

X = [0] * N

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

ok = 0

for i in range(N):
    for j in range(i+1,N):
        sum = 0
        for k in range(D):
            sum += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k])
        sum = np.sqrt(sum)
        if sum.is_integer() == True:
            ok += 1

print(ok)

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

line=[]
count=0

for i in range(n):
    line.append(list(map(int,input().split( ))))
    
    if i>=1:
        for j in range(i):
            
            if float(np.linalg.norm(np.array(line[i])-np.array(line[j]))).is_integer():
                count+=1

print(count)

Solution (Python):
import math

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

ans = 0
for i in range(n):
    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.is_integer():
            ans += 1

print(ans)

Solution (Python):

import sys

import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n, d = readmi()
t = []
for i in range(n):
    k = readl()
    t.append(k)
count = 0
b = defaultdict(lambda:defaultdict(int))
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        if b[i][j] == 1:
            continue
        b[i][j] = 1
        b[j][i] = 1
        p = 0
        for k in range(d):
            p += abs(t[i][k] - t[j][k]) ** 2
        if float.is_integer(math.sqrt(p)):
            count += 1
print(count)

Solution (Python):
n, d = map(int, input().split(' '))
a = [list(map(int,input().split(' '))) for i in range(n)]
res = 0
for i in range(n-1):
    for j in range(i+1, n):
        count = 0
        for k in range(d):
            count += (a[i][k]-a[j][k])**2
        count = count**(1/2)
        if (count.is_integer()) is True:
            res += 1
print(res)

Solution (Python):
def sqrtjudge(n):
    m = int(pow(n,0.5))
    return 1 if abs(m*m - n) < 1e-6 else 0

n,d = [int(i) for i in 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):
        ans += sqrtjudge(sum(pow(x[i][k]-x[j][k],2) for k in range(d)))

print(ans)

Solution (Python):
import sys
import math


def input():
    return sys.stdin.readline()[:-1]


def main():
    n, d = map(int, input().split())
    x = []
    ans = 0
    for i in range(n):
        x.append([int(i) for i in input().split()])

    for a in range(0, n-1):
        for c in range(a+1, n):
            s = 0
            for b in range(d):
                s += abs(x[a][b]-x[c][b])**2
            if math.floor(math.sqrt(s)) == math.sqrt(s):
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):



import sys
import math

import numpy as np
def myinput_int():
    return list(map(int, input().split()))

N,D = myinput_int()

X=[]
for i in range(N) :
    X.append(myinput_int())

X = np.asarray(X)

counter=0
for i in range(N) :
    for j in range(i+1, N) :
        if np.sqrt(np.sum((X[i]-X[j])**2)).is_integer()==True:
            counter+=1

print(counter)

Solution (Python):
from math import sqrt

n, d = map(int, input().split())
x = []
for _ in range(n):
    x.append(list(map(int, input().split())))
ans = 0
for i in range(n):
    for j in range(n):
        if i != j:
            t = 0
            for a, b in zip(x[i], x[j]):
                t += abs(a - b)**2
            if sqrt(t) == int(sqrt(t)):
                ans += 1

print(ans//2)

Solution (Python):
from math import sqrt
a,b=input().split()
a=int(a)
b=int(b)
ll=[]
ans=0
for i in range(a):
  x=input().split()
  x=[int(i) for i in x]
  ll.append(x)
for i in ll:
  s=0
  for j in ll:
    if i==j:
      s=1
      continue
    elif s==0:
      continue
    x=0
    for k in range(b):
      x+=(i[k]-j[k])**2
    if sqrt(x)%1==0:
      ans+=1
print(ans)

Solution (Python):
import numpy as np

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



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

    except:
        break;
        





cnt = 0

for i in range(N):
	for j in range(N):
		if i!=j and i < j: 
			dist = 0
			for k in range(D):
				dist += (listA[i][k] - listA[j][k])**2
			
			if np.sqrt(dist).is_integer()==1:
				cnt += 1


print(cnt)

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):
        cnt = 0
        for k in range(D):
            cnt += abs(x[i][k] - x[j][k]) ** 2
        ans = math.sqrt(cnt)
        if ans.is_integer():
            count += 1
print(count)

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
for i in range(n-1):
    for j in range(i+1,n):
        nor = math.sqrt(sum([(x[i][k]-x[j][k])**2 for k in range(d)]))
        
        if nor.is_integer():

            ans+=1

print(ans)

Solution (Python):
from math import floor,ceil
n,d=map(int,input().split())
P=[list(map(int,input().split())) for _ in range(n)]
def judge(A,B):
    d=len(A)
    s=0
    for i in range(d):
        s+=(A[i]-B[i])**2
    s=s**0.5
    return floor(s)==ceil(s)
ans=0
for i in range(n):
    for j in range(i+1,n):
        ans+=judge(P[i],P[j])
print(ans)

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

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        tmp = np.sum((X[i] - X[j]) ** 2)
        if tmp % np.sqrt(tmp) == 0.0:
            ans += 1
print(ans)

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

ten = []

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

count = 0
for i in range(N):
    s = 0
    for j in range(i+1, N):
        for k in range(D):
            ss = ten[i][k]-ten[j][k]
            if ss < 0: ss = -ss

            s2 = pow(ss, 2)

            s += s2

        ans = math.sqrt(s)
        if ans.is_integer()==True:
            count += 1
        s = 0

print(count)

Solution (Python):
import itertools

n,d=map(int,input().split())
x=[]
for i in range(n):
    x.append(list(map(int,input().split())))
cnt=0
for k in itertools.combinations(x,2):
    tmp=0
    for m in range(d):
        tmp+=(k[0][m]-k[1][m])**2
    for l in range(200):
        if l**2==tmp:
            cnt+=1
            break
        else:
            pass
print(cnt)

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


import itertools,math
dis = []
for x in itertools.combinations(x_list_kai,2):
    distance = 0
    for dim in range(0,d):
        result  = 0
        for y in x:
            if result == 0:
                result = y[dim]
            else:
                result -= y[dim]
            
        result  = result **2
        distance += result
    dis.append(math.sqrt(distance))
    
counter = 0
for i in dis:
    if i.is_integer() == True:
        counter += 1
print(counter)

Solution (Python):
N, D = map(int,input().split())
listA = []
for i in range(N):
    listA.append(list(map(int,input().split())))
import numpy
a = 0
for i in range(N - 1):
    for j in range(i+1):
        b = numpy.linalg.norm((numpy.array(listA[i+1])-numpy.array(listA[j])))
        if b-int(b) == 0:
            a += 1
print(a)

Solution (Python):
from enum import Enum
from queue import Queue
import collections
import numpy as np


import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

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 += abs(X[i][k]-X[j][k])**2
        dist = np.sqrt(dist)
        if dist.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 = [int(n) for n in input().split()]
    X.append(x)

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

Solution (Python):
from math import sqrt

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):
        dist = sqrt(sum([(x1-x2)**2 for (x1, x2) in zip(x[i], x[j])]))
        if dist.is_integer():
            cnt += 1

print(cnt)

Solution (Python):
import math


def distance(X, Y):
    d = 0
    for x, y in zip(X, Y):
        d += (x - y)**2
    return math.sqrt(d)


str = input()

N, D = map(int, str.split(" "))

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

X = list(map(list, X))

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

print(count)

Solution (Python):
import math

def judge_d(a,b):
    ans = 0
    for i, j in zip(a, b):
        ans += (i-j)**2

    if math.sqrt(ans).is_integer():
        return 1
    else:
        return 0



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

for i,v in enumerate(x):
    
    if n-i >1:
        for j in range(i+1,n):
            
            ans += judge_d(x[i],x[j])

print(ans)

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

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

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

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



nums = []

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

ans = 0
tmp = 0
for i in range(n-1):

    for j in range(i+1, n):
        tmp = 0
        for k in range(d):
            tmp += (nums[i][k] - nums[j][k])**2


        
        if math.sqrt(tmp).is_integer():
            
            ans += 1

                

print(ans)