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

Solution (Python):



N_D = list(map(int,input().split()))
X = []
n = 0

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

for i in range(N_D[0]-1):
    j = i + 1
    while j <= N_D[0]-1:
        distance = 0
        sum = 0
        for k in range(N_D[1]):
            sum += (X[i][k] - X[j][k])**2
        distance = sum ** (1/2)
        j += 1
        if int(distance) == distance:
            n += 1

print(n)

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

s = 0
c = 0
for n1 in range(-1,N-1):
    for n2 in range(n1+1,N-1):
        for d in range(D):
            s = s + abs(li[n1][d] - li[n2][d]) ** 2
        s_float = float(s**(1/2))
        if s_float.is_integer():
            c += 1
        s = 0
print(c)

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

Solution (Python):
import math

n, d = map(int, input().split())
a = []
for i in range(n):
  a.append(list(map(int, input().split())))
  
def dist(x, y):
  ret = 0
  for i in range(len(x)):
    ret += (x[i]-y[i]) * (x[i]-y[i])
  return ret
    
ans = 0
for i in range(n):
  for j in range(i+1, n):
    d = math.sqrt(dist(a[i], a[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)]

ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        dist = sum(map(lambda v1, v2: (v1 - v2) ** 2, x[i], x[j]))
        if math.sqrt(dist) == int(math.sqrt(dist)):
            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
a = 0
for i in range(N):
    for j in range(i + 1,N):
        for k in range(D):
            a += (X[i][k] - X[j][k])**2
        if math.sqrt(a) == int(math.sqrt(a)):
            count += 1
        a = 0

print(count)

Solution (Python):
from math import sqrt
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 = 0
    for k in range(D):
      s += (X[i][k] - X[j][k])**2
    r = sqrt(s)
    if r == int(r):
      ans+=1

print(ans)

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

Solution (Python):
import math
from sys import stdin, exit

def calc_dist(y, z, D):
    dist = 0
    for i in range(D):
        dist += pow(y[i]-z[i], 2)
    return pow(dist, 0.5)

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

ans = 0
for i in range(N):
    for j in range(i+1, N):
        dist = calc_dist(X[i], X[j], D)
        if dist.is_integer():
            ans += 1
print(ans)

Solution (Python):
import sys
import numpy as np 
dist = 0
pairs_num = 0
dist_ary = []
i = 0
j = 1
n, d = map(int, input().split())
n_point = [input().split() for i in range(n)]
while i < n:
    while j < n:
        dist = 0
        for y,z in zip(n_point[i],n_point[j]):
            dist += (int(y)-int(z))**2
        dist_ary.append(dist)
        j+=1
    i+=1
    j = i+1
for i in range(len(dist_ary)):
    if np.sqrt(dist_ary[i]).is_integer():
        pairs_num +=1
print(pairs_num)

Solution (Python):
import numpy as np
n, d = map(int, input().split())
mat = np.zeros((n, d), "int64")
for index in range(n):
    pos = list(map(int, input().split()))
    for val_index in range(len(pos)):
        mat[index, val_index] = pos[val_index]

count = 0
for i_index in range(n-1):
    i_pos = mat[i_index]
    for j_index in range(i_index+1, n):
        j_pos = mat[j_index]
        sa = j_pos - i_pos
        sa_jijou = sa * sa
        dist_square = np.sum(sa_jijou)
        m = int(dist_square ** 0.5)
        if abs(m * m - dist_square) < 1e-6:
            count += 1
print(count)

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):
        d = 0
        for x, y in zip(X[i], X[j]):
            d += (x-y)**2
        d = math.sqrt(d)
        if d - int(d) == 0:
            count += 1
        d = 0

print(count)

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

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

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

cnt = 0

for comb in combs:
    in_sqrt = 0
    for i in range(D):
        in_sqrt += (comb[0][i] - comb[1][i]) ** 2
    dist = sqrt(in_sqrt)
    if dist.is_integer():
        cnt += 1
print(cnt)

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

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

count = 0
for i in range(n):
    for j in range(i+1, n):
        cal = 0
        for y, z in zip(point[i], point[j]):
            cal += (y - z) ** 2
        
        if math.sqrt(cal).is_integer():
            count += 1


