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())
ans=0
a=[]
for i in range(n):
  a.append(list(map(int,input().split())))
for i in range(n-1):
  for j in range(i+1,n):
    dis=0
    for k in range(d):
      dis+=(a[i][k]-a[j][k])**2
    if(math.sqrt(dis)-math.floor(math.sqrt(dis))==0):
      ans+=1
print(ans)

Solution (Python):

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

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


counter = 0

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

        
        if int(round(math.sqrt(float(tmp)))**2) == tmp:
            counter += 1


print(counter)

Solution (Python):
N, D = map(int, input().split(" "))
X = [list(map(int, input().split(" "))) for i in range(N)]
dist = []
n = 0
while n * n <= 16000:
    dist.append(n * n)
    n += 1


def Dis(x, y):
    return sum([(a - b)**2 for a, b in zip(x, y)])


cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        dd = Dis(X[i], X[j])
        for d in dist:
            if dd == d:
                cnt += 1
                break
print(cnt)

Solution (Python):

import sys
import math
def isSquare(x):
    x_sqrt = int(math.floor(math.sqrt(x)))
    if x_sqrt * x_sqrt == x:
        return True
    else:
        return False

def distSquare(a, b, D):
    result = 0
    for i in range(D):
        result += (a[i]-b[i]) * (a[i]-b[i])
    return result

def solve(N: int, D: int, X: "List[List[int]]"):
    count = 0
    for i in range(N):
        for j in range(i+1, N):
            if isSquare(distSquare(X[i], X[j], D)):
                count += 1
    print(count)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    D = int(next(tokens))  
    X = [ [ int(next(tokens)) for _ in range(D) ] for _ in range(N) ]  
    solve(N, D, X)

if __name__ == '__main__':
    main()

Solution (Python):
import math

def main():
    N, D = map(int, input().split())
    points = []
    for i in range(N):
        p = [int(c) for c in input().split()]
        points.append(p)

    count = 0
    for i in range(N-1):
        for j in range(i+1, N):
            v = 0
            for k in range(D):
                v += pow(points[i][k]-points[j][k], 2)
            vsqrt = math.sqrt(v)
            if int(vsqrt) == vsqrt:
                count += 1
    return count

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

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

for i in range(n):
    X[i] = np.array( list(map(int,input().split())) )
cnt = 0
for j in range(n):
    for k in range(1,n-j):
        if (np.sqrt(sum((X[j] - X[j+k])**2))).is_integer():
            cnt += 1
print(cnt)

Solution (Python):
def solve(X:list, N:int):
    cnt = 0
    for i in range(N):
        for j in range(i):
            dist = 0
            for a, b in zip(X[i], X[j]):
                dist += (a-b)**2
            if dist**.5%1 == 0:
                cnt += 1
    print(cnt)

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

if __name__ == "__main__":
    main()

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

Solution (Python):
N,D=map(int,input().split())
List=[list(map(int,input().split())) for i in range(N)]
i=0
tmp=0 
k=1 
ans=0 

for n in range(N):
    for m in range(n+1,N):
        for d in range(D): 
            tmp+=(List[n][d]-List[m][d])**2
        while k**2 <= tmp:
            if k**2 == tmp:
                ans+=1
            k+=1
        tmp,k=0,0
print(ans)

Solution (Python):
input_data = input().split(" ")
N = int(input_data[0])
D = int(input_data[1])
p_data = [list(map(lambda x:int(x),input().split(" "))) for i in range(N)]
distance = []

for n in range(N):
  for t in range(n,N):
    if n == t:
      pass
    else:
      tes = list(map(lambda x,y:(x-y)**2,p_data[n],p_data[t]))
      dis = (sum(tes)**0.5).is_integer()
      distance.append(dis)

print(sum(distance))

Solution (Python):

N,D=list(map(int, input().split()))
X=[]
A=0
B=[]
for i in range(N):
    X.append(list(map(int, input().split())))
for i in range(N):
    for v in range(i+1,N):
        A=0
        for x in range(D):
            A+=(X[i][x]-X[v][x])**2
            if x==D-1:
                B.append(A)
C=0
for i in B:
    for v in range(1,i+1):
        if i/v==v:
            C+=1
            break
print(C)

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

Solution (Python):
N, D = map(int, input().split())
table = []
for _ in range(N):
    row = list(map(int, input().split()))
    table.append(row)
