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())
P=[]
ans=0
for i in range(n):
    a=list(map(int,input().split()))
    P.append(a)

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

        if int(Ds**0.5)*int(Ds**0.5) == Ds:
            ans += 1

print(ans)

Solution (Python):

import sys
input = sys.stdin.readline

def main():
    N, D = list(map(int, input().rstrip().split()))
    X = tuple(tuple(map(int, input().rstrip().split())) for _ in range(N))
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            r = sum(abs(a - b) ** 2 for a, b in zip(X[i], X[j]))
            if r ** 0.5 == int(r ** 0.5):
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()

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

count = 0
for y, z in itertools.combinations(A, 2):
  d = np.sqrt(((y-z)**2).sum())
  if d == int(d):
    count += 1
print(count)

Solution (Python):
from numpy import*
n,*x=[int32(t.split()) for t in open(0)]
print(sum(j==int(j) for i in x for j in map(linalg.norm,i-x))-n[0]>>1)

Solution (Python):
def cal(x,y,d):
    res = 0
    for i in range(d):
        res+=(x[i]-y[i])**2
    for i in range(res+1):
        if i*i == res:
            return True
    return False
n, d = map(int, input().split())
ans=0
l = []
for i in range(n):
    a = list(map(int,input().split()))
    l.append(a)
for i in range(n):
    for j in range(i+1,n):
        if (cal(l[i],l[j],d)):
            ans+=1
print(ans)

Solution (Python):
from numpy import*
n,*x=[int32(t.split())for t in open(0)]
print(sum(triu([linalg.norm(i-x,2,1)%1==0for i in x],1)))

Solution (Python):
from numpy import*
n,*x=[int32(t.split())for t in open(0)]
print(sum(sum(linalg.norm(i-x,2,1)%1==0)for i in x)-n[0]>>1)

Solution (Python):
import itertools


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

    count = 0
    for (a, b) in itertools.combinations(x, 2):
        if (sum((pair[0] - pair[1]) ** 2 for pair in zip(a, b)) ** .5).is_integer():
            count += 1
    print(count)


if __name__ == "__main__":
    main()

Solution (Python):
from numpy import*
n,*x=[int32(t.split())for t in open(0)]
print(sum(j%1==0for i in x for j in map(linalg.norm,i-x))-n[0]>>1)

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

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

count=0
sum=0
for i in range(n):
    for k in range(i+1,n):
        for j in range(d):
            sum+=int((a[i][j]-a[k][j])*(a[i][j]-a[k][j]))
        for l in range(sum+1):
            if sum==l*l:
                count+=1
        sum=0

print(count)

Solution (Python):
from numpy import*
n,*x=[int32(t.split())for t in open(0)]
print(sum(j==int(j)for i in x for j in map(linalg.norm,i-x))-n[0]>>1)

Solution (Python):
from subprocess import*
call(('python3','-c',"""
from numpy import*
n,*x=[int32(t.split())for t in open(0)]
print((sum(j==int(j)for i in x for j in map(linalg.norm,i-x))-n[0])//2)
"""))

Solution (Python):
import math


def issq(x):
    sx = int(math.sqrt(x))
    return any([
        (sx - 1)**2 == x,
        sx**2 == x,
        (sx + 1)**2 == x,
    ])


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

print([
    issq(sum((v - w)**2 for v, w in zip(X[i], X[j])))
    for i in range(N)
    for j in range(i + 1, N)
].count(True))

Solution (Python):
import sys
import numpy as np


def cal(X):
    ret = 0
    for i in range(X.shape[0] - 1):
        for j in range(i + 1, X.shape[0]):
            r = 0
            for k in range(X.shape[1]):
                r += (X[i, k] - X[j, k]) ** 2
            d = np.sqrt(r)
            if d - int(d) < 0.000001:
                ret += 1
    return ret


sin_ = sys.stdin.read()
ain = np.fromstring(sin_, dtype=np.int64, sep=' ')
N = ain[0]
D = ain[1]
X = ain[2:N*D + 2].reshape((N, D))
ans = cal(X)
print(ans)

Solution (Python):
N,D = map(int,input().split())
A=[]
C=0
E=0
Z=0
for i in range (1,N+1):
    A.append(i)
for i in range (0,N):
    A[i]=list(map(int,input().split()))
for i in range (0,N-1):
    for j in range(i,N-1):
        for k in range(0,D):
            B=(A[i][k]-A[j+1][k])**2
            C+=B
        Z=C
        C=0
        if (Z**(1/2))%1==0:
            E+=1