print(count)

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

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

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

Solution (Python):
from sys import stdin

lines = stdin.readlines()
N, D = map(int, lines[0].split())
X = [[int(j) for j in lines[i].split()] for i in range(1, N + 1)]
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        acum = 0.0
        for k in range(D):
            acum += (X[j][k] - X[i][k]) ** 2
        if float.is_integer(acum ** 0.5):
            ans += 1
print(ans)

Solution (Python):
N,D=map(int,input().split())
X=[list(map(int, input().split())) for i in range(N)]
result = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        result += (sum((a - b) ** 2 for a, b in zip(X[i], X[j])) ** 0.5).is_integer()
print(result)

Solution (Python):
N, D = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(N)]
s = 0
for i in range(N - 1) :
    for j in range(i + 1, N) :
        l = 0.0
        for d in range(D) :
            l += (x[i][d] - x[j][d]) ** 2
        length = l ** (1/2)
        if length.is_integer() :
            s += 1
print(s)

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):
        sum=0.0
        for dd in range(d):
            sum+=(x[i][dd]-x[j][dd])**2
        sum=sum**(1/2)
        if sum.is_integer():
            cnt+=1
print(cnt)

Solution (Python):

a,b=map(int,input().split())
c=[]
for i in range(a):
    d=list(map(int,input().split()))
    c.append(d)


ans=0
for j in range(a):
    for k in range(j+1,a):
        count=0
        sum=0
        for l in range(b):
            e=abs(c[j][l]-c[k][l])
            f=e**2
            count +=1
            if count <=b:
                sum +=f
                
        for n in range(sum+1):
            if n**2 == sum:
                ans +=1
                
print(ans)

Solution (Python):
def dis(a,b):
  ans = 0
  sum = 0
  
  for i in range(d):
   
   
    sum += (a[i] - b[i]) ** 2
   
  ans = sum ** 0.5
  return ans

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

count = 0

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

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

ans = 0
for i in range(N-1):
    for k in range(i+1, N):
        distance = 0
        for z in range(D):
            distance += (X[i][z] - X[k][z]) ** 2
        if math.ceil(distance**0.5) == math.floor(distance**0.5):
            ans += 1
print(ans)

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



def try_square_root_naive(n):
    m = int(n**.5)
    return m if abs(m*m - n) < 1e-6 else None
 
  
for i in range(N):
  x = list(map(int,input().split()))
  X.append(x)

count = 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])*(X[i][k] - X[j][k])
      if(try_square_root_naive(dist) != None):
        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())))
c = 0
while len(X) > 1:
    x = X.pop()
    a = 0
    for i in range(len(X)):
        for j in range(len(x)):
            a += (x[j]-X[i][j])**2
        if math.sqrt(a).is_integer():
            c += 1
        a = 0
print(c)

Solution (Python):

import sys
import numpy as np


def solve(N: int, D: int, X: "List[List[int]]"):
    x_array = np.array(X)

    count = 0
    for i, x in enumerate(x_array):
        if not i == N:

            for x_target in x_array[i + 1 :]:

                distance = np.sqrt(np.power(x - x_target, 2).sum())
                if distance == int(distance):
                    count += 1
                else:
                    pass

        else:
            pss

    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):
from math import sqrt

N,D = [int(i) for i in input().split()]
XY_l = [[int(i) for i  in input().split()] for _ in range(N)]
ans = 0

for i in range(N):
  for j in range(N):
    if i <= j :
      continue
    S = float()
    for d in range(D):
      S += ((XY_l[i][d]) - (XY_l[j][d]))**2
    if sqrt(S).is_integer():
      ans+=1

print(ans)

Solution (Python):
import math

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

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

print(c)

Solution (Python):
import math
N, D = map(int,input().split())
X = [0] * N
for i in range(N):
    X[i] = list(map(int,input().split()))
count = 0
def func(A,B):
    a = 0
    for k in range(D):
        a += (A[k] - B[k])**2
    a = math.sqrt(a)
    return a
