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) = [int(i) for i in input().rstrip().split(" ")]

point_list = [[int(i) for i in input().rstrip().split(" ")] for j in range(n)]

ans = 0
for i in range(n):
    for j in range(i+1,n):
       temp = sum([pow(point_list[i][k] - point_list[j][k],2) for k in range(d)])
       sq = int(math.sqrt(temp))
       if sq * sq == temp:
           ans += 1
print(ans)

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

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False
for _ in range(N):
    x=list(map(int,input().split()))
    zahyo.append(x)    
cnt=0
for y in itertools.combinations(zahyo,2):
    
    kyori=[(i-j)**2 for i,j in zip(y[0],y[1])]
    soukyori=(sum(kyori))**(1/2)
    if is_integer_num(soukyori):
        cnt+=1
print(cnt)

Solution (Python):
from itertools import combinations
N, D = map(int, input().split())
X = []
for _ in range(N):
  X += list(map(int, input().split()))
cnt = 0
for i, j in combinations(range(N),2):
  d = 0
  for k in range(D):
    d += (X[i*D + k] - X[j*D + k])**2
  if int(d**0.5)**2 == d: cnt += 1
print(cnt)

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, D = MAP()
X = [LIST() for _ in range(N)]

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

com = list(combinations(X, 2))

pare = 0
for x in com:
	dis = 0
	for i in range(len(x[0])):
		dis += (x[0][i] - x[1][i])**2
	dis = sqrt(dis)
	if is_integer_num(dis):
		pare += 1

print(pare)

Solution (Python):
from itertools import combinations

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

def dist(x1, x2):
    return sum((xx1 - xx2) ** 2 for xx1, xx2 in zip(x1, x2))

def is_acceptable(d):
    dd = round(d ** 0.5)
    return dd ** 2 == d

print(sum(is_acceptable(dist(x1, x2)) for x1, x2 in combinations(X, 2)))

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

Solution (Python):
import sys
read=sys.stdin.buffer.readline

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

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

Solution (Python):
import sys
import numpy as np

n, d, *x = map(int, sys.stdin.read().split())
x = np.array(x, dtype=np.int64).reshape(n, d)

def main():
    cnt = 0
    for i in range(n-1):
        for j in range(i+1, n):
            dist = np.sqrt(((x[i] - x[j]) ** 2).sum())
            if dist == int(dist):
                cnt += 1
    
    return cnt
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):



import itertools
n, d = [int(x) for x in input().split()]
x = []
cnt = 0
for _ in range(n):
    x.append([int(x) for x in input().split()])
for a, b in itertools.combinations(x, 2):
    d = sum([(x1 - x2)**2 for x1, x2 in zip(a, b)])**0.5
    if d.is_integer():
        cnt += 1
print(cnt)

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

total_d = 0
count=0
for i in range(N-1):
    for k in range(i+1,N):
        for j in range(D):
            d = abs(X[i][j]-X[k][j])
            total_d += d**2
            
        
        if (total_d**(1/2)).is_integer():
            count+=1
            total_d = 0
        else:
            total_d = 0
        
print(count)

Solution (Python):
import math
n,d=map(int,input().split())
a=[[int(i) for i in input().split()] for l in range(n)]
c=0
for i in range(n):
    for j in range(i+1,n):
        sum=0
        for x,y in zip(a[i],a[j]):
            sum+=(abs(x-y))**2
        if math.sqrt(sum)%1==0:c+=1
print(c)

Solution (Python):



from itertools import combinations


def main():
    N, D = map(int, input().split())
    X = [list(map(int, input().split()))for _ in range(N)]
    count = 0
    for a, b in combinations(X, 2):
        tmp = 0
        for d in range(D):
            tmp += abs(a[d] - b[d])**2
        if (tmp**0.5).is_integer():
            count += 1
    print(count)


if __name__ == "__main__":
    main()

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

def is_square(n):
    res=n**0.5
    return res.is_integer()

cnt = 0
for i in range(n):
    for j in range(i+1,n):
        dist = 0
        for k in range(d):
            
            dist += (dis[i][k]-dis[j][k])**2
        if is_square(dist) == True: cnt+=1
print(cnt)

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

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

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

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

import math
ans = 0
for i in range(N):
    X1 = X[i]
    for X2 in X[i+1:]:
        if math.sqrt(sum([(x1-x2)**2 for x1, x2 in zip(X1, X2)])).is_integer():
            ans += 1