print(E)

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

A = [i ** 2 for i in range(150)]

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

print(ans)

Solution (Python):
from numpy import*
n,*x=[int32(t.split())for t in open(0)]
print((sum(j==int(j)for i in x for j in map(linalg.norm,i-x))-n[0])//2)

Solution (Python):


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,d=LI()
  l=[LI() for _ in range(n)]

  c=0
  for i in range(n):
    for j in range(i+1,n):
      x=l[i]
      y=l[j]

      sm=0
      for k in range(d):
        sm+=(x[k]-y[k])*(x[k]-y[k])

      

      a=math.sqrt(sm)
      if a==int(a) and a*a==sm:
        c+=1

  return c

print(main())

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

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

Solution (Python):
import numpy as np

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

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

count = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        tmp_kyori = np.linalg.norm(x_list[i] - x_list[j])

        hoge = tmp_kyori % 1

        if hoge == 0:
            count += 1

print(count)

Solution (Python):
import math
N=list(map(int,input().split()))
a=['X' for _ in range(int(N[0]))]
A=0
for i in range(int(N[0])):
    a[i]=list(map(int,input().split()))
    for t in range(int(i)):
        if i!=t:
            Y=[]
            for s in range(int(N[1])):
                Y+=[(a[i][s]-a[t][s])**2]
            Z=sum(Y)
            if (math.sqrt(Z))- int(math.sqrt(Z))==0:
                A+=1
        else:
            continue
print(A)

Solution (Python):
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n,d=IL()
X=[IL() for i in range(n)]
c=0
for i in range(n-1):
    for j in range(i+1,n):
        dis=0
        for k in range(d):
            dis+=(X[i][k]-X[j][k])**2
        if int(dis**0.5)==dis**0.5:
            c+=1
print(c)

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

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):
    r1 = X[i]
    for j in range(N-1, -1, -1):
        if i == j:
            break
        r2 = X[j]
        ls = [(r1[j] - r2[j])**2 for j in range(D)]
        res = math.sqrt(sum(ls))
        if res % 1 == 0:
            count += 1

print(count)

Solution (Python):
import math

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


X = []


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


ans = 0
for i in range(N):

    for j in range(i+1, N):

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


print('{}'.format(ans))

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

Solution (Python):
import sys
import math

input = sys.stdin.readline

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):
        t = 0
        for l in range(d):
            y = x[i][l]
            z = x[j][l]
            t += (y - z) ** 2
        if math.sqrt(t).is_integer():
            ans += 1
print(ans)

Solution (Python):
from itertools import combinations as comb
import math
n, d = map(int, input().split())
zahyo_list = []
for l in range(n):
    zahyo = list(map(int, input().split()))
    zahyo_list.append(zahyo)

comb_list = list(comb(zahyo_list, 2))

count = 0
for p in comb_list:
    y_zahyo = p[0]
    z_zahyo = p[1]
    hs = 0
    for q in range(d):
        hs += abs(y_zahyo[q]-z_zahyo[q])**2

    if math.sqrt(hs).is_integer():
        count += 1
print(count)

Solution (Python):
import math

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


X =  [[0 for i in range(D)] for j in range(N)]


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


ans = 0
for i in range(N):

    for j in range(i+1, N):

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


print('{}'.format(ans))

Solution (Python):

import numpy as np
from itertools import combinations


def answer(l):
    results = [np.linalg.norm(np.array(i) - np.array(j))for i, j in combinations(l, 2)]
    return sum(float.is_integer(i) for i in results)


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

Solution (Python):
import math
n, d= (int(c) for c in input().split())

x = []

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

sum_ans = 0
count=0
print
for j in range(0,n-1):
    for k in range(j+1,n):
        for l in range(d):
            sum_ans = sum_ans+(int(x[j][l]) - int(x[k][l])) **2
        if math.sqrt(sum_ans)%1==0.0:
            count=count+1
        sum_ans=0
print(count)

Solution (Python):

import sys
import numpy as np
from itertools import combinations


def answer(l):
    results = []
    for i, j in combinations(l, 2):
        v_a = np.array(i)
        v_b = np.array(j)
        results.append(np.linalg.norm(v_a - v_b))
    return sum(float.is_integer(i) for i in results)


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

Solution (Python):
from math import sqrt

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

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

