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

Solution (Python):
import numpy as np
N, D = map(int, input().split())
X = []
count = 0
for i in range(N):
    x = list(map(int, input().split()))
    X.append(x)
for j in range(N-1):
    X1 = X[j]
    for k in X[j+1:]:
        X2 = k
        XXX = 0
        for l in range(D):
            XX = (X1[l]-X2[l])**2
            XXX += XX
        XXXX = np.sqrt(XXX)
        if XXXX.is_integer() == True:
            count += 1
print(count)

Solution (Python):
import math

def dist(X1,X2):
  d=[abs(X1[i]-X2[i]) for i in range(len(X1))]
  d=[x**2 for x in d]
  d=sum(d)
  d=math.sqrt(d)
  return d
 
count=int(0)
N,D=map(int,input().split())
X=list(range(N))
for i in range(N):
  X[i]=list(map(int,input().split()))
for i in range(N):
  for j in range(i+1,N):
    d=dist(X[i],X[j])
    if d.is_integer():
      count=count+1
print(count)

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

cnt = 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])*(x[i][k]-x[j][k])
            
            
        s = np.sqrt(s)
        
        if s//1 == s:
            
            cnt += 1
print(cnt)

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

import numpy as np
from scipy.spatial import distance

distance = distance.cdist(data, data, metric='euclidean')
count = 0
for n in range(0,N):
  for d in range(n+1,N):
    if distance[n][d].is_integer() and distance[n][d] != 0 :
      count+=1
print(count)

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

cnt = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        d = 0
        for xi, xj in zip(X[i], X[j]):
            d += (xi - xj)** 2
        if d ** (1 / 2) == int(d ** (1 / 2)):
            cnt += 1

print(cnt)

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

def main():
    N, D = [int(n) for n in input().split()]
    points = []
    res = 0
    for _ in range(N):
        points.append([int(a) for a in input().split()])
    for i in range(N):
        for j in range(i+1, N):
            if float.is_integer(dis(points[i], points[j])):
                res += 1
    print(res)
main()

Solution (Python):
import numpy
N, D = map(int,input().split())
point = []

for i in range(N):
    a = input().split()
    a = [int(i) for i in a]
    point.append(a)
ans = 0

for p1 in range(0,len(point)-1):
    for p2 in range(p1+1, len(point)):
        if numpy.linalg.norm(numpy.array(point[p2]) - numpy.array(point[p1])).is_integer():
            ans += 1
    
print(ans)

Solution (Python):
import math

def cul(a,b,d):
    num = 0
    for i in range(d):
        num += (a[i] - b[i]) ** 2
    return math.sqrt(num)

N,D = map(int,input().split())
X = []
count = 0
d = 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):
        if(i != j):
            d = cul(X[i],X[j],D)
        if (d - int(d)) == 0.0:
            count += 1

print(count)

Solution (Python):
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(i+1,N) :
        x = X[i]
        y = X[j]
        dist = 0
        for k in range(D) :
            dist += (x[k] - y[k])**2
        b = int(dist**0.5)
        if abs(b**2 - dist) < 1e-10 :
            ans += 1

print(ans)

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


cnt = 0

for i in range(n-1):
  for j in range(i+1,n):
    sum = 0
    for k in range(d):
      sum += (lst[i][k]-lst[j][k])**2
    sum = pow(sum,1/2)
    
    if sum == int(sum):
      cnt+=1
print(cnt)