for i in range(N):
    for j in range(i,N):
        sum_x = 0
        int_x = 0
        if i == j:
            continue
        sum_x = func(X[i],X[j])
        int_x = int(sum_x)
        if sum_x == int_x:
            count += 1
print(count)

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

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

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

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

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

for i in range(N):
    for j in range(i+1,N):        
        length = 0      
        for k in range(D):          
            diff = abs(X[i][k]-X[j][k])
            length += diff**2           
        l = 0            
        while l < length+1:
            if l**2 == length:
                count+=1
                break
            l+=1
print(count)

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

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

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

count = 0

for i in range(n):
  for j in range(i+1, n):
    if distance(x[i], x[j]) % 1 == 0:
      count += 1

print(count)

Solution (Python):
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')


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

for i in range(N):
	for j in range(i+1,N):
		for k in range(D):
			a+=(X[i][k]-X[j][k])**2
		if int(a**.5)**2==a:
			cnt+=1
		a=0
		
			
print(cnt)

Solution (Python):
import math


def p_b():
    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):
            d = sum([(X[i][k] - X[j][k]) ** 2 for k in range(D)])
            if math.sqrt(d).is_integer():
                ans += 1
    print(ans)
    
p_b()

Solution (Python):
import numpy as np

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

X = np.zeros((N, D), np.float)
for i in range(N):
  X[i,] = [int(x) for x in input().split()]

def dist(X1, X2):
  return np.linalg.norm(X1-X2)

ans = 0
for i in range(N-1):
  for j in range(i+1, N):
    d = dist(X[i,], X[j,])
    if d.is_integer():
      ans += 1
print(ans)

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

def func(i,j):
	global list1
	global d
	cout = 0
	for k in range(d):
		cout += (list1[i][k] - list1[j][k])**2
	return math.sqrt(cout)

count = 0

for i in range(0,n-1):
	for j in range(i+1,n):
		judge = func(i,j)
		if judge.is_integer():
			count += 1
print(count)

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

n,d = [int(x) for x in stdin.readline().rstrip().split()]
li = [tuple(map(int,stdin.readline().rstrip().split())) for _ in range(n)]

li2 = list(itertools.combinations(li, 2))

point  = 0

for i in range(len(li2)):
    score = 0
    for j in range(d):
        score += int(li2[i][1][j] - li2[i][0][j])**2
    if round(math.sqrt(score)) - math.sqrt(score) == 0.0:
        point += 1
print(point)

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

count = 0
for a in range(N):
  for b in range(a+1, N):
    sumX = 0
    for c in range(D):
      sumX += (X[a][c]-X[b][c])**2
    if math.sqrt(sumX)%1 == 0:
      count += 1
print(count)

Solution (Python):
n, d = map(int, input().split())
points = [list(map(int, input().split())) for _ in range(n)]
res = 0
for i in range(n):
    for j in range(i+1, n):
        l = sum(map(lambda x: x ** 2, [a - b for a, b in zip(points[i], points[j])]))
        for k in range(200):
            if l == k ** 2:
                res += 1
                break

print(res)

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

Solution (Python):
import math

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

list_coordinates = [ [ int(i) for i in input().split() ] for j in range(N) ]

list_distance_between_pts = []


for i in range(N-1):
	for j in range(i+1, N):
		distance_square = 0
		for l in range(D):
			distance_square += (list_coordinates[i][l] - list_coordinates[j][l])**2
		
		distance = math.sqrt(distance_square)
		
		if distance.is_integer() == True:
			list_distance_between_pts.append(distance)

count_interger_distance = len(list_distance_between_pts)

print(count_interger_distance)

Solution (Python):
import math
n,d = map(int,input().split())
li = [list(map(int,input().split())) for i in range(n)]
cnt = 0
sum_d = 0
for i in range(n):
    for j in range(n):
        if i<j:
            ans = math.sqrt(sum(abs(li[i][k]-li[j][k])**2 for k in range(d)))
            if ans.is_integer() == True:
                cnt+=1
print(cnt)

Solution (Python):
import math

n,d=map(int,input().split())
ans=[]
cnt=0
for _ in range(n):
    ans.append(list(map(int,input().rstrip().split())))
