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

Solution (Python):
import math

N, D = map(int, input().split())
xList = []
zahyoList = []
for x in range(N):
    xList.append(list(map(int, input().split())))

count = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        r = 0
        for n in range(D):
            r += (xList[i][n] - xList[j][n]) ** 2
        if (math.sqrt(r) % 1 == 0):
            count += 1

print(count)

Solution (Python):
import math


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


count = 0

for j in range(ND[0]):

    for u in range(ND[0]):
        if j == u:
            continue
        else:
            SUM = 0

            for b in range(ND[1]):
                SUM += pow(X[j][b] - X[u][b],2)

            SQ = math.sqrt(SUM)

            if SQ.is_integer():
                count+=1
            else:
                continue

print(int(count/2))

Solution (Python):

import math
import itertools

cnt = 0
n, d = [int(i) for i in input().split()]

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

for i in itertools.combinations(ipt, 2):
    dist_b = 0
    for j in range(d):
        dist_b += pow(abs(i[0][j] - i[1][j]), 2)
    
    if math.floor(math.sqrt(dist_b)) == math.ceil(math.sqrt(dist_b)):
        cnt += 1

print(cnt)

Solution (Python):
import math

n,d=map(int,input().split())
x={}
for a in range(0,n):
    x[a]=list(map(int,input().split()))
cou=0
for i in range(0,n):
    for j in range(i+1,n):
        s=0
        for b in range(0,d):
            s=s+(x[i][b]-x[j][b])**2
        if math.sqrt(s).is_integer()==True:
           cou=cou+1
print(cou)

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

vc = []