Solution (Python):
import numpy as np
N, D = map(int, input().split())
coords = np.array([np.array([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):
    a = coords[i]
    b = coords[j]
    d = np.linalg.norm(a-b)
    ans += d == d.astype(np.integer)
    
print(ans)

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

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

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        cnt = 0
        for y, z in zip(x[i], x[j]):
            cnt += abs(y-z)**2
        if cnt ** 0.5 % 1 == 0:
            ans += 1

print(ans)

Solution (Python):
import math

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

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

Solution (Python):
import math

a1=list(input().split( ))
a=list(map(int, a1))

b = [input().split() for l in range(a[0])]
g=0
for j in range(a[0]):
 for k in range( a[0] - j  - 1 ):
  c=0
  for m in range(a[1]):
   c  +=  ( int(b[j][m]) - int(b[j + k+1][m]) )**2
  d = float(math.sqrt(c))
  e = float(int(d))
  if e==d:
   g += 1

print(g)

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

Solution (Python):
import math

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((N - i) - 1):
        A = 0
        if N - i == 0:
            continue
        for k in range(D):
            B = 0
            point1 = X[i][k]
            point2 = X[(i + j) + 1][k]
            B = B + point1 - point2
            A = A + pow(B, 2)
        C = math.sqrt(A)
        if C.is_integer():
            ans = ans + 1

print(ans)

Solution (Python):
def get_distance(x, y, d):
    result = 0
    for i in range(d):
        result += (x[i] - y[i]) ** 2
    return result

def is_2jou(i):
    ii = i ** 0.5
    if ii == float(round(ii)):
        return True
    else:
        return False

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

    cnt = 0
    for _ in range(len(x)):
        head = x.pop(0)
        for j in x:
            distance = get_distance(head, j, d)
            flag = is_2jou(distance)
            if flag:
                cnt += 1

    print(cnt)

main()

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

num_l=[]

for i in range(N):
  d=list(map(int,input().split()))
  num_l.append(d)
         
num_2=np.array(num_l)


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

Solution (Python):
import itertools

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

_result = 0
_sum = 0
for i in itertools.combinations(range(N),2):
    for j in range(D):
        _result += abs(lst[(i[0])][j] - lst[(i[1])][j])**2
    if (_result ** 0.5).is_integer():
        _sum += 1
    _result = 0
print(_sum)

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

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

    dist = dist ** 0.5

    return dist

for i in range (N):
    a = X[i]
    B = X[:i] + X[i+1:]

    for b in B:
        d = distance(a, b)
        if d == d // 1:
            ans += 1

print(ans // 2)

Solution (Python):
import math

nd = [int(i) for i in input().split()]
x = []
for i in range(nd[0]):
    tmp = [int(i) for i in input().split()]
    x.append(tmp)
result = 0
for i in range(nd[0]):
    for j in range(i+1, nd[0]):
        before_root = 0
        for k in range(len(x[0])):
            before_root += (x[i][k] - x[j][k])**2
        if math.sqrt(before_root).is_integer():
            result += 1
print(result)

Solution (Python):
import itertools
import math


def calcDistanceIsInt(p1, p2):
    sum = 0
    for i in range(len(p1)):
        sum += math.pow(abs(p1[i] - p2[i]), 2)

    sq = math.sqrt(abs(sum))
    if sq.is_integer():
        return True
    else:
        return False


nd = list(map(int, input().split()))
n, d = nd[0], nd[1]

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




int_count = 0
for i in list(itertools.combinations(points, 2)):
    
    
    if calcDistanceIsInt(i[0], i[1]):
        int_count += 1
print(int_count)

Solution (Python):

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

cnt = 0
for c in list(itertools.combinations(x,2)):
        dist = 0
        for i in range(d):
                dist += (c[0][i]-c[1][i])**2
        dist = dist**0.5
        if dist.is_integer():
                cnt += 1

print(cnt)

Solution (Python):
import math
n, d = [int(s) for s in input().split(" ")]
pts = []
for _ in range(n):
  pts.append([int(s) for s in input().split(" ")])

def dist(x, y):
  sum = 0
  for xx, yy in zip(x, y):
    sum += (xx - yy)**2
  return math.sqrt(sum)

cnt = 0
for i in range(n):
  for j in range(i + 1, n):
    d = dist(pts[i], pts[j])
    if int(d) == d:
      cnt += 1

print("%d" % cnt)

Solution (Python):
import math
N, D = map(int, input().split())
l = []
cnt = 0

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

for i in range(N-1):
	x = list(map(int, input().split()))
	length = len(l)
	for j in range(math.floor(length/D)):
		num = 0
		for k in range(D):
			num += (x[k] - l[(j*D)+k]) ** 2
			if k == D - 1 and (math.sqrt(num)).is_integer() == True:
				cnt += 1
			if (j == math.floor(length/D) -1):  
				l.append(x[k])

print(cnt)

Solution (Python):

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

answer = 0

def distance(x, a, b):
    list = []
    for d in range(D):
        list.append((x[a][d] - x[b][d])**2)
    r = math.sqrt(sum(list))
    return r



def isinteger(x):
    if isinstance(x, float):
        return x == int(x)

for j in range(N):
    for i in range(j+1,N):
        
        
        if isinteger(distance(X, i, j)):
            answer = answer + 1

print(answer)

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


ans=0
for i in range(n):
    for j in range(i+1,n):
        kyorino2zyou=0
        for k in range(d):
            kyorino2zyou=kyorino2zyou+(list_a[i][k]-list_a[j][k])**2
            kyori=(kyorino2zyou)**(1/2)
            kyori2=int(kyori)
           
          
        if kyori2-kyori==0:
                ans=ans+1
print(ans)

Solution (Python):
import itertools
import math
N, D = map(int, input().split())
A = [[int(i) for i in input().split()] for j in range(N)]
B = [int(j) for j in range(N)]

count = 0
for x in itertools.combinations(B, 2):
    abs_A =[(A[x[0]][l]-A[x[1]][l])**2 for l in range(D)]
    if math.sqrt(sum(abs_A))%1 == 0 :
        count+=1
    else:
        count+=0
print(count)

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

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

ans = 0
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        else:
            tmp = 0
            for k in range(D):
                tmp += (x[i][k] - x[j][k]) ** 2
            dis = tmp ** 0.5
            if dis.is_integer():
                ans += 1
print(int(ans / 2))

Solution (Python):
n,d = map(int,input().split())
lid,a,dis,b = [],0,[],[]
import itertools
for i in range(n):
    lid.append(list(map(int, input().split())))

dis = list(itertools.combinations(lid,2))

for i in range(len(dis)):
    for j in range(d):
        a += (dis[i][0][j]-dis[i][1][j])**2
        
    a = a**0.5
    b.append(a)  
    a = 0
    
ans = 0
for i in range(len(b)):
    if b[i]%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;
        

count = 0
for i in range(n):
    for j in range(n):
        if(i < j):
            dis = 0
            for k in range(d):
                dis += (listA[i][k]-listA[j][k]) ** 2
            dis = np.sqrt(dis)
            
            if( dis/int(dis) == 1 ):
                count += 1


print(count)

Solution (Python):
import math

vectors = list()

n, d = (int(x) for x in input().split())
for c in range(n):
    vectors.append([int(x) for x in input().split()])

counter = 0

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

print(counter)

Solution (Python):
import math
x = 0
num = list(map(int,input().split()))
n = [list(map(int, input().split())) for i in range(num[0])]
for i in range(num[0]):
  k=1
  while i+k < num[0]:
    dd = 0
    for l in range(num[1]):
      dd += (n[i][l] - n[i+k][l]) ** 2      
    d = math.sqrt(dd)
    k += 1
    if d.is_integer() == True:
      x += 1
print(x)

Solution (Python):
import math
n,d=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]
cnt=0
dis=0
if d==1:
    print(n*(n-1)//2)
else:
    for i in range(n-1):
        for j in range(i+1,n):
            distance=0
            dis=0
            for k in range(d):
                dis+=(x[i][k]-x[j][k])**2
            distance=math.sqrt(dis)   
            if distance.is_integer()==True:
                cnt+=1
    print(cnt)

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

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

x = []

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

import itertools

ans = 0

for v in itertools.combinations(x, 2):
  a, b = v
  n = 0
  for i in range(d):
    n += (a[i] - b[i]) ** 2
  n = n ** 0.5
  if str(n)[-1] == "0":
    ans += 1

print(ans)

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

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

cnt=0
for n in range(N):
    for nn in range(N):
        if n==nn:
            continue
        else:
            a=[]
            for d in range(D):
                a.append((x[n][d]-x[nn][d])**2)
            c=math.sqrt(sum([abs(i) for i in a]))
            if c%1==0:
                cnt+=1
print(int(cnt/2))

Solution (Python):
import itertools


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


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

cnt = 0
for a, b in itertools.combinations(x, 2):
    if is_integer(sum([(ad - bd) ** 2 for ad, bd in zip(a, b)]) ** 0.5):
        cnt += 1

print(cnt)

Solution (Python):
import itertools
import math

n,d = map(int,input().split())
x = [[int(i) for i in input().split()] for i in range(n)] 
seq = list(itertools.combinations(range(n),2))
tmp = 0.0
cnt = 0
for i,j in seq:
    for k in range(d):
        tmp += (x[i][k] - x[j][k])**2
    tmp = math.sqrt(tmp)
    if tmp.is_integer():
        cnt += 1
    tmp = 0.0
print(cnt)

Solution (Python):
import itertools
import numpy

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

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

list(itertools.combinations(s,2))

count = 0

for element in itertools.combinations(s, 2):
    
    
    a =	numpy.array(element[0])
    b =	numpy.array(element[1])
    u =	b - a
    
    if(numpy.linalg.norm(u).is_integer() == True):
    	count =	count + 1


print(count)

Solution (Python):






import sys
import math


class mymath:
    
    pi = 3.14159265358979323846264338

    
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()


class output:
    
    def list(self, l):
        l = list(l)
        
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()






















def get_input():
    N = []
    while True:
        try:
            N.append(input())
            
            
        except EOFError:
            break
    return N

def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()

def dist(A, B):
    d = 0
    for i in range(len(A)):
        d += (A[i]-B[i])**2            
    d = d**(1/2)
    return d

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

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

count = 0

for i in range(len(X)):
    for j in range(i+1,len(X)):
        d = dist(X[i],X[j])
        if is_integer(d):
            count += 1
            
print(count)

Solution (Python):
import numpy as np
from sys import stdin

N,D=[int(x) for x in stdin.readline().rstrip().split()]
data = [stdin.readline().rstrip().split() for _ in range(N)]

ret=0
for i in range(N-1):
    a=[ int(x) for x in data[i]]
    for j in range(i+1,N,1):
        b=[ int(x) for x in data[j]]
        u = np.array(b) - np.array(a)
        c = np.linalg.norm(u)
        de,inte=np.modf(c)
        if de == 0:
            ret+=1
            
            

print(ret,flush=True)

Solution (Python):
import math
N,D = map(int,input().split())
lists = []
seisuu = []
cnt = 0
for i in range(N):
    X = list(map(int,input().split()))
    lists.append(X)
for i in range(N):
    for j in range(i+1,N):
        list_A = lists[i]
        list_B = lists[j]
        cnt = 0
        for k in range(D):
            cnt += abs(list_A[k] - list_B[k])**2
        m = float(math.sqrt(cnt))
        if m.is_integer():
         seisuu.append(m)
print(len(seisuu))

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

Solution (Python):
import math

Dot_Num, N_Dimention= (int(i) for i in input().split())
Dot = [[int(i) for i in input().split()] for i in range(Dot_Num)]
count=0

for n in range(0, len(Dot)):
    for j in range(n+1, len(Dot)):
        SUM = math.sqrt(sum(pow(Dot[n][i]-Dot[j][i],2) for i in range(N_Dimention)))
        if SUM.is_integer():
            count+=1

print(count)

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

Solution (Python):
import itertools


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


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

cnt = 0
for a, b in itertools.combinations(x, 2):
    if is_integer(sum([(ad - bd) ** 2 for ad, bd in zip(a, b)]) ** 0.5):
        cnt += 1

print(cnt)

Solution (Python):
import math
N,D=map(int,input().split())
L=[list(map(int,input().split())) for i in range(N)]
ans=0
for n in range(N):
	for n2 in range(n+1,N):
		tmp=0
		for d in range(D):
			tmp+=abs(L[n][d]-L[n-n2][d])**2
		if math.sqrt(tmp) % 1 == 0:
			ans+=1
print(ans)

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

Solution (Python):
import numpy as np
ans = 0
s = 0
n,d = map(int,input().split())
a =[]
for _ in range(n):
  ar = list(map(int,input().split()))
  a.append(ar)
for i in range(n):
  for j in range(i+1,n):
    for k in range(d):
      s += (a[i][k]- a[j][k])**2
    c = float(np.sqrt(s))
    if c.is_integer() == True:
      ans += 1
    s = 0
print(ans)

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

for i in range(N):
    for j in range(i+1,N):
        y=X[i]
        z=X[j]
        tmp=0
        for k in range(D):
            tmp += (y[k]-z[k])**2
        tmp2 = tmp ** 0.5
        if tmp2.is_integer():
            ans+=1   
         
print(ans)

Solution (Python):
import numpy as np
input_arr = [int(x) for x in input().split()]

N = input_arr[0]
D = input_arr[1]


point = []

for i in range(N):
    input_num = [int(x) for x in input().split()]
    point.append(input_num)
count = 0

for i in range(N):
    for j in range(i+1,N):
        a = np.array(point[i])
        b = np.array(point[j])
        u = b - a
        distance = (np.linalg.norm(u))
        if distance.is_integer():
            count = count +1
            
print(count)

Solution (Python):
import numpy as np

n,d=map(int,input().split())
arr=[]
for i in range(n):
  arr.append(list(map(int,input().split())))
arr =np.array(arr)
ans=0
for i in range(n):
  for j in range(i,n):
    if j!=i:
      k = np.linalg.norm(arr[i]-arr[j],ord=2)
    else:
      k=0.5
    if k==int(k):
      ans +=1
print(ans)

Solution (Python):
import numpy as np
import itertools

num=list(map(int,input().split()))
a=0
ten=[]
for i in range(num[0]):
    ten.append(list(map(int,input().split())))

poi=list(itertools.combinations(ten, 2))

for i in range(len(poi)):
    c=np.array(poi[i][0])
    b=np.array(poi[i][1])
    l = np.linalg.norm(b-c)
    if l%1==0:
        a += 1

print(a)

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

a = 0

for j in (range(N)):
    for k in (range(N)):
        if j > k:
            dif = 0
            dis = 0
            for n in range(D):
                dif += (E[j][n]-E[k][n])**2
                dis = pow(dif, 0.5)
            if dis.is_integer():
                a += 1

print(a)

Solution (Python):
import math

N, D = [int(item) for item in input().split()]
X=[]
res = 0
for i in range(N):
  X.append([int(item) for item in input().split()])
for i in range(N):
  for j in range(i+1, N):
    x1 = X[i]
    x2 = X[j]
    dis = 0
    for d in range(D):
      dis += abs(x1[d]-x2[d])**2
    dis = math.sqrt(dis)
    if int(dis) == float(dis):
      res += 1
print (res)

Solution (Python):
import math

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

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

An=0  
for i in range(N):
  for j in range(i+1,N):
    A=0
    for k in range(D):
      A=A+(L[i][k]-L[j][k])**2
    A=A**0.5
    if A-int(A)==0:
      An=An+1

print(An)

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

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

cnt = 0
for p1, p2 in itertools.combinations(points, r=2):
    d = np.linalg.norm(np.array(p1) - p2)
    if d == int(d):
        cnt += 1
print(cnt)

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

Solution (Python):
def he(cc):
    aa = 1
    while(cc>aa*aa) :
        aa += 1
    if(cc==aa*aa) :
        return True
    else :
        return False


n,d = map(int,input().split())
a = []
b = []
cnt = 0 
for z in range(n) :
    a.append([int(x) for x in input().split(' ')])


for i in range(n-1) :
    for j in range(i+1,n) :
        c = map(lambda x,y: abs(x-y) * abs(x-y), a[i], a[j])
        
        if(he(sum(c))) :
            cnt += 1

print(cnt)

Solution (Python):
import math

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

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

cnt = 0
for i in range(N):
    for j in range(i):
        a = ll[i]
        b = ll[j]
        ans = 0
        for iii in range(D):
            ans += (a[iii] - b[iii]) ** 2
        t = math.sqrt(ans)
        if t == int(t):
            cnt += 1
print(cnt)

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

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

ans = 0

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

Solution (Python):
import numpy as np
n,d = map(int,input().split())
ans=0
g=[]
if d==1:
    for _ in range(n):
        lis = np.array(list(map(int,input().split())))
    ans=n*(n-1)//2
    print(ans)
else:
    for _ in range(n):
        lis = np.array(list(map(int,input().split())))
        for i in range(len(g)):
            u = g[i]-lis
            z=np.linalg.norm(u)
            if z==int(z):
                ans+=1
        g.append(lis)
    print(ans)

Solution (Python):
from itertools import combinations as pt
import math

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

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






def dist(p1, p2):
    a = 0
    for i in range(D):
        a += (p1[i] - p2[i]) ** 2
    b = math.sqrt(a)
    return b

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


num = 0
for comb in pt(range(N), 2):
    
    p1 = data[comb[0]]
    p2 = data[comb[1]]
    a = dist(p1, p2)
    
    if is_integer(a):
        num += 1

print(num)

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

Solution (Python):
import numpy as np
import itertools

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

X = []

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

X = np.array(X)

cnt = 0
for i, j in itertools.combinations(range(n), 2):
    dist = np.linalg.norm(X[i] - X[j])
    if dist == int(dist):
        cnt += 1

print(cnt)

Solution (Python):
import math

n, d = map(int, input().split())
a_list = []
result = 0
count = 0
while count < n:
    a_list.append(list(map(int, input().split())))
    count += 1

def calculate_distance(a, b, axis_count):
    hoge = 0
    for i in range(axis_count):
        hoge += abs((a[i] - b[i])**2)
    return math.sqrt(hoge)

for i in range(n):
    for j in range(n-i):
        distance = calculate_distance(a_list[i], a_list[j+i], d)
        if distance != 0 and distance.is_integer():
            result += 1
print(result)

Solution (Python):
import math
import itertools

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

points = []
counter = 0
num = []
for i in range(N):
	points.append(list(map(int, input().split())))
	num.append(i)
  
for v in itertools.combinations(num, 2):
	length2 = 0
	i1 = int(v[0])
	i2 = int(v[1])
	for j in range(D):
		length2 += (points[i1][j] - points[i2][j])*(points[i1][j] - points[i2][j])
	length = math.sqrt(length2)
	if(length.is_integer()):
		counter += 1
  
print(counter)

Solution (Python):
import numpy as np

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

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

Solution (Python):

import numpy as np
import math

def calculate_distance(in1, in2):
    list1 = np.array(in1) 
    list2 = np.array(in2) 
    sub_list = list1 - list2
    pow_list = np.power(sub_list, 2)
    sum_number = sum(pow_list)
    distance = math.sqrt(sum_number)

    return distance

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

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

number = 0
for n in range(N):
    for nn in range(n+1, N):
        distance = calculate_distance(X[n], X[nn])
        if distance.is_integer() is True:
            number += 1

print(number)