for i in range(n):
    for j in range(n):
        if i >= j:
            continue
        else:
            result = math.sqrt(sum(abs(ans[i][k]-ans[j][k])**2 for k in range(d)))
            if result.is_integer():
                cnt += 1
            else:
                continue
print(cnt)

Solution (Python):
import numpy as np
n, d = map(int, input().split())
x = np.array([[int(i) for i in input().split(" ")] for j in range(n)])
c = 0
for i in range(1,n):
    t = x[:-1*i,:]-x[1*i:,:]
    t = np.sqrt(np.sum(t*t, axis=1))
    c += np.sum(t%1==0)
print(c)

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

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


count = 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 s ** 0.5 % 1 == 0:
            count += 1

print(count)

Solution (Python):
n,d = map(int,input().split())
x = [list(map(int,input().split())) for hoge in range(n)]
y = x
count = 0
tmp = 0
for i in range(n):
         for j in range(n):
                  for k in range(d):
                           tmp += (x[i][k] - y[j][k]) ** 2
                  if (tmp ** (1/2)).is_integer():
                           count += 1
                           tmp = 0
                  else:
                           tmp = 0
print((count-n)//2)

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

a = np.array(a)
ctn = 0
for i in range(0,n-1):
    for j in range(i+1,n):
        if np.sqrt(np.sum((a[i]-a[j])**2)) % 1 == 0:
            ctn +=1

print(ctn)

Solution (Python):
from itertools import combinations
from math import sqrt
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

res = 0
for Y,Z in combinations(X, 2):
    r = sqrt(sum((y-z)**2 for y,z in zip(Y,Z)))
    if r == float(int(r)):
        res += 1
print(res)

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

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

aaa_list = []
cnt = 0


for i in range(N):
    for j in range(i+1,N):
        for k in range(D):
            aaa_list.append(abs(X_list[i][k]-X_list[j][k])**2)
        judge_aaa = (sum(aaa_list))**0.5
        
        if judge_aaa.is_integer() :
            cnt +=1
        aaa_list.clear()

print(cnt)

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

Solution (Python):
import sys
import math
from itertools import combinations
n, d = [int(i) for i in sys.stdin.readline().split()]
xs = []
for i in range(n):
    xs.append([int(i) for i in sys.stdin.readline().split()])
cnt = 0
for (x, y) in combinations(xs, 2):
    if (math.sqrt(sum([(_x - _y)**2 for _x, _y in zip(x, y)])) % 1 == 0):
        cnt += 1
print(cnt)

Solution (Python):
import math

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

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

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

    return round(math.sqrt(dist), 2)

count = 0
for i in range(n-1):
    for j in range(i+1, n):
        dist = distance(points[i], points[j])
        if dist == dist//1:
            count += 1

print(count)

Solution (Python):
import math
N, D = list(map(int,input().split()))
x = []
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,1):
        s = 0
        for k in range(D):
            s += (x[j][k] - x[i][k])**2
        
        if math.sqrt(s) == int(math.sqrt(s)):
            count += 1
print(count)

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

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

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

a = 0
X = []

while a < n :
    X.append(input().split())
    a += 1

i = 0
j = 0
p = 0
wa = 0
count = 0

while i < n :
    p = 1
    while i + p < n :
        wa = 0
        j = 0
        while j < d :
            wa += pow(int(X[i][j]) - int(X[i + p][j]), 2)
            j += 1
        p += 1
        if (wa ** .5).is_integer() :
            count += 1
    i += 1

print(count)

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

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

print(ans)

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

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

ans = 0

def dist(a,b):
    dist = 0
    for j in range (len(a)):
        dist += (a[j]-b[j])**2
    return(dist**0.5 == int(dist**0.5))
    
for k in range (len(X)):
    for l in range (k+1, len(X)):
        ans += (dist(X[k],X[l]))

print(ans)

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

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


score = 0
for i in range(len(list_N)):
    for j in range(i+1, len(list_N)):
        val = 0

        for a, b in zip(list_N[i], list_N[j]):
            val += (a-b)**2

        val = val**0.5
        
        if val.is_integer():
            score += 1