def isqrt(n):
    x = n
    y = (x + 1) // 2
    while y < x:
        x = y
        y = (x + n // x) // 2
    return x

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

cc = 0
for k, i in enumerate(vc):
    if len(vc) < 2:
        break
    for v in vc[k+1:]:
        summ = 0
        for (x, y) in zip(i, v):
            summ += abs(x - y) ** 2


        if isqrt(summ) == math.sqrt(summ):
            cc += 1


print(cc)

Solution (Python):
import itertools
n,d = map(int,input().split())
li = [list(map(int,input().split())) for i in range(n)]
nnn = [i for i in range(n)]
cnt = 0
for i,j in itertools.combinations(nnn,2):
  dis = 0
  for di in range(d):
    dis += (li[i][di]-li[j][di])**2
  if int(dis**(1/2))**2 == dis:
    cnt += 1
print(cnt)

Solution (Python):
import sys
from math import sqrt

def solve(N, D, X):
    def dist(ys, zs):
        sum = 0
        for d in range(D):
            sum += (ys[d] - zs[d])**2
        return sqrt(sum)
    count = 0
    for i in range(N):
        for j in range(i+1, N):
            d = dist(X[i], X[j])
            if d.is_integer():
                count += 1
    print(count)


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

if __name__ == "__main__":
    main()

Solution (Python):
import math

N, D = map(int,input().split())
A = [[0]*D]*N

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

cnt = 0
for i in range(N-1):
  
  for j in range(i+1,N):
    tmp = 0
    for m in range(D):
      tmp = tmp + (A[i][m]-A[j][m])**2
    if (math.sqrt(tmp)).is_integer():
      cnt += 1

print(cnt)

Solution (Python):
import math, itertools

def calc_dict(D, p_list):
    sqrt_in = 0
    for i in range(0, D):
        sqrt_in += abs( p_list[0][i] - p_list[1][i] )**2
    return math.sqrt( sqrt_in )

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

X_list = []
for i in range(0, N):
    X_list.append(list(X[i]))

points_list = list(itertools.combinations(X_list,2))

int_count = 0
for i in range(0, len(points_list)):
    dist = calc_dict(D, points_list[i])
    if( dist.is_integer() ):
        int_count += 1

print(int_count)

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

nums=[input().split()for i in range(N)]
sum=0
for i in range(N):
    for j in range(D):
        nums[i][j]=int(nums[i][j])


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

cout=0

for i in range(N-1):
    for j in range(i+1,N):
           for k in range(D):
               sum+=(nums[i][k]-nums[j][k])*(nums[i][k]-nums[j][k])

           sum=math.sqrt(sum)
          

           if is_integer_num(sum)==True:
                cout+=1
                sum=0
           else:
                sum=0

print(cout)

Solution (Python):
from math import sqrt
N, D = map(int, input().split())
X = []
ans = 0
for _ in range(N):
    x = [int(s) for s in input().split()]
    X.append(x)
for i in range(N - 1):
    for j in range(i + 1, N):
        dist = 0
        for d in range(D):
            dist += (X[i][d] - X[j][d]) ** 2
        sqdist = round(sqrt(dist))
        if sqdist ** 2 == dist:
            ans += 1
print(ans)

Solution (Python):
import math

def norm(x, y):
    result = 0
    for i in range(len(x)):
        result += (x[i] - y[i]) * (x[i] - y[i])
    result = math.sqrt(result)
    return result

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

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

print(result)

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

points=[]

counts=0

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


for i in range(N):
    for j in range(i+1, N):
        sum= 0
        for k in range(D):
            sum+= (points[i][k] - points[j][k])**2
        sum= pow(sum, (1/2))
        if(sum.is_integer()):
            counts+= 1

print(counts)

Solution (Python):
import numpy as np

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

count = 0
while X:
  Xt = X.pop()
  for Xi in X:
    if np.linalg.norm(Xt-Xi).is_integer():
      count += 1
    
print(count)

Solution (Python):
import itertools

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

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

cnt = 0
for v in itertools.combinations(X, 2):
  f = 0
  for w in range(D):
    f += (v[0][w]-v[1][w])**2
  f = f ** 0.5  
  if f.is_integer():
    cnt += 1
    
print(cnt)

Solution (Python):
import math
import itertools
N,D = map(int, input().split())
X = []
count = 0
for i in range(N):
    a1 = list(map(int, input().split()))
    X.append(a1)
p3 = 0   
a2 = list(itertools.combinations(range(N),2))

for i,e in a2:
    for j in range(D):
        p = X[i][j]
        p1 = X[e][j]
        p3 += pow(p-p1,2)
    p4 = math.sqrt(p3)
    if p4.is_integer():
        count += 1
    p3 = 0
print(count)

Solution (Python):
import math

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

def check(a,b):
    distance = 0
    for x,y in zip(a,b):
        distance += (x - y) ** 2
    return math.floor(math.sqrt(distance)) == math.sqrt(distance)

ans = 0

for i in range(N):
    for j in range(i+1,N):
        ans += check(ab[i],ab[j])

print(ans)

Solution (Python):
N, D = (int(item) for item in input().split())

import numpy as np

def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()
      
grid = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    grid.append(array)

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

Solution (Python):
import numpy as np

points, dimention = map(int, input().split())
count = 0

coordinate = []
for i in range(points):
  coordinate.append(input())

for s in range(points-1):
  point1 = np.array([int(i) for i in coordinate[s].split()])
  for t in range(s+1, points):
    point2 = np.array([int(i) for i in coordinate[t].split()])
    distance = np.sqrt(np.sum((point1 - point2) * (point1 - point2)))
    if distance.is_integer():
      count += 1
print(count)

Solution (Python):
import math
import itertools


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


for n in range(N):
    l = input().split()
    X[n] = [0]*D
    for d in range(D):
        X[n][d] = int(l[d])


count = 0
for y, z in itertools.combinations(X, 2):
    d = math.sqrt(sum(pow(y[i] - z[i], 2) for i in range(D)))
    if d.is_integer():
        count += 1

print(count)

Solution (Python):
import numpy as np

n,d=list(map(int, input().split()))
lst=[]
for i in range(n):
    lst.append(list(map(int, input().split())))
answer=0
for i in range(n):
    for j in range(n):
        if i==j:
            continue
        if i>=j:
            continue
        a=np.array(lst[i])
        b=np.array(lst[j])
        c=a-b
        d=np.linalg.norm(c)
        if d.is_integer():
            answer+=1
print(answer)

Solution (Python):
import math


a = input().split()
li = [int(i) for i in a]


b = [input().split() for i in range(li[0])]
lis = [[int(j) for j in i] for i in b]


an = [[(lis[i][j]-lis[k][j])**2 for j in range(li[1])] for i in range(0,len(lis)-1) for k in range(i+1,len(lis))]
ann = [math.sqrt(sum(i)) for i in an] 
ans = [i for i in ann if (i.is_integer())]
print(len(ans))

Solution (Python):
import math
import itertools

N , D  = map(int,input().split())
X_list = list() 
count = 0

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

for i in itertools.combinations(X_list,2):
	distance = 0
	for j in range(len(i[0])):
		distance += abs(i[0][j]-i[1][j])**2
	if math.sqrt(distance) % 1 == 0:
		count += 1 
print(count)

Solution (Python):
import numpy as np
N,D = map(int,input().rstrip().split(' '))
X = []
for i in range(N):
    X.append(list(map(int,input().rstrip().split(' '))))
r = []
for i in range(N):
    for j in range(i+1,N):
        ran = 0
        for l in range(D):
            ran += abs(X[i][l] - X[j][l]) **2
        r.append(ran)
r = [i for i in np.sqrt(r) if i % 1 == 0]
print(len(r))

Solution (Python):

import math
def main():
    N,D = map(int,input().split())
    X=[list(map(int,input().split())) for i in range(N)]
    count = 0
    for i in range(N):
        for k in range(N-1-i):
            K = 0
            KK = 0
            for j in range(D):
                K += ((X[i][j])-(X[N-1-k][j]))**2
            KK = K**0.5
            if isinstance(KK,int) or KK.is_integer():
                count += 1
    print(count)
if __name__ == '__main__':
    main()

Solution (Python):
import math

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

cnt = 0
for i in range(n - 1):
  for j in range(i+1, n):
    hoge = 0
    for num in range(d):
      hoge = hoge + pow(abs(x[i][num] - x[j][num]),2)
    if(hoge == pow(int(math.sqrt(hoge)), 2)):
       cnt = 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())))