print(ans)

Solution (Python):
from itertools import combinations

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

ans = 0
for a, b in combinations(d, 2):
    dist = sum(abs(i-j)**2 for i,j in zip(a, b))
    for i in range(1, int(dist**0.5)+1):
        if i**2==dist:
            ans += 1
            break
    
print(ans)

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

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

Solution (Python):
n,d = map(int,input().split())
x = []
for i in range(n):
    xi = [int(i) for i in input().split()]
    x.append(xi)
count = 0
ans = 0
for i in range(n-1):
    for l in range(i+1,n):
        ans = 0
        for j in range(d):
            ans += (x[i][j]-x[l][j])**2

        ans = ans **(1/2)
        if ans == int(ans):
            count += 1
print(count)

Solution (Python):
import math
import numpy as np

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

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

def cal_distance(a, b):
    distance = np.sqrt(np.sum((a - b) ** 2))
    return (distance)

for i in range(N):
    
    for j in range(i + 1, N):
        
        dis = cal_distance(X[i], X[j])
        if (math.floor(dis) == dis):
            ctr += 1

print(ctr)

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

index = 0
count = 0
for x in X:
    for y in X[index+1:]:
        dist = sum([(x[i]-y[i])**2 for i in range(D)])**(1/2)
        if dist == int(dist):
            count += 1
    index += 1

print(count)

Solution (Python):
import math

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

count=0

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

print(count)

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

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

def is_int(x1, x2):
    dist = 0
    for i, j in zip(x1, x2):
        dist += (i-j)**2
    if round(math.sqrt(dist))**2==dist:
        return True
    else:
        return False

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        if is_int(x[i], x[j]):
            ans += 1

print(ans)

Solution (Python):
import math
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):
    tmp=0
    for k in range(d):
      tmp+=(x[i][k]-x[j][k])**2
    if math.sqrt(tmp).is_integer():
      ans+=1
print(ans)

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

n_sq = {n*n for n in range(400*100+1)}

def is_gooddist(ta,tb):
	dist_sq = sum((y-z)*(y-z) for y,z in zip(ta,tb))
	return dist_sq in n_sq

def main():
	N,D=map(int,input().split())
	mX=[tuple(map(int,input().split())) for _ in [0,]*N]
	
	res = 0
	for i in range(N-1):
		tI = mX[i]
		for j in range(i+1,N):
			tJ = mX[j]
			res += is_gooddist(tI,tJ)
	print(res)

main()

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

def f(x,y):
  cal=0
  for i in range(d):
    cal+=abs(x[i]-y[i])**2
  return cal**0.5

for i in range(n-1):
  for j in range(i+1,n):
    if f(a[i],a[j]).is_integer()==True:cnt+=1

print(cnt)

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

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

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

Solution (Python):
from math import sqrt
N, D = map(int, input().split())
X_list = [input().split() for i in range(N)]
cnt = 0
for x in range(N-1):
    d = 0
    tmp = 0
    for y in range(x+1, N):
        d = 0
        tmp = 0
        while d < D:
            x_d = int(X_list[x][d])
            y_d = int(X_list[y][d])
            tmp += (x_d - y_d) ** 2
            d += 1
        if sqrt(tmp).is_integer():
            cnt += 1

print(cnt)

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

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

cnt = 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
        if math.sqrt(sum).is_integer():
            cnt += 1
print(cnt)

Solution (Python):
import itertools
import math


n, dimension = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(n)]
l = list(itertools.combinations(X, 2))
num = len(l)
ans = 0
for i in range(num):
    dist = 0
    for d in range(dimension):
        dist += (l[i][0][d] - l[i][1][d]) ** 2
    dist = math.sqrt(dist)
    if dist.is_integer():
        ans += 1
print(ans)

Solution (Python):
import numpy as np
from itertools import combinations

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

ans = 0
for x, y in combinations(X, 2):
  d = pow((x-y), 2).sum()
  if (d**0.5).is_integer():
    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):
        lst = 0
        for k in range(d):
            lst += (x[i][k]-x[j][k])**2
        if (lst)**(1/2)%1 == 0.0:
            cnt += 1
        else:
            cnt += 0
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
import math
for i in range(0,N-1):
    for j in range(i+1,N):
        ans+=math.sqrt(sum((X[i][k]-X[j][k])**2 for k in range(D))).is_integer()
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):
    dist=0
    for k in range(d):
      dist+=(abs(x[i][k]-x[j][k])**2)
    for l in range(int(dist**.5)+1):
      if dist==l**2:
        cnt+=1