cnt = 0
for i in range(N):
    for k in range(i+1, N):
        diff = 0
        for d in range(D):
            diff += (table[i][d] - table[k][d]) ** 2
        result = diff ** 0.5
        if float(int(result)) == result:
            cnt += 1
print(cnt)

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

ans = 0

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

Solution (Python):
import numpy as np

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

tmp = 0
ans = 0
  
for i,a in enumerate(point):
  for j in range(i+1,n):
    for k in range(d):
      tmp += (a[k]-point[j][k])**2
    if np.sqrt(tmp).is_integer():
      ans += 1
    tmp = 0
    
print(ans)

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



list_mapping = []
for n in range(N):
  mapping = list(map(int,input().split(' ')))
  list_mapping.append(mapping)

  

cnt = 0

for m in list_mapping:
  
  for n in range(N):
    _ = list_mapping[n]
    if m != _:
      dis_2 = [(x - y) ** 2 for (x, y) in zip(m, _)]
      dis = sum(dis_2) ** (1/2)
    else:
      continue
    
    if dis.is_integer():
      cnt += 1
      
print(int(cnt / 2))

Solution (Python):
import numpy as np

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

cnt = 0
for n in range(N - 1):
    for n2 in range(n + 1, N):
        if (((X[n] - X[n2]) ** 2).sum() ** 0.5).is_integer():
            cnt += 1

print (cnt)

Solution (Python):

import math
import itertools




ans = 0

cal = []

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


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


counter = [i for i in range(N)]

comb = itertools.combinations(counter, 2)

li_comb = []
for i in comb:
    li_comb.append(i)


for i in range(len(li_comb)):
    for j in range(D):
        cal.append(pow(G[li_comb[i][0]][j]-G[li_comb[i][1]][j],2))
    if math.sqrt(sum(cal)).is_integer() :
        ans += 1
    cal = []

print(ans)

Solution (Python):
n, D = map(int, input().split())
points = [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):
        pre_distance = 0
        for d in range(D):
            pre_distance += (points[i][d] - points[j][d])**2

        distance = pre_distance ** 0.5
        if distance.is_integer():
            ans += 1

print(ans)

Solution (Python):
def f(a, b):
  res = 0
  for x, y in zip(a, b):
    res += (x - y) ** 2
  res **= 0.5
  return res.is_integer()
  
N, D = [int(x) for x in input().split()]
XND = ['' for _ in range(N)]
for n in range(N):
  XND[n] = [int(x) for x in input().split()]

res = 0
for a in range(N - 1):
  for b in range(a + 1, N):
    if f(XND[a], XND[b]):
      res += 1
print(res)

Solution (Python):
import numpy as np
import itertools

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


count = 0

c = list(itertools.combinations(x,2))
c = np.array(c)
for i in c:
  k = np.linalg.norm(i[0]-i[1])
  
  if k.is_integer():
    count +=1

print(count)

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

x = np.array(input().split(" ") , dtype="int32")
ans = 0
for i in range(N-1):
    x = np.append(x, np.array(input().split(" ") , dtype="int32"))
x = x.reshape(N , D)
for i in range(N):
    for n in range(i+1 , N):
        dist = np.linalg.norm(x[i] - x[n])
        if math.ceil(dist)==math.floor(dist):
            ans += 1
print(ans)

Solution (Python):
import numpy as np
import math
inp = [int(v) for v in input().split(' ')]
N = inp[0]
D = inp[1]
data = []
for i in range(N):
    data.append(np.array([float(v) for v in input().split(' ')]))

cnt = 0
for n1 in range(N):
    for n2 in range(n1 + 1, N):
        l = math.sqrt(np.sum((data[n1] - data[n2]) ** 2)) 
        if int(l) == l:
            cnt += 1

print(cnt)

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

Solution (Python):
tmp=input().split()
n=int(tmp[0])
d=int(tmp[1])
xn = [0]*n
num = 0

for i in range(n):
  xn[i] = input().split()
    
for i in range(n):
  for j in range(i+1, n):
    dist = 0
    for k in range(d):
      dist = dist + pow(int(xn[i][k])-int(xn[j][k]), 2)


    if dist == int(pow(int(pow(dist,0.5)), 2)):
      num += 1
print(num)

Solution (Python):
import numpy as np

N, D = map(int,input().rstrip().split())
li = [[int(_) for _ in input().rstrip().split()] for __ in range(N)]

count = 0
for i in range(N-1):
    for j in range(i+1, N):
        if np.linalg.norm(np.array(li[i])-np.array(li[j])).is_integer():
            count += 1