count = 0
for i in range(N):
    for j in range(i+1, N):
        dist = 0
        for d in range(D):
            dist += (X[i][d] - X[j][d])**2
        droot = sqrt(float(dist))
        if droot.is_integer():
            count += 1

print(count)

Solution (Python):
N,D = map(int, input().split())
X = [[int(i) for i in input().split()] for i in range(N)]
ans = 0
def dis2(x,y):
    T = []
    for i in range(len(x)):
        T.append((x[i]-y[i])**2)
    return sum(T)
for i in range(N):
    for j in range(i+1,N):
        R = dis2(X[i],X[j])
        for k in range(R+1):
            if k**2 == R:
                ans +=1
print(ans)

Solution (Python):
import math
def distance(l1, l2):
  l = [0] * len(l1)
  for i in range(len(l)):
    l[i] = (l1[i] - l2[i]) ** 2
  s = sum(l)
  return math.sqrt(s), int(math.sqrt(s))
n,d=map(int, input().split())
l = []

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

c = 0  
for i in range(n):
  for j in range(i+1, n):
    sq, insq = distance(l[i], l[j])
    if sq-insq == 0:
      c +=1
      
print(c)

Solution (Python):
import numpy as np
N, D = [int(i) for i in input().split()]
Positions = np.array([[int(i) for i in input().split()] for j in range(N)])
ans = 0
for i, x in enumerate(Positions):
    for y in Positions[i + 1:]:
        if np.linalg.norm(x - y).is_integer():
            ans += 1
print(ans)

Solution (Python):
import numpy as np
N, D = map(int, input().split())
Xs = []
while True:
  Xs.append(list(map(int, input().split())))
  if len(Xs) == N:
    break
result = []
tmp = []
for x in Xs:
  tmp.append(x)
  for n in range(N):
    if Xs[n] in tmp:
      l = np.linalg.norm(np.array(x) - np.array(Xs[n]))
      if l.is_integer() and l > 0:
        result.append(l)
print(int(len(result)))

Solution (Python):
import numpy as np
N, D = map(int, input().split())
Xs = []
while True:
  Xs.append(list(map(int, input().split())))
  if len(Xs) == N:
    break
result = []
Xi = 1
tmp = []
for x in Xs:
  tmp.append(x)
  for n in range(N):
    if Xs[n] in tmp:
      l = np.linalg.norm(np.array(x) - np.array(Xs[n]))
      if l.is_integer() and l > 0:
        result.append(l)
print(int(len(result)))

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):
        s = 0
        for xi, xj in zip(x[i], x[j]):
            s += (xi - xj)**2
        if math.sqrt(s) % 1 == 0:
                ans += 1
print(ans)

Solution (Python):
from math import *
N,D = map(int,input().split())
lst = [[int(kk) for kk in input().split()] for aa in range(N)]
tot = 0
c = 0

for a in range(1,N):
    for b in range(a):
        c = 0
        for i in range(D):
            c += (lst[a][i] - lst[b][i])**2
        if sqrt(c) == int(sqrt(c)):
            tot += 1
print(tot)

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

cnt = 0 
for i in range(N-1):
  for j in range(i+1,N):
    x = np.array(e[i])
    y = np.array(e[j])
    d = np.linalg.norm(x-y)
    if d.is_integer():
      cnt +=1
print(cnt)

Solution (Python):
import math
N, D = map(int, input().split())
a = []
for i in range(N):
  b = map(int, input().split())
  a += b
res = 0
for i in range(N-1):
  j = i + 1
  while(j < N):
    x = []
    y = []
    for k in range(D):
      x.append(a[i * D + k])
      y.append(a[j * D + k])
    tmp = 0
    for k in range(D):
      tmp += (x[k] - y[k]) ** 2
    if tmp == int(tmp ** 0.5) * int(tmp ** 0.5):
      res += 1
    j += 1
print(res)

Solution (Python):
import math