ans = 0
for i in range(n):
    for q in range(n):
        sumv = 0
        if i == q:
            continue
        for j in range(d):
            sumv += (x[i][j] - x[q][j]) ** 2

        if math.sqrt(sumv).is_integer() == True:
            ans += 1

print(round(ans/2))

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

A = [[0 for x in range(D)]for y in range(N)]
for i in range(N):
  A[i] = [int(x) for x in sys.stdin.readline().split()]

B=[]
x=-126
while x**2 <= 16000:
  B.append(x**2)
  x+=1
count = 0
for i in range(N-1):
  for j in range(i+1,N):
    y = 0
    for k in range(D):
      y += (A[j][k]-A[i][k])**2

    if y in B:
      count+=1
print(count)

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

Y = []
i=0
n=0
for j in X[i:]:
    for k in X[i+1:]:
        m=0
        for l in range(D):
            m=m+(j[l]-k[l])**2
        o=math.sqrt(m)
        if o.is_integer()==True:
            n+=1

    i+=1

print(n)

Solution (Python):
import math
N,D=map(int,input().split())
X=[]
cnt=0
def distance(x,y):
    d2=[]
    for k in range(D):
        d2.append((X[x][k]-X[y][k])**2)
    return math.sqrt(sum(d2))
for i in range(N):
    X.append(list(map(int,input().split())))
for j in range(N-1):
        for l in range(j+1,N,):
            if float.is_integer(distance(j,l)):
                cnt+=1 
print(cnt)

Solution (Python):
from math import sqrt

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

def issqrt(k):
  a = int(sqrt(k))
  if (k == a**2) or (k == (a+1)**2):
    return True
  else:
    return False
  
def distance(p1, p2):
  h = 0
  for i in range(d):
    h += (p1[i] - p2[i])**2
  return h
  
def solve():
  ans = 0
  for i in range(n):
    for j in range(i+1, n):
      dis = distance(points[i], points[j])
      ans += issqrt(dis)
  return ans

print(solve())

Solution (Python):
import math

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

    count = 0
    for i in range(n):
        if i == n: break
        for j in range(i+1, n):
            
            
            

            dis = get_distance(X[i], X[j], d)
            if dis.is_integer(): count += 1
            
    print(count)

def get_distance(P1, P2, d):
    s = 0
    for i in range(d):
        s += (P2[i] - P1[i])**2
    return math.sqrt(s)

main()

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

x=np.array(x)

ans=0
for i in range(n-1):
    for j in range(i+1,n):
        
        if np.sum((x[i]-x[j])**2) in square:
            ans+=1