print(count)

Solution (Python):
import math

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

count = 0
Xs = []
for i in range(n):
  x = [int(x) for x in input().split()]
  
  if i >= 1:
    for x_ in Xs:
      distance = 0
      for j in range(d):
        distance += (x[j] - x_[j]) ** 2
      distance = math.sqrt(distance)
      if distance == int(distance):
        count += 1
  Xs.append(x)
  
print(count)

Solution (Python):
import math

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

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

print(c)

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

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

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

print(cnt)

Solution (Python):
import math

N,D = map(int, raw_input().split())
array = []
num = 0

for i in range(N):
    array.append( map(int, raw_input().split()))


for i in range(N):
    for j in range(N):
        if i >= j :
            continue
        else:
            dist = 0
            for d in range(D):
                dist +=  (array[i][d] - array[j][d])*(array[i][d] - array[j][d])

            if (math.sqrt(dist) % 1) == 0:
                num += 1

print num

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

ans=0
for i in range(n):
    for j in range(i+1,n):
        val=np.sqrt(np.power(p[i]-p[j], 2).sum())
        if float.is_integer(val):
            ans+=1

print(ans)

Solution (Python):
def is_good_num(x):
    i = 1
    while i ** 2 <= x:
        if i ** 2 == x:
            return True
        i += 1
    return False

def main():
    n, d = map(int, input().split())
    x = [[int(x) for x in input().split()] for i in range(n)]
    ans = 0
    for i in range(n):
        for j in range(i + 1, n):
            s = 0
            for k in range(d):
                s += (x[i][k] - x[j][k]) ** 2   
            if is_good_num(s):
                ans += 1
    print(ans)
    
main()

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

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

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

Solution (Python):
import math

n,d = [int(i) for i in input().split()]
main = []
for i in range(n):
  array = [int(i) for i in input().split()]
  main.append(array)
  
cnt = 0

for i in range(n):
  for j in range(i+1,n):
    kyori2 = 0
    for k in range(d):
      kyori2 += (main[i][k]-main[j][k])*(main[i][k]-main[j][k])
      
    kyori = math.sqrt(kyori2)
    if int(kyori)+0.000001 > kyori:
      cnt += 1
      
print(cnt)

Solution (Python):

import sys
import math
from collections import defaultdict


sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]


mod = 10**9 + 7


def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))



N,D = II()

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

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

print(ans)

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

Solution (Python):

import sys
import math


def solve(N: int, D: int, X: "List[List[int]]"):
    count = 0
    for i in range(N):
        for j in range(i + 1,N):
            sum = 0
            for k in range(D):
                sum += (X[i][k] - X[j][k]) ** 2
            f = float(math.sqrt(sum))
            if f.is_integer():
                count += 1
    print(count)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    D = int(next(tokens))  
    X = [ [ int(next(tokens)) for _ in range(D) ] for _ in range(N) ]  
    solve(N, D, X)

if __name__ == '__main__':
    main()

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

narr = np.array(x)
ans = 0

for i in range(n):
    for j in range(i+1, n):
        dis = np.linalg.norm(narr[j] - narr[i])
        if math.ceil(dis) == math.floor(dis):
            ans += 1

print(ans)

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

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

Solution (Python):
n, d = map(int, input().split())
x = [list(map(int, input().split())) for number in range(n)]
ans = 0
for a in range(n):
    for b in range(n):
        if a < b:
            distance_element =  [(ai - bi) ** 2 for ai, bi in zip(x[a], x[b])]
            distance = sum(distance_element) ** (1/2)
            if distance - int(distance) == 0:
                ans += 1
            else:
                pass
        else:
            pass
print(ans)

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

squares=[i**2 for i in range(200)]
ans=0
for i in range(n):
    for j in range(i+1,n):

        dist = sum((x[i][m]-x[j][m])**2 for m in range(d)) 
        if dist in squares: ans+=1

print(ans)

Solution (Python):
import math

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

flag=0
ANS=0

for i in range(0,N):
    for j in range(i+1,N):
        for k in range(0,D):
            ANS+=(int(x[i][k])-int(x[j][k]))*(int(x[i][k])-int(x[j][k]))
        if math.sqrt(ANS)==int(math.sqrt(ANS)):
            flag+=1
        ANS=0
        
print(flag)

Solution (Python):
from sys import stdin
import math