N, D = map(int, input().split())
X = [list(map(int, input().split())) for i 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 numpy as np
import itertools
 
N, D = [int(i) for i in input().split()]
X = []
for i in range(N):
    X.append(np.array([int(i) for i in input().split()]))

d = []
for c in itertools.combinations(X, 2):
    d.append(np.linalg.norm(c[1] - c[0]))

print(len([True for x in d if x.is_integer()]))

Solution (Python):
import numpy as np
import types
N, D = map(int, input().split())
Xs = []
while True:
  Xs.append(list(map(int, input().split())))
  if len(Xs) == N:
    break
result = []
Xi = 1
tmp = []
for x in Xs:
  tmp.append(x)
  for n in range(N):
    if Xs[n] in tmp:
      l = np.linalg.norm(np.array(x)-np.array(Xs[n]))
      if l.is_integer() and l>0:
        result.append(l)
print(int(len(result)))

Solution (Python):
import math
def isPerfect(a):
  x1=math.floor(math.sqrt(a))
  if((x1*x1)==a):
    return True
  return False
n,d=map(int,input().split())
mat=[]
for _ in range(n):
  l=list(map(int,input().split()))
  mat.append(l)
c=0
for i in range(n):
  l1=mat[i]
  for j in range(i+1,n):
    l2=mat[j]
    sm=0
    for k in range(len(l2)):
      x=abs(l2[k]-l1[k])
      sm=sm+(x*x)
    if(isPerfect(sm)):
        c+=1
print(c)

Solution (Python):
import math
dlst = []

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

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

count=0
distance = 0

for i in range(N-1):
    for m in range(i+1,N):
        distance = 0
        for j in range(D):
            distance += (dlst[i][j] - dlst[m][j])**2
        judge=math.sqrt(distance)
        if judge.is_integer():
            count += 1
print(count)

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

for i in range(n):
  b=list(map(int,input().split()))
  a.append(b)
for i in range(n-1):
  for j in range(i+1,n):
    cnt=1
    dist=0
    for k in range(d):
      dist+=(a[i][k]-a[j][k])**2
    while cnt**2<=dist:
      if cnt**2==dist:
        ans+=1
      cnt+=1
print(ans)

Solution (Python):
import numpy as np


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


for i in range(n,0,-1):
    for j in range(i-1,0,-1):
        a=np.array(X[i-1])
        b=np.array(X[j-1])
        u=b-a
        u=np.linalg.norm(u)
        if(int(u)==u):
            cnt+=1

        
print(cnt)

Solution (Python):
def dist(a, b):
	res = 0
	for i in range(D):
		res += (a[i] - b[i]) ** 2
	res = res ** 0.5
	return res


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):
		if dist(X[i], X[j]).is_integer():
			ans += 1
print(ans)

Solution (Python):
import numpy as np
import types
N, D = map(int, input().split())
Xs = []
while True:
  Xs.append(list(map(int, input().split())))
  if len(Xs) == N:
    break
result = []
Xi = 1
for x in Xs:
  for d in range(N):
    a = np.array(x)
    b = np.array(Xs[d])
    l = np.linalg.norm(a-b)
    if l.is_integer() and l>0:
      result.append(l)
print(int(len(list(result))/2))

Solution (Python):
import math
N,D=map(int,input().split())
X=[list(map(int,input().split())) for _ in range(N)]
def d(x,y):
    kyori=0
    for a,b in zip(x,y):
        kyori+=abs(a-b)**2
    return kyori
ans=0
for i in range(N-1):
    for j in range(i+1,N):
        if math.sqrt(d(X[i],X[j])).is_integer():
            ans+=1
print(ans)

Solution (Python):
import numpy as np
import math

buf=input().split(" ")

N=int(buf[0])
D=int(buf[1])

arr = np.empty((0,D), int)

for i in range(N):
  buf=input().split(" ")
  buf = [int(s) for s in buf]

  arr=np.append(arr, [buf], axis=0)
  

buf=0
c=0

for i in range(N):
  for j in range(N):
    if i<j:
      for k in range(D):
        buf=abs((arr[i,k]-arr[j,k])*(arr[i,k]-arr[j,k]))+buf
      buf=math.sqrt(buf)
      if buf.is_integer() == True:
        c=c+1
      buf=0
          
print(c)

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

ans=0
for k in range(n):
    for t in range(k+1,n):
        dis=0
        for kai in range(d):
            dis+=(x[k][kai]-x[t][kai])**2
        
        if(dis**(1/2)%1==0.0):
            ans+=1
print(ans)

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

Solution (Python):
N, D = map(int, input().split())
X = []
for i in range(N):
    X.append([int(i) for i in input().split()])
ans = 0
def d(a, b):
    num = 0
    for x, y in zip(a, b):
        num += (x-y)**2
    return num**(1/2)

for i in range(N-1):
    for j in range(i+1, N):
        a = d(X[i], X[j])
        if a == int(a):
            ans += 1
print(ans)