print(ans)

Solution (Python):
import math

n,d = map(int,input().split())
x=[]
for i in range(n):
    x.append(list(map(int,input().split())))
    
ans = 0
for i in range(n):
    for m in range(i+1,n):
        temp = 0
        for l in range(d):
            temp += (x[i][l]-x[m][l])**2
            
        temp **= 0.5

        if temp%1==0:
            ans += 1
        
print(ans)

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

Solution (Python):
n, d = map(int, input().split())
x_list = [[int(x) for x in input().split()] for _ in range(n)]
power_list = [i**2 for i in range(200)]
ans = 0

for l in range(~-n):
  for r in range(-~l, n):
    if int(sum([(y-z)**2 for y, z in zip(x_list[l], x_list[r])])) in power_list:
      ans += 1

print(ans)

Solution (Python):
from scipy.spatial.distance import euclidean as e

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

ans = 0

for i in range(n):
    for j in range (i+1, n):
        if e( l[i], l[j] ).is_integer(): 
            ans += 1
        
print(ans)

Solution (Python):
import math
N,D=map(int,input().split())
a=[]
c=0
for i in range(1,N+1):
    g=list(map(int,input().split()))
    a.append(g)
for i in range(N):
    for k in range(1,N-i):
        dis=0
        for j in range(D):
            z=a[i][j]-a[i+k][j]
            dis=dis+z*z
        dis=math.sqrt(dis)
        b=int(dis)-dis
        if b==0:
            c=c+1
print(c)

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


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

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

res = 0
for i, j in combinations(range(N),2):
  dist = 0
  for d in range(D):
    delta = X[i][d] - X[j][d]
    dist += delta**2

  if np.sqrt(dist) == int(np.sqrt(dist)):
    res += 1

print(res)

Solution (Python):
import numpy as np
N, D = map(int, input().split(' '))
def parse_list(hoge):
  result = list(map(int, input().split(' ')))
  return np.array(result)
points = list(map(parse_list, range(N)))


def calc_dist(points, i , j ):
    result = np.linalg.norm(points[i] - points[j], ord=2)
    return result

res_cnt = 0
for i in range(N):
    for _j in range(N-i-1):
        j = _j + i + 1
        res = calc_dist(points, i, j )
        if float.is_integer(res):
            res_cnt += 1
print(res_cnt)

Solution (Python):
import numpy as np

s = input().split()
N = int(s[0])
D = int(s[1])
X=np.empty((0,D),int)
count=0

for i in range(0,N):
    s = input().split()
    X=np.append(X,np.array([s],dtype='int16'),axis=0)

for i in range(0, N-1):
    for j in range(i+1,N):
        if np.sqrt(np.sum(np.square(X[i]-X[j]))).is_integer()==True:
            count+=1

print(count)

Solution (Python):
N, D = map(int, input().split())
x = [None for k in range(N)]
for k in range(N):
  a = list(map(int, input().split()))
  x[k] = a
ans = 0
for n in range(N):
  for p in range(n):
    wa = 0
    for d in range(D):
      wa += (x[n][d] - x[p][d])**2
    t = wa ** 0.5
    if wa == int(t) **2:
      ans += 1
print(ans)

Solution (Python):
import math


def distance(N, D, X):
    distance_list = list()

    for n in range(N - 1):
        for i in range(n + 1, N):
            tmp = 0
            for d in range(D):
                tmp += (abs(X[n][d] - X[i][d])) ** 2
            distance_list.append(math.sqrt(tmp))

    return distance_list


def main():

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

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

    distance_list = distance(N, D, X)

    ans = 0

    for i in distance_list:
        if i.is_integer():
            ans += 1

    print(ans)

    return


if __name__ == "__main__":
    main()

Solution (Python):
p=list(map(int,input().split()))
data_list = [ list(map(int,input().split(" "))) for i in range(p[0])]
cnt = 0
l = 0
for i in range(p[0]-1):
    for j in range(i+1,p[0]):
        for k in range(p[1]):
            l += pow(abs(data_list[i][k] - data_list[j][k]),2)
        l = pow(l,1/2)
        cnt += 1 if l.is_integer() else 0
        l = 0
print(cnt)

Solution (Python):
import numpy as np

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