n, d = map(int,input().split())
cnt = 0
x =  [stdin.readline().rstrip().split() for _ in range(n)]
ans = 0
for i in range(n):
	for k in range(i+1,n):
		for j in range(d):
			ans += (int(x[i][j]) - int(x[k][j]))**2

		ans1 = math.sqrt(ans)
		
		if ans1.is_integer() == True: 
			cnt += 1
		ans = 0
print(cnt)

Solution (Python):

import math

def calc(before, cur):
    sum = 0
    for x, y in zip(before, cur):
        sum += (x-y) ** 2

    return (1 if math.sqrt(sum) % 1 == 0 else 0)

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

count = 0
for i in range(n-1):
    for j in range(i+1, n):
        count += calc(Xs[i], Xs[j])

print(count)

Solution (Python):

import math

def calc(before, cur):
    sum = 0
    for i in range(len(before)):
        sum += ((before[i] - cur[i])**2)

    return (1 if math.sqrt(sum) % 1 == 0 else 0)

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

count = 0
for i in range(n-1):
    for j in range(i+1, n):
        count += calc(Xs[i], Xs[j])

print(count)

Solution (Python):

import math

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

counter = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        e = 0
        for xi, xj in zip(X[i], X[j]):
            e += (xj - xi)**2
        e = e**0.5
        counter += 1 if float.is_integer(e) else 0

print(counter)

Solution (Python):
import math





inputa = input().split()


a = int(inputa[0])
b = int(inputa[1])





inputList=[]
for i in range(a):
    inputNum = input().split()
    inputList.append(inputNum)



cnt = 0
for i in range(a):
    for j in range(i+1, a):
        dstnc = 0
        for k in range(b):
            tmpi = inputList[i][k]
            tmpj = inputList[j][k]

            dstnc += math.pow(int(tmpi) - int(tmpj), 2)

        if math.sqrt(dstnc) % 1.0 == 0 :
            cnt += 1

print(cnt)

Solution (Python):
import math
n,d=map(int,input().split())
arr=[]
for _ in range(n):
	arr.append(list(map(int,input().split())))
def dist2(p,q):
  ans=0
  for i,j in zip(p,q):
    ans+=(i-j)**2
  return ans

ans=0
for i in range(n-1):
  for j in range(i+1,n): 
    d2=dist2(arr[i],arr[j])
    d=int(math.sqrt(d2)+1e-15)
    if d*d==d2: ans+=1
print(ans)

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

print(ans)

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

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

cnt = 0
for i, x in enumerate(arr[:-1]):
  for y in arr[i+1:]:
    sum_=sum([(x[k]-y[k])**2 for k in range(d)])**0.5
    if float(sum_).is_integer():
      cnt += 1
print(cnt)

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

l=[]
for _ in range(n):
  l1=list(map(int,input().split()))
  l.append(l1)

import math

ans=[]
for a in range(n):
  for b in range(n):
    x=0
    for c in range(d):
      D=(l[a][c]-l[b][c])**2
      x+=D
    y=math.sqrt(x)
    ans.append(y.is_integer())
      
ans=(ans.count(True)-n)//2
print(ans)

Solution (Python):
import math

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

for i in range(N):
    X1=input().split()
    
    X2=[]
    for j in range(D):
        X2.append(int(X1[j]))
    X.append(X2)
    
c=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
        if abs(math.sqrt(d)-int(math.sqrt(d))) <0.0001:
            c+=1

print(c)

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

ans = 0
for idx1,el1 in enumerate(x):
    for idx2, el2 in enumerate(x):
        dis = 0
        if idx1 < idx2:
            for i in range(d):
                dis += (el1[i] - el2[i])**2
            if math.sqrt(dis).is_integer():
                ans += 1
print(ans)

Solution (Python):

import math


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


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


print(ans)

Solution (Python):
import math
num,digit=map(int,input().split())
dot=[list(map(int,input().split())) for _ in range(num)]
count=0
for i in range(num):
    for j in range(i+1,num):
        distance=0
        for a,b in zip(dot[i],dot[j]):
            distance+=(a-b)**2
        if distance==math.floor(math.sqrt(distance))**2:
            count+=1
print(count)

Solution (Python):
import math
N,D = map(int,input().split())
s = []
cnt = 0
for i in range(N):
    s.append(list(map(int,input().split())))