Solution (Python):
n,d = map(int,input().split())
x = []
for _ in range(n):
  xi = list(map(int,input().split()))
  x.append(xi)
def dis(a,b,d):
  s = 0
  for i in range(d):
    s += (a[i] - b[i])**2
  return s
count = 0
for i in range(n-1):
  for j in range(i+1,n):
    e = dis(x[i],x[j],d)
    ed = e**(1/2)
    if (ed - int(ed)) == 0:
      count += 1
print(count)

Solution (Python):
import numpy
import itertools

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

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

for xs in itertools.combinations(x,2):
    dist = numpy.linalg.norm(xs[1] - xs[0])

    if dist % 1 == 0 :
        count += 1

print(count)

Solution (Python):

from scipy.spatial.distance import pdist
N, D = map(int,input().split())
P = []
for i in range(N):
    P.append(list(map(int,input().split())))
DI = pdist(P)
sm = 0
for d in DI:
    sm += d.is_integer()
print (sm)

Solution (Python):
import math

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

array = [[0 for i in range(10)] for j in range(10)]

for i in range(N):
    x = list(map(int, input().split()))
    for j in range(0, D):
        array[i][j] = x[j];
sum_dis = 0
for i in range(0,N-1):
    for j in range(i+1,N):
        dis = 0
        for k in range(D):
            dis += (array[i][k] - array[j][k])**2
        dis = math.sqrt(dis)
        if(dis.is_integer()): sum_dis += 1
print(sum_dis)

Solution (Python):
import numpy as np
ND =  list(map(int,input().split()))
Lis = []
for i in range(ND[0]):
    a =list(map(int,input().split()))
    Lis.append(a)
Lisnp = np.array(Lis)
Count = 0
for k in range(ND[0]):
    for g in range(k):
        u = Lisnp[k] - Lisnp[g]
        norm = np.linalg.norm(u)
        if norm.is_integer():
            Count += 1
print(Count)

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