print(cnt)

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(i+1,N):
        distance2=0
        for k in range(D):
            distance2+=(X[i][k]-X[j][k])**2
        distance=(distance2)**0.5
        if distance%1==0:
            ans+=1

print(ans)

Solution (Python):
import math

n, d = map(int, input().split())
x = [[0] * d for _ in range(n)]
for i in range(n):
    line = input().split()
    for li in enumerate(line):
        x[i][li[0]] = int(line[li[0]])

ans = 0

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

Solution (Python):
import numpy as np
n,d=map(int,input().split())
x=[]
ans=0
for _ in range(n):
    *r,=map(int,input().split())
    x.append(r)
x=np.array(x)
for i in range(1,n):
    for j in range(i):
        d=x[i]-x[j]
        d2=d*d
        y=np.sqrt(sum(d2))
        if y.is_integer():
            ans += 1
print(ans)

Solution (Python):

import numpy as np
n,d=map(int,input().split())
L=[]
ans=0
for i in range(n):
    A=list(map(int,input().split()))
    L.append(A)
P=np.array(L)
for i in range(n):
    for j in range(i,n):
        if np.linalg.norm(P[i]-P[j])>0 and np.linalg.norm(P[i] - P[j])%1==0:
            ans+=1
print(ans)

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

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

Solution (Python):
import math

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

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

print(count)

Solution (Python):
import math
import itertools
n, d = map(int, input().split())
ary = []
for i in range(n):
	x = list(map(int, input().split()))
	ary.append(x)
c = 0
for j,k in itertools.combinations(ary,2):
	s = 0
	for l in range(d):
		s += (j[l]-k[l])**2
	ss = math.sqrt(s)
	if ss.is_integer():
		c += 1
print (c)

Solution (Python):
import math
import itertools
n, d = map(int, input().split())
ary = []
for i in range(n):
	x = list(map(int, input().split()))
	ary.append(x)
c = 0
for j,k in itertools.combinations(ary,2):
	s = 0
	for l in range(d):
		s += (j[l]-k[l])**2
	ss = math.sqrt(s)
	if ss.is_integer():
		c += 1
print (c)

Solution (Python):
import numpy as np

N,D = list(map(int,input().split()))
x = [list(map(int,input().split())) for _ in range(N)]
l = np.array(x)

def d(x):
  cnt = 0
  for i in range(len(x)):
    for p2 in l[i+1:]:
      p1 = x[i]
      d = np.linalg.norm(p1-p2)
      if d - int(d) == 0:
        cnt += 1
  return cnt
    
print(d(x))

Solution (Python):
import itertools
N,D=map(int,input().split())
X=[list(map(int,input().split())) for i in range(N)]
cmb=list(itertools.combinations(range(N),2))
ans=int(0)
for j in range(len(cmb)):
  xdis=0
  for k in range(D):
    xdis+=(X[cmb[j][0]][k]-X[cmb[j][1]][k])**2
  xdis=xdis**0.5
  if xdis-int(xdis)==0:
    ans+=1 
  else:
    ans+=0
print(ans)

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

cnt = 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():
            cnt += 1
print(cnt)

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):
        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
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]


def get_nums_l():
    return [ int(s) for s in input().split(" ")]


def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n,d = get_nums_l()

points = [ list(map(int, s.split(" "))) for s in sys.stdin.readlines() ]

ans = 0
for ai, a in enumerate(points):
    for bi, b in enumerate(points):
        if ai <= bi :
            continue
        diss = 0
        for i in range(d):
            diss +=  (a[i]-b[i]) ** 2
        if math.sqrt(diss) % 1 < 0.00000000001:
            ans += 1

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


d = []

for i in range(N - 1):
    for j in range(i + 1, N):
        d.append((sum((X[j] - X[i]) ** 2)) ** 0.5)
d = np.array(d)

np.mod(d, 1, out=d)
mask = d == 0



print(np.count_nonzero(mask))

Solution (Python):
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
 