listX=[] 
while True:
    try:
        listX.append(list(map(int,input().split())))

    except:
        break;
        
X=np.array(listX)
flag=0
for  i in range(N):
    for j in range(N):

        if i>=j:
            continue
        
        dist=X[i,:]-X[j,:]
        dist=np.linalg.norm(dist)

        if dist%1==0:
            
            flag+=1
print(flag)

Solution (Python):
import numpy as np

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

for i in range(0,N):
  for j in range(i+1,N):
    vec_a=np.array(listX[i])
    vec_b=np.array(listX[j])
    Y=np.linalg.norm(vec_a - vec_b)
  
    if Y.is_integer()==True:
      
      if Y==0:
        next
      else:
        count+=1
print(count)

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

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

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

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

Solution (Python):
import math

n, d = map(int, input().split())
c = [0]*n

for i in range(n):
	c[i] = (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):
			s = (c[i][k]-c[j][k]) ** 2
			sum += s
		dist = math.sqrt(sum)

		if dist.is_integer():
			cnt += 1
			
print(cnt)

Solution (Python):



import numpy as np

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

x = np.array(x)
count = 0
for i in range(N):
    for j in range(i+1, N, 1):
        diff_array = x[i] - x[j]
        diff = np.sqrt(np.sum(diff_array**2))
        if float(diff).is_integer():
            count += 1
print(count)

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return list(map(float, sys.stdin.readline().split()))
def LS():return sys.stdin.readline().split()
def SR(n): return [list(sys.stdin.readline())[:-1] for i in range(n)]
def IR(n): return [int(sys.stdin.readline()) for i in range(n)]
def LIR(n): return [list(map(int, sys.stdin.readline().split())) for i in range(n)]
def LSR(n): return [list(map(list, sys.stdin.readline().split())) for i in range(n)]
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
sys.setrecursionlimit(1000000)
INF = float('inf')
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

N, D = LI()

X = LIR(N)

ans = 0
for xd1 in X:
    for xd2 in X:
        ret = 0
        for x1, x2 in zip(xd1, xd2):
            ret += (x2-x1)**2
        ret = math.sqrt(ret)
        ans += ret.is_integer()