if D == 1:
  print(N * (N-1) // 2)
else:
  A = [0] * N
  count = 0
  sei = 0

  for i in range(0,N):
	  A[i] = list(map(int, input().split()))
    
  for p in range(0,N):
      for q in range(0,N):
          sum = 0
    
          for r in range(0,D):
              sum = sum + (A[p][r]-A[q][r]) ** 2
           
          sum = sum ** 0.5 
          sei = int(sum)
        
          if sum != 0 and sum == sei:
              count = count + 1
      
  print(count // 2)

Solution (Python):
import sys
import math
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
    
N,D=LI()
MAT=[LI() for i 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 += (MAT[i][k]-MAT[j][k])*(MAT[i][k]-MAT[j][k])
        distrt = math.ceil(math.sqrt(dist))
        if distrt*distrt == dist:
            cnt += 1
print(cnt)

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

nums=[]

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



ans=[]

for j in range(n-1):
    for k in range(j+1,n):
        x=abs(np.array(nums[j])-np.array(nums[k]))
        
        y=x**2
        
        z=np.sqrt(sum(y))
        
        ans.append(z)
cnt=0

for a in ans:
    if a.is_integer():
        cnt+=1
print(cnt)

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

cnt=0
for i in range(N):
  for j in range(N-i-1):
    s=0
    for k in range(M):
      s += pow((int(a[i][k])-int(a[i+j+1][k])),2)
    c=1
    
    while(True):
      if pow(c,2) == s:
        cnt += 1
        break
      elif pow(c,2) > s:
        break
      c+=1
  
  
print(cnt)

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

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





count = 0
for i in range(N):
    k = i+1
    while k < N:
        dis = 0
        for j in range(D):

            test = X[i][j] - X[k][j]
            dis = dis + test*test

        sqdis = math.sqrt(dis)  
        jud = sqdis.is_integer()

        if jud == 1:

            count = count + 1
        k = k + 1
print(count)

Solution (Python):
import math

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

counter = 0
for n1 in range(N):
    for n2 in range(n1 + 1, N, 1):
        sum = 0
        for d in range(D):
            sum += (X[n1][d] - X[n2][d]) * (X[n1][d] - X[n2][d])
        sum = math.sqrt(sum)
        if sum == int(sum):
            counter += 1
print(counter)

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

cnt = 0
R = []
for i in range(N):
    for j in range(i+1,N):
        r = 0
        for d in range(D):
            r += (X[i][d] - X[j][d]) ** 2
        for n in range(1,300):
            if r == n ** 2:
                cnt += 1
        R.append(r)

print(cnt)

Solution (Python):
def inpl(): return map(int, input().split())
from itertools import accumulate
from bisect import bisect, bisect_left
from collections import Counter
from functools import reduce
from itertools import accumulate
from operator import itemgetter, xor

from sys import setrecursionlimit
setrecursionlimit(10**9)
 
import sys
input = sys.stdin.readline
from collections import Counter
import numpy as np
def inpl(): return list(map(int, input().split()))
N, D = inpl()
S = set([i**2 for i in range(1, 400)])
X = np.array([inpl() for _ in range(N)], dtype=np.int64)

ans = 0
for i in range(N):
    for x in np.power(X - X[i], 2).sum(axis=1):
        if x in S:
            ans += 1
print(ans//2)

Solution (Python):
import itertools
import numpy as np
H, W = map(int, input().split())
arr = []
for _ in range(H):
    S = input().split()
    S = [int(s) for s in S]
    arr.append(S)
x = list(itertools.combinations(arr,2))
count = 0
for i in range(len(x)):
    vec_a = np.array(x[i][0])
    vec_b = np.array(x[i][1])
    d = np.linalg.norm(vec_a - vec_b)
    d2 = int(d)
    if d == d2:
        count+=1
print(count)
print()

Solution (Python):
import math
N,D = list(map(int,input().split()))
X = []
for i in range(N):
    X.append(list(map(int,input().split())))
c = 0
for i in range(N):
    for j in range(i+1,N):
        sum_d = 0
        for d in range(D):
            sum_d += (X[i][d] - X[j][d])**2
        if math.sqrt(sum_d) == int(math.sqrt(sum_d)):
            c += 1
print(c)

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

List = []

for _ in range(n):
  r = list(map(int,input().split()))
  List.append(r)
  
Answers = []

for i in range(n):
  for j in range(n-i-1):
    Lsquare = 0
    for k in range(d):
      Lsquare += (List[i][k]-List[i+j+1][k])**2
    Answers.append(Lsquare**0.5)

Answer = []
for s in Answers:
  if s.is_integer()==True:
    Answer.append(s)

print(len(Answer))

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

A=[[int(a) for a in input().split()]for a in range(N)]

def int_test(a,n):
    if a.is_integer():
        n+=1

n=0


for i in range(0,N):

    if i != N:
        for j in range(i+1,N):
            sq=0.0
            for k in range(0,D):
                sq=sq+(A[i][k]-A[j][k])**2

            sq2=math.sqrt(sq)
            
            if sq2.is_integer():
                n+=1

print(n)

Solution (Python):

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

m = 0
for i in range(n):
	for j in range(i+1,n):
		a = 0
		for k in range(d):
			a += (point[i][k]-point[j][k])**2
		b = a**(1/2)
		if b.is_integer():
			m += 1
print(m)

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

cnt = 0
for j in range(N):
    for k in range(j+1, N):
        dist = 0
        for i in range(D):
            dist += (X[j][i]-X[k][i]) * (X[j][i]-X[k][i])
        dist = math.sqrt(dist)
        if dist.is_integer() is True:
            cnt += 1
print(cnt)

Solution (Python):
import itertools
import numpy as np

n,d = map(int, input().split())
x = np.asarray([list(map(int, input().split())) for i in range(n)])
c = 0
for v in itertools.combinations(x, 2):
  if np.linalg.norm(v[0] - v[1]).is_integer():
    c += 1
print(c)

Solution (Python):
def euclid(A, B):
    c2 = 0
    for a,b in zip(A,B):
        c2 += (a-b)**2
    return c2**0.5

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):
        c = euclid(X[i], X[j])
        if c.is_integer():
            cnt += 1
print(cnt)

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

for a in range(n):
    for b in range(a+1,n):
        for c in range(d):
            total+= (x[a][c]-x[b][c])**2
        result=math.sqrt(total)
        if(result.is_integer()):
            num+=1

        total=0
print(num)

Solution (Python):
N, D = map(int, input().split())
import math
X = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    X.append(array)
var = 0
for i in range(N-1):
  for k in range(N-1-i):
    s = 0
    for j in range(D):      
      s = s + (X[i+1+k][j] - X[i][j])*(X[i+1+k][j] - X[i][j])
    if math.sqrt(s) - (int(math.sqrt(s))) ==0:
      var = var+1
print(var)