def dist(A, B):
    sums = 0
    for i in range(len(A)):
        sums += (abs(A[i] - B[i])) ** 2
    sums = sums ** 0.5
    return sums
 
for i in range(N-1):
    for j in range(i+1, N):

        if dist(X[i], X[j]).is_integer():
            cnt += 1
print(cnt)

Solution (Python):
from math import sqrt
n, d = map(int, input().split())
point = [[int(i) for i in input().split()] for j in range(n)]
count = 0
for i in range(n):
    for j in range(i + 1, n):
        norm = 0
        for pi, pj in zip(point[i], point[j]):
            norm += (pi - pj) ** 2
        if int(sqrt(norm)) == sqrt(norm):
            count += 1

print(count)

Solution (Python):
import math

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

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

ans = 0
for i in range(n):
    for j in range(i+1,n):
        d = distance(x[i],x[j])
        if d == int(d):
            ans += 1

print(ans)

Solution (Python):
import math

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


def distance(a, b):
  dist = 0.0
  for i in range(len(a)):
    dist += pow(a[i]-b[i], 2)
  return math.sqrt(dist)

ans = 0
for k in range(N-1):
  for l in range(k+1, N):
    if distance(X[k], X[l]).is_integer():
      ans += 1
print(ans)

Solution (Python):
from math import sqrt


import sys
input = sys.stdin.readline


def solve(N, D, X):
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            dist = sqrt(sum((X[i][d] - X[j][d])**2 for d in range(D)))
            if dist == int(dist):
                ans += 1

    return ans




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


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

print(solve(N, D, X))

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

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

Solution (Python):
n,d = map(int,input().split( ))
px = [tuple(map(int, input().split( ))) for _ in range(n)]
cnt = 0
for i in range(n):
    for j in range(i):
        sq = 0
        for t in range(d):
            sq += (px[i][t]-px[j][t])**2
        sqsq = int(sq**(1/2))
        if sq == sqsq**2 or sq==(sqsq+1)**2:
            cnt += 1
print(cnt)

Solution (Python):

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

res = 0;
rowres = 0
for i in range(0, n):
    for j in range(i+1,n):
        rowres = 0
        for k in range(0, d):
            rowres += (x[i][k] - x[j][k]) ** 2
        if math.sqrt(rowres) - int(math.sqrt(rowres)) == 0:
            res += 1
print(res)

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):
        sum = 0
        for k in range(D):
            sum += (X[i][k] - X[j][k])**2
        if (sum**0.5).is_integer():
            ans += 1

print(ans)

Solution (Python):
import math

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

count = 0
distance = 0

for i in range(N):
    for j in range(i + 1, N):
        for k in range(D):
            distance += (int(Dists[i][k]) - int(Dists[j][k])) ** 2
        distance = math.sqrt(distance)

        if distance.is_integer():
            count += 1
        distance = 0

print(count)

Solution (Python):
import math
a,b = map(int, input().split())
l = [list(map(int,input().split())) for i in range(a)]

cnt = 0
for i in range(a):
  for j in range(i+1,a):
    x = 0
    for k in range(b):
      x += (l[i][k]-l[j][k])**2
    if x**(1/2) - int(x**(1/2)) == 0:
      cnt += 1
print(cnt)

Solution (Python):

import itertools
n,d=map(int,input().split())
N=[i for i in range(n)]
k=[i*i for i in range(127)]
x=[]
for i in range(n):
    a=list(map(int,input().split()))
    x.append(a)
ans=0
kumi=itertools.combinations(N,2)

for a,b in kumi:
    s=0
    for j in range(d):
        s+=(x[a][j]-x[b][j])**2
    if s in k:
        ans+=1
print(ans)

Solution (Python):
import itertools
n,d=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
count=0
for i,j in itertools.product(l,l):
  s = sum([abs(i[k]-j[k])**2 for k in range(d)])
  f = s**0.5 - int(s**0.5)==0
  g =s!=0
  if f and g:
    count+=1
print(int(count/2))

Solution (Python):
def distance(x1, x2):
    sum = 0
    for i in range(len(x1)):
        sum += (x1[i] - x2[i])**2
    return sum**(1/2)

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

cnt = 0
for i in range(len(x)-1):
    for j in range(i+1, len(x)):
        d = distance(x[i], x[j])
        if d == int(d):
            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())))