print((ans-N)//2)

Solution (Python):
import math
n,d=map(int,input().split())
x,y,z=[],[],[]
flag=0
co=0
i,j,u=0,1,0
for l in range(n):
 x=x+(list(map(int,input().split())))
while i < n-1:
 while j < n:
  co+=1
  y=x[i*d:(i+1)*d]
  z=x[j*d:(j+1)*d]
  for l in range(len(y)):
   u+=(y[l]-z[l])*(y[l]-z[l])
  u=math.sqrt(u)
  if str(u)[len(str(u))-1] == "0":
   flag+=1
  u=0
  j+=1
 i+=1
 j=i+1
print(flag)

Solution (Python):
import math

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

count = 0
dif2sum = 0
    
for i in range(n - 1):
    for j in range(i + 1, n):
        for k in range(d):
            dif = X[i][k]-X[j][k]
            dif2sum += dif * dif
        if math.sqrt(dif2sum).is_integer():
            count += 1
        dif2sum = 0
    
print(count)

Solution (Python):
import sys
import math
from pprint import pprint
import numpy as np

def solve(n, d, p):
  count = 0
  for i in range(n):
    for j in range(i, n):
      if i == j:
        continue
      
      distance = math.sqrt(sum(map(lambda i: i ** 2, p[i] - p[j])))
      
      if float.is_integer(distance):
        count += 1

  return count


if __name__ == "__main__":
  n, d = map(int, sys.stdin.readline().rstrip().split(" "))
  p = []
  for _ in range(n):
    p.append(np.array(map(int, sys.stdin.readline().rstrip().split(" "))))

  
  print solve(n, d, p)

Solution (Python):
import math as mt

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

xlis = [[0 for _ in range(D)] for _ in range(N)]

for i in range(N):
    inputlis = list(map(int, input().split()))
    for l in range(D):
        xlis[i][l] = inputlis[l]

cnt = 0

for i in range(N):
    for s in range(N):
        res = 0
        if i == s:
            continue
        for l in range(D):
           res += ((xlis[i][l] - xlis[s][l]) ** 2)

        if mt.sqrt(res).is_integer():
            cnt += 1


print(int(cnt/2))

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

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

print(cnt)

Solution (Python):
import math

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

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

Solution (Python):
import math

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

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

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

        a = 0
        for k in range(D):
            a += (c[i][k] - c[j][k]) ** 2
    
        a = math.sqrt(a)
        if a.is_integer() == True:
            ans += 1

print(ans)

Solution (Python):
import math

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

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

Solution (Python):
import math

N,D=input().split()

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

count=0

for i in range(int(N)):
    for j in range(i+1,int(N)):
        result1=0
        for k in range(int(D)):
            result1+=pow(x[i][k]-x[j][k],2)

        diff=math.sqrt(result1)
        if diff.is_integer():
            count+=1

print(count)

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

res = 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
        if math.sqrt(tmp).is_integer():
            res += 1

print(res)

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

for i in range(N):
    for j in range(i, N):
        if i != j:
            tmp = 0.0
            for k in range(D):
                tmp += abs(X[i][k] - X[j][k]) ** 2
            tmp = math.sqrt(tmp)
            if tmp.is_integer():
                result += 1

print(result)

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

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

count=0
for i in range(0,N):
  for j in range(i+1,N):
    Dist=0
    for k in range(0,D):
      Dist=Dist+(X[i][k]-X[j][k])**2
    mod=np.sqrt(Dist)%1
    if mod==0:
      count=count+1

print(count)

Solution (Python):
def issq(n):
    for i in range(2 * n):
        if i * i == n:
            return True
    return False
    

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

count = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        sqdist = 0
        for k in range(d):
            sqdist = sqdist + ((x[i][k] - x[j][k]) ** 2)
        if issq(sqdist) == True:
            count = count + 1

print(count)

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

X_list = list(list(map(int, input().split())) for _ in range(N))



ans = 0
for i in range(N-1):
    for j in range(N-i-1):
        double_s = 0
        S = 0
        for k in range(D):
            double_s += (X_list[i][k] - X_list[j+i+1][k]) ** 2

        S = math.sqrt(double_s)
        
        if(abs(S - int(S)) == 0):
            ans += 1








print(ans)

Solution (Python):
import math
N, D = map(int, input().split())
nlist = []
anslist = []
for i in range(N):
    llist = list(map(int, input().split()))
    nlist.append(llist)
a = 0
for x in range(N - 1):
    for i in range(x, N - 1):
        tmp = 0
        for j in range(D):
            tmp += (abs(nlist[x][j] - nlist[i + 1][j]) ** 2)
        anslist.append(int(math.sqrt(tmp)) - math.sqrt(tmp))

cnt = 0
for i in anslist:
    if i == 0.0:
        cnt += 1
print(cnt)

Solution (Python):
import itertools


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

result = []
tmp = 0

for i in itertools.combinations(s, 2):
    tmp = [(x - y)**2 for (x, y) in zip(i[0], i[1])]
    tmp = sum(tmp)
    result.append(tmp)

result2 = []
for i in result:
    tmp = int(i ** 0.5)
    if abs(tmp*tmp - i) < 1e-6:
        result2.append(tmp)

print(len(result2))

Solution (Python):
import numpy as np

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

X = []

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

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

print(res)

Solution (Python):
import math
a=input()
b=a.split()
b=list(map(int,b))
i = [input() for i in range(b[0])]
for o in range(b[0]):
    i[o]=i[o].split()
    i[o]=list(map(int,i[o]))
f=0
for p in range(b[0]-1):
    for g in range(b[0]-p-1):
        h=g+p+1
        c=0
        for j in range(b[1]):
            c+=(i[p][j]-i[h][j])*(i[p][j]-i[h][j])
        d=math.sqrt(float(c))
        if (d-int(d))==0:
            f+=1
print(f)

Solution (Python):
import sys 
import numpy as np 

def distance():
    N,D=map(int,input().split())
    y=[]
    ans=0
    for i in range(N):
        x=list(map(int,input().split()))
        y.append(x)
    y=np.array(y)
    y.reshape(N,-1)
    for i in range(N-1):
        for j in range(i+1,N):
            dis=(((y[i]-y[j])**2).sum())**(1/2)
            if dis.is_integer():
                ans+=1
    
    print(ans)

distance()