print(score)

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

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

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

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

Solution (Python):
import math

def dist(p1, p2):
    total = 0
    for x, y in zip(p1, p2):
        total += (x - y) ** 2
    return total

N, D = map(int, input().split())
point_list = [None] * N

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

count = 0
for i in range(N):
    for j in range(i + 1, N):
        dis = math.sqrt(dist(point_list[i], point_list[j]))
        if dis == int(dis):
            count += 1
print(count)

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

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

square = [i**2 for i in range(500)]
ans = 0
for i in range(N):
  for j in range(i):
    x = X[i]
    y = X[j]
    dist = 0
    for k in range(D):
      dist += (x[k] - y[k])**2
    if dist in square:
      ans += 1
      
print(ans)

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

cnt = 0

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


for i in range(n):
  for j in range(i+1, n):
    if distance(points[i], points[j]).is_integer():
      cnt += 1

print(cnt)

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

for i in range(n):
  for j in range(i):
    dis = sum( [((a[i][k] - a[j][k] )*(a[i][k] - a[j][k])) for k in range(d)])
    if dis in sei:
        cnt +=1
print(cnt)

Solution (Python):
n, d = [int(i) for i in input().split()]
x =[[int(i) for i in input().split()] for j in range(n)]
squares = set([i * i for i in range(1000)])
count = 0
for i in range(n):
	for j in range(i):
		dist = sum([(x[i][k] - x[j][k]) * (x[i][k] - x[j][k]) for k in range(d)])
		if dist in squares:
			count += 1
print(count)

Solution (Python):
import numpy as np
n,d = list(map(int,input().split()))
x = [np.array(input().split(), dtype=np.int64) for _ in range(n)]
cnt = 0
for i in range(n):
    for j in range(n):
        if i !=j:
            
            
            if (np.linalg.norm(x[i]-x[j]))%1==0:
                cnt +=1
print(cnt//2)

Solution (Python):
import math

n, d = map(int, input().split())
a = []
for l in range(n):
    a.append(list(map(int, input().split())))
res = 0
temp = 0
for x in a:
    for i in range(0, n):
        temp = 0
        for j in range(0, d):
            temp += (x[j] - a[i][j]) ** 2
        temp = math.sqrt(temp)
        if temp.is_integer():
            res += 1

print((res - n) // 2)

Solution (Python):
import math
X, D = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(X)]
ans = 0
for i in range(X - 1):
    for j in range(1, X - i):
        total = 0
        for k in range(D):
            total += abs(x[i + j][k] - x[i][k])**2
        if math.sqrt(total).is_integer():
            ans += 1
print(ans)

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

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

vec_L = []

for val in range(n):
    a_vec = list(map(int,input().split()))
    vec_L.append(a_vec)

a = list(range(n))

comb = list(combinations(a,2))

counter_L = []


for val in comb:
    
    vec1 = np.array(vec_L[val[0]])
    vec2 = np.array(vec_L[val[1]])
    ans = np.linalg.norm(vec1 - vec2)
    counter_L.append(ans.is_integer())

print(counter_L.count(True))

Solution (Python):
import copy
import math

n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
y = copy.deepcopy(x)
cnt = 0
inside = 0
for nx, i in enumerate(x[:]):
  
  for ny, j in enumerate(y[:]):
    
    inside = 0
    if nx != ny:
      for item in range(d):
        inside += (i[item] - j[item]) ** 2
        
      root = math.sqrt(inside)
      if root.is_integer():
        cnt += 1
print(int(cnt / 2))

Solution (Python):
import math

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

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

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


cnt = 0
for i in range(n):
    for j in range(i+1,n):
        if dist(points[i],points[j]).is_integer():
            cnt += 1

print(cnt)

Solution (Python):
import math

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

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

cnt = 0
for i in range(n-1):
  for j in range(i+1, n):
    dist = 0
    for d in range(D):
      dist += (point[i][d] - point[j][d])**2
    dist = math.sqrt(dist)
    if int(dist) == dist:
      cnt += 1
print(cnt)