from itertools import combinations as cm
total = 0
for pair in cm(X, 2):
  dis2 = 0
  for i in range(d):
    dis2 += (pair[0][i] - pair[1][i])**2
  dis = dis2**0.5
  if int(dis) == dis:
    total += 1
print(total)

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

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

for j in range(0, N):
    for k in range(j+1,N):
        a = numpy.array(listx[j])
        b = numpy.array(listx[k])
        u = b - a
        c = float(numpy.linalg.norm(u))
        if c.is_integer() :
            count += 1
print(count)

Solution (Python):
n,d=map(int,input().split())
x=[]
out=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):
        tol=0
        for k in range(d):
            tol+=(x[i][k]-x[j][k])**2
        if tol**(1/2)-int(tol**(1/2))==0:
            out+=1
print(out)

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

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

cnt = 0
for i in range(N):
    for j in range(N):
        if i<j:
            u = numpy.array(listX[i]) - numpy.array(listX[j])
            distance = numpy.linalg.norm(u)
            if distance.is_integer():
                cnt += 1
                
print(cnt)

Solution (Python):
import numpy as np
n,d=map(int, input().split())
l=[np.array(list(map(int, input().split()))) for _ in range(n)]
cnt=0
for i in range(n):
    for j in range(i+1,n):
        tmp=0
        for k in range(d):
            tmp+=(l[i][k]-l[j][k])**2
        if np.sqrt(tmp)%1==0.0: cnt+=1
print(cnt)

Solution (Python):
import numpy

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

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

count = 0
for i in range(0, N):
    for j in range(i+1, N):
        y = numpy.array(lstMain[i])
        z = numpy.array(lstMain[j])
        u = z - y
        distance = float(numpy.linalg.norm(u))
        if distance.is_integer():
            count += 1

print(count)

Solution (Python):



def dis(d, x, y): 
    a = 0
    for i in range(d):
        a += (x[i] - y[i])**2
    return a**0.5
    
n, d = map(int,input().split())

l = [] 
for j in range(n):
    l.append(input().split())
 
c=[]
for j in l:
    b=[]
    for k in j:
        b.append(int(k))
    c.append(b)

z = []
for e in range(n):
    for f in range(e,n): 
        g = dis(d, c[e], c[f]) 
        if g == int(g) and g != 0: 
            z.append(g) 
            
print(len(z))

Solution (Python):
n,d=map(int,input().split())
l=[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):
  l1=l[i]
  l2=l[j]
  sum=0
  for y,z in zip(l1,l2):
   sum+=(y-z)**2
  dist=sum**0.5
  if dist==int(dist):
   cnt+=1
print(cnt)

Solution (Python):
def dis(d, x, y):
    a = 0
    for i in range(d):
        a += (x[i] - y[i])**2
    return a**0.5
    
n, d = map(int,input().split())


l = []
for j in range(n):
    l.append(input().split())

c=[]
for j in l:
    b=[]
    for k in j:
        b.append(int(k))
    c.append(b)


z = []
for e in range(n):
    for f in range(e,n):
        g = dis(d, c[e], c[f])
        if g == int(g) and g != 0:
            z.append(g)
print(len(z))

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

def f(y, z):
    return abs(y - z) ** 2
ans = 0
B = tuple(itertools.combinations(A, 2))
for i in range(len(B)):
    accum = 0
    for j in range(D):
        accum += f(B[i][0][j], B[i][1][j])
    if (accum ** 0.5).is_integer():
        ans += 1
print(ans)

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

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


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

print(ans)

Solution (Python):
import numpy as np

def dist(x,y,d):
    sum=0
    for length in range(d):
       sum=sum+pow(x[length]-y[length],2)
    if not(int(np.sqrt(sum))==float(np.sqrt(sum))):
        return 0
    else:
        return 1

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


for i in range(N-1):
    for j in range(N-i-1):
        count=count+dist(X[i],X[j+i+1],D)
print(count)

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

counter = 0
for i in range(N):
  for j in range(N-i-1):
    base = 0
    for k in range(D):
      base += (List[i][k]-List[i+j+1][k])**2
    if float.is_integer(base**0.5):
      counter += 1
  
print(counter)

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


def calc(a, b):
    return np.sqrt(sum((a - b)**2))


ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        k = calc(point[i], point[j])
        if k.is_integer():
            ans += 1

print(ans)