for i in range(N-1):
    for j in range(i+1,N):
        sub = 0
        dis = 0
        for k in range(D):
            sub += math.pow(abs(s[i][k] -s[j][k]),2)
            
        dis = math.sqrt(sub)
        if dis.is_integer():
            cnt += 1
print(cnt)

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

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

print(cnt)

Solution (Python):
import math

n, d = map(int, input().split())
x = []
cnt = 0
sum = 0
for _ in range(n):
    tmp = list(map(int, input().split()))
    x.append(tmp)

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

print(cnt)

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

for i in range(n):
    for j in range(i + 1, n):
        sum = 0
        l = 1
        for k in range(d):
            sum += (x[i][k] - x[j][k]) ** 2
        while (l ** 2 <= sum):
            if l ** 2 == sum:
                cnt += 1
            l += 1

print(cnt)

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

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

count = 0 
for i in mc:
    ans2=0
    for j in range(d):
        ans2+= abs(x[i[1]][j] - x[i[0]][j])**2
    ans = math.sqrt(ans2)
    if ans.is_integer():
        count+=1

print(count)

Solution (Python):
from math import sqrt
def dist(l1,l2):
  return sqrt(sum([abs((n1-n2)**2) for n1,n2 in zip(l1,l2)]))
n,d = map(int,input().split())
ll = [list(map(int,input().split())) for _ in [0]*n]
ans = 0
for i in range(n):
  for j in range(i+1,n):
    if dist(ll[i],ll[j]) == int(dist(ll[i],ll[j])):
      ans += 1
print(ans)

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

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

def calc_dist(point1, point2):
  total = 0
  for x1, x2 in zip(point1, point2):
    total += (x1-x2)*(x1-x2)
  return math.sqrt(total)

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

ans = 0
for i  in range(0,N-1):
  for j in range(i+1,N):
    dist = calc_dist(points[i], points[j])
    if float(int(dist)) == dist:
      ans += 1    
print(ans)

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

for i in range(n-1):
  for k in range(1, n-i):
    for j in range(d):
      r_temp = (x[i][j] - x[i+k][j])**2 
      r += r_temp
    r = r**0.5
    if int(r) == r:
      ans += 1
    r = 0
    
print(ans)

Solution (Python):
import numpy as np


def isint(x):
    return np.equal(np.mod(x, 1), 0)


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

    vecs = np.array(vecs)
    
    v1 = np.tile(vecs, (1, n))
    v2 = np.tile(vecs.reshape(1, n * d), (n, 1))
    
    
    dists = v1 - v2
    
    dists = dists.reshape([-1, d])
    
    dists = np.linalg.norm(dists, axis=1)
    
    score = (np.count_nonzero(isint(dists)) - n) // 2
    print(score)


main()

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

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

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

def func(n, d, x):
    count = 0
    terms = 0.0
    index = [i for i in range(n)]
    for i, k in itertools.combinations(index, 2):
        for j in range(d):        
            j_term = abs(x[i][j]-x[k][j])
            j_term **= 2      
            terms += j_term
        terms **= 0.5
        if terms.is_integer():
            count += 1
        terms = 0.0
    print(count)
    pass


def main():
    n,d = [int(i) for i in input().split()] 
    x = [[0]*d for i in range(n)]
    
    for i in range(n):
        xd = [int(j) for j in input().split()] 
        x[i] = xd
    
    
    
    func(n, d, x)
    

if __name__ == "__main__":
    main()

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

for i in range(N):
    for j in range(i+1,N):
        tmp=0
        for k in range(D):
            tmp+=(dot[i][k]-dot[j][k])**2
        tmp=math.sqrt(tmp)
        if(float.is_integer(tmp)==True):sum+=1

print(sum)

Solution (Python):
n, d = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        s = pow(sum([(X[i][k] - X[j][k])**2 for k in range(d)]), 1/2)
        if s.is_integer():
            ans +=1
print(ans)

Solution (Python):
import math

def distance(l1,l2):
    d2 = 0
    for i in range(len(l1)):
        l = l1[i] - l2[i]
        d2 += l ** 2
    return d2

def issqrt(num):
    cand = int(math.sqrt(num))
    if (cand + 1) ** 2 == num:
        return True
    if cand ** 2 == num:
        return True
    if (cand - 1) ** 2 == num:
        return True
    return False


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

count = 0
for i in range( N - 1):
    for j in range( i+1, N):
        d = distance( cord[i],cord[j])
        
        if issqrt( d ):
            count += 1

print( count )

Solution (Python):

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

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