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

Solution (Python):
import math

n, d = [int(y) for y in input().split()]
x = []

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

distance = []

for i in range(n):
  for j in range(n):
    di = 0
    for k in range(d):
      di += (x[i][k]-x[j][k])**2
    di = math.sqrt(di)
    if (di == int(di)):
      distance.append(di)

print('{0}'.format(int((len(distance)-n)/2)))

Solution (Python):
arg0 = list(map(int, input().split()))

arg_array = []

for i in range(arg0[0]):
  arg = list(map(int, input().split()))
  arg_array.append(arg)

counter = 0
for i in range(arg0[0]):
  for j in range(i+1, arg0[0]):
    distance = 0
    
    for k in range(arg0[1]):
      distance += (arg_array[i][k] - arg_array[j][k]) ** 2
    
    distance = distance ** (1.0/2)
    if distance == int(distance):
      counter += 1

print(counter)

Solution (Python):
from sys import stdin

def bisearch(f, n):
    l = 0
    r = n
    fl = f(l)
    fr = f(r)
    while l <= r:
        m = (l + r) // 2
        fm = f(m)
        if fm == n:
            return True
        elif fm > n:
            r = m - 1
            fr = f(r)
        else:
            l = m + 1
            fl = f(l)
    return False

def is_sqrt(n):
    return bisearch(lambda m: m * m, n)

def main():
    N, D = map(int, input().split())
    X = [tuple(map(int, input().split())) for _ in [0] * N]

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

input = lambda: stdin.readline()
main()

Solution (Python):
import math
n,d = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(n)]
def cheak(y,z):
    counter = 0
    for i in range(d):
        counter += (y[i]-z[i])**2
    if math.sqrt(counter).is_integer():
        return True
    return False
count = 0
for i in range(n):
    for k in range(i+1,n):
        if(cheak(x[i],x[k])):
            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
tmp = []

for i in range(N):
    r1 = X[i]
    for j in range(N):
        t = str(i)+str(j)
        if i == j or t in tmp or str(j)+str(i) in tmp:
            continue

        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
        tmp.append(t)

print(count)

Solution (Python):

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

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

cnt = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        tmp = 0.0
        for k in range(d):
            tmp += pow((x[i][k] - x[j][k]), 2)

        tmp = math.sqrt(tmp)
        cnt += tmp.is_integer()

print(cnt)

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

pow2 = set()
for i in range(40**2*10):
    pow2.add(i**2)

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

print(ans)

Solution (Python):
import math

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

ans = 0
for i in range(n):
  ai = a_list[i]
  for j in range(i+1,n):
    aj = a_list[j]
    l = math.sqrt(sum([(x-y)**2 for (x,y) in zip(ai, aj)]))
    if l - round(l) == 0:
      ans += 1

print(ans)

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

count = 0
m = 0
k = n-1
while m < k:
    for i in range(m,n-1):
        an = 0
        for j in range(d):
            an += abs(ls[m][j] - ls[i+1][j])**2
        if ((math.sqrt(an)).is_integer()) == True:
            count += 1
    m += 1
print(count)

Solution (Python):
import math
from collections import deque


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

points = []

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


def distance(x, y):
    dd = 0
    for xy in zip(x,y):
        dd += (xy[0] - xy[1])**2
    return math.sqrt(dd)

q = deque(points)

result = 0
while len(q) != 0:
    left = q.popleft()
    for right in q:
        d = distance(left, right)
        if d.is_integer():
            result += 1
        else:
            pass

print(result)

Solution (Python):
import math

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

n,d = map(int,input().split())
x = []
for i in range(n):
    x.append([int(j) for j in input().split()])
c = 0
for i in range(n-1):
    for j in range(i+1,n):
        dist = 0
        for a in range(d):
            dist += (x[i][a] - x[j][a]) * (x[i][a] - x[j][a])
        if is_integer(math.sqrt(dist)):
            c += 1
print(c)

Solution (Python):
import math

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


dis = []
for i in range(n):
    for j in range(n):
        distanse = 0
        for k in range(d):
            distanse += abs(x[i][k]-x[j][k])**2
        dis.append(math.sqrt(distanse))

ans = 0
for i in dis:
    a = i
    if a.is_integer() == True:
        ans += 1
print(int((ans-n)/2))

Solution (Python):
import sys
all_data = sys.stdin.readlines()

line1 = [int(a) for a in all_data[0].split()]
points_num = line1[0]
dimensions = line1[1]

data_int = []
for item in all_data[1:points_num + 1]:
    tuple_str = item.split()
    tuple_int = [int(a) for a in tuple_str]
    data_int.append(tuple_int)
    
def dii(coor1, coor2):
    import math
    pyth_sum = 0
    for dimension in range(0, dimensions):
        pyth_sum += (coor1[dimension] - coor2[dimension])**2
    distance = math.sqrt(pyth_sum)
    if distance % 1 == 0:
        return True
    else:
        return False

num_pairs = 0

for idx1, val1 in enumerate(data_int):
    coor1 = val1
    for idx2, val2 in enumerate(data_int[idx1 + 1:]):
        coor2 = val2
        if dii(val1, val2):
            num_pairs += 1

print(num_pairs, end="")

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

for i in range(n):
  for j in range(r,n):
    tmp = 0
    for k in range(d):
      tmp += abs(lis[i][k]-lis[j][k])**2
    rtmp = math.sqrt(tmp)
    
    if rtmp.is_integer():
      res += 1
  r+=1
print(res)

Solution (Python):
from math import factorial
import itertools
n,d =map(int,input().split())
x=[]
cnt=0
n_lis = [i for i in range(n)]
n_list = list(itertools.combinations(n_lis, 2))
for i in range(n):
    tmp = list(map(int,input().split()))
    x.append(tmp)
    
for index1, index2 in n_list:
    if d != 1:
        dist = 0
        for ind in range(d):
            dist += (x[index1][ind]-x[index2][ind])**2
        if int(dist **(1/2)) == dist **(1/2):
            cnt+=1
    if d == 1:
        cnt = int(factorial(n) / factorial(2) / factorial(n - 2))

print(cnt)

Solution (Python):
import numpy as np

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

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

def Distanse_int(x,y,D):
    A=0
    for i in range(D):
        A = A + (x[i]-y[i])**2
       
    B = np.sqrt(A)
    if B == int(B):
        return(1)
    else:
        return(0)

count = 0

for i in range(N-1):
    for k in range(i+1,N):
        B = Distanse_int(X[i],X[k],D)
        if B == 1:
            count = count + 1

print(count)

Solution (Python):
import math

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

ans = 0

for i in range(N):
    for j in range(N):
        if j <= i:
            continue
        temp = 0
        for k in range(D):
            temp += pow((X[i][k] - X[j][k]), 2)
        
        temp = math.sqrt(temp)
        if temp == math.floor(temp):
            ans += 1

print(ans)

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

ans = 0
l = [list(map(int, input().split())) for _ in range(n)]
for i in range(n-1):
  for j in range(i+1,n):
    if dist(l[i],l[j]).is_integer():
        ans += 1
print(ans)

Solution (Python):
import numpy

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





cnt=0
for i in range(n):
    for j in range(n-i-1):

        a = numpy.array(x[i])
        b = numpy.array(x[i+j+1])
        u = b - a
        if numpy.linalg.norm(u).is_integer():
            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):
    for j in range(i+1,N):
        d2=0
        for dim in range(D):
            d2+=(X[i][dim]-X[j][dim])**2
        d=math.sqrt(d2)
        if (round(d) == d):
            count+=1
print(count)

Solution (Python):
n , D =map(int,input().split())
import math
 
a = [input().split() for l in range(n)]
count = 0
 
for i in range(n):
  for j in range(n):
    if i == j:
      count += 0
    else:
      x = []
      for c in range(D):
        x.append((int(a[i][c]) - int(a[j][c])) ** 2)
      d = math.sqrt(sum(x))
      d = float(d)
      if d.is_integer():
        count += 1
print(int(count/2))

Solution (Python):
import math


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


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

li = []
count = 0

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

for i in range(N - 1):
    for j in range(i + 1, N):
        target = 0
        if D != 1:
            for k in range(D):
                target += (li[i][k] - li[j][k]) ** 2
            if is_integer_num(math.sqrt(target)):
                count += 1
        else:
            target += (li[i][0] - li[j][0]) ** 2
            if is_integer_num(math.sqrt(target)):
                count += 1


print(count)

Solution (Python):
N, D = map(int, input().split())
X = []
for _ in range(N):
    X.append([int(x) for x in input().split()])
ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        s = sum((X[i][d] - X[j][d])**2 for d in range(D))
        if any(i**2 == s for i in range(1000)):
            ans += 1

print(ans)

Solution (Python):
from math import modf
N, D=map(int,input().split())
lis = []
for i in range(N):
   li = list(map(int,input().split()))	
   lis.append(li)
res = 0
ans = 0
for i in range (N):
   for j in range(i+1,N):
      for k in range(D):
         a = lis[i][k]-lis[j][k]
         res += a ** 2
      b = res ** 0.5
      decimal, integer = modf(b)
      if (decimal == 0):
         ans += 1
      res = 0
print(ans)

Solution (Python):
def resolve():
    data = []
    n,d = map(int,input().split())
    for _ in range(n):
        x = list(map(int,input().split()))
        data.append(x)
    square =[]
    for i in range(1,200):
        square.append(i*i)
    ans=0
    for i in range(n):
        for j in range(i+1,n):
            k = [abs(l-m)**2 for l,m in zip(data[i],data[j]) ]
            s=sum(k)
            if s in square:
                ans = ans + 1

    print(ans)


if __name__ == "__main__":
    resolve()

Solution (Python):
import math

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

tmp = []

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

cnt = 0

for i in range(len(tmp)):
    for j in range(len(tmp))[i+1:]:
        y = 0
        for k in range(D):
            y += abs(tmp[i][k] - tmp[j][k]) ** 2


        if math.sqrt(y).is_integer():
            cnt += 1

print(cnt)

Solution (Python):
import math
n, d = list(map(int, input().split()))
a = [[0]*d]*n
ans = []
temp = 0
count = 0
for i in range(n):
    a[i] = list(map(int, input().split()))

for i in range(n):
    for j in range(i+1, n):
        for k in range(d):
            temp += (a[i][k]-a[j][k])*(a[i][k]-a[j][k])
        ans.append(math.sqrt(temp))
        temp = 0
for i in range(len(ans)):
    if ans[i]%1 == 0:
        count+=1
print(count)

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

Solution (Python):
from sys import stdin
import math

n, d = map(int, input().split())
data = [stdin.readline().rstrip().split() for _ in range(n)]


count = 0
fig = 0

for i in range(n):

        for j in range(n):

                if i == j:
                        pass
                elif i > j:
                        pass
                else:
                        fig = 0
                        res = 0

                        for h in range(d):
                                fig += abs(int(data[i][h]) - int(data[j][h])) **2
                        res = math.sqrt(fig)
                        
                        if res%1 == 0:
                                count +=1



print(count)

Solution (Python):
import math
import itertools

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

coordinate = []
for i in range(N):
  coordinate.append(list(map(int, input().split())))
  
cnt = 0
c_list = list(itertools.combinations(coordinate, 2))

for i in range(len(c_list)):
  combined = [(x - y)**2 for (x, y) in zip(c_list[i][0], c_list[i][1])]
  combined = math.sqrt(sum(combined))
  if combined.is_integer():
    cnt += 1

print(cnt)

Solution (Python):
import math

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

a = [i**2 for i in range(300)]
n = 1
t = 0
for i in range(N):
    k = i + n
    for j in range(k, N):
        count = 0
        for l in range(D):
            count += (x[i][l] - x[j][l]) ** 2
        n += 1
        if count in a:
            t += 1
    n = 1

print(t)

Solution (Python):

N, D = map(int, input().split())
List=[[int(j) for j in input().split()] for i in range(N)]
count =0
pp =0

for j in range(1,N):
    for i in range(j,N):
        pp= pp + 1
        combined1 = sum([(x-y)**2 for (x, y) in zip(List[j-1], List[i])])**0.5
        flg =combined1.is_integer()
        
        if flg ==True:
            count =count+1

print(count)

Solution (Python):
import math

N,D = map(int, raw_input().split())
ans = 0
X = []

for i in range(0, N):
    x = map(int, raw_input().split())
    X.append(x)
    for j in range(0, i):
        d = 0
        for k in range(0, D):
            d += (X[i][k] - X[j][k]) ** 2
        dx = math.sqrt(d)
        if dx.is_integer():
            ans += 1

print(ans)

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

LIST=[[0]*D]*N



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


  
  
for i in range(N):
  for j in range(N):
    for k in range(D):
      DISTANCE=DISTANCE+(LIST[i][k]-LIST[j][k])**2
    DISTANCE=DISTANCE**0.5
    if DISTANCE%1==0 and DISTANCE!=0:
      COUNT=COUNT+1
      
    DISTANCE=0
    
print(int(COUNT/2))

Solution (Python):
import numpy as np

N, D = map(int, raw_input().split(' '))

nizyo = np.array(range(1, 127))
nizyo = nizyo ** 2
X = []
for i in range(N):
    X.append(map(int, raw_input().split(' ')))

count = 0
for j in range(1, N):
    for k in range(j):

        if j > k:

            d = np.sum( (np.array(X[k]) - np.array(X[j])) **2)
            
            if d in nizyo:
                count += 1
            
print(count)

Solution (Python):
import sys
import math
import itertools

input = sys.stdin.readline


def main():
    n, d = [int(i) for i in input().split()]
    ps = [[int(i) for i in input().split()] for _ in range(n)]
    cnt = 0
    for i, x in itertools.combinations(range(n), 2):
        hige = math.sqrt(sum([(ps[i][j] - ps[x][j]) ** 2 for j in range(d)]))
        if hige % 1 == 0:
            cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()

Solution (Python):

import numpy as np
np.seterr(all='ignore')

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

Xs = []
for _ in range(N):
    Xs.append(list(map(int, input().split())))
mat = np.array(Xs)

d = np.empty([mat.shape[0], mat.shape[0]])
d[:,:] = np.nan

for i in range(mat.shape[0]):
    for j in range(i+1, mat.shape[0]):
        d[i,j] = np.sqrt(((mat[i,:] - mat[j,:])**2).sum())

np.mod(d,1,d)
print('{}'.format(np.sum(d==0)))

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

c = 0
ans = []
for i in range(len(l)-1):
  for j in range(i+1,len(l)):
    u = l[i] - l[j]
    
    ans.append(np.linalg.norm(u))

for k in ans:
  if k % 1 == 0:
    c += 1
print(c)

Solution (Python):





def main():
  N,D = map(int, input().split())
  Xn = []
  for _ in range(N):
    Xn.append(list(map(int, input().split())))

  ans = 0
  ansset = [i**2 for i in range(1001)]
  for i in range(N):
    for j in range(i+1,N):
      sm = 0
      for k in range(D):
        sm += (Xn[i][k]-Xn[j][k])**2
      if sm in ansset:
        ans += 1
  print(ans)


if __name__ == "__main__":
  main()

Solution (Python):

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

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


cnt=0
lenx=len(X)
leny=len(X[0])
for i in range(lenx):
   
    for j in range(i+1,lenx):
        suma=0
        for k in range(leny):
            suma+=(X[i][k]-X[j][k])**2
 
        if math.sqrt(suma)%1==0:
       
            cnt+=1
        
print(cnt)

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

Solution (Python):
import numpy
N,D=map(int,input().split())
X=[list(map(int,input().split())) for i in range(N)]
A=0
for i in range(N):
    for j in range(N-i-1):
        Z=numpy.linalg.norm(numpy.array(X[i])-numpy.array(X[i+j+1]))
        if Z.is_integer()== True:
            A=A+1
print(A)

Solution (Python):
import math

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


flag = 0
for i in range(n):
  for j in range(i+1, n):
    total = 0
    for k in range(d):
      total = total + (ls1[i][k]-ls1[j][k])**2
    total_root = math.sqrt(total)
    
    if total_root.is_integer():
      flag += 1
print(flag)

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

l = stdin.readline().rstrip().split()
l = [int(s) for s in l]

data = [stdin.readline().rstrip().split() for _ in range(l[0])]
for i in range(len(data)):
	data[i] = [int(s) for s in data[i]]

l = data
c = itertools.combinations(l, 2)
hoge = []
vvv = []
for v in itertools.combinations(l, 2):
    vvv.append(v)

for i in range(len(vvv)):
    vvv[i]
    calc = np.linalg.norm(np.array(vvv[i][0]) - np.array(vvv[i][1]))
    hoge.append(calc.is_integer())

print(hoge.count(True))

Solution (Python):
def distance(a, b):
	cont = 0
	for k in xrange(len(a)):
		cont += (a[k] - b[k]) * (a[k] - b[k])
	return cont ** 0.5
n, t = map(int, raw_input().split())

ar = []

for i in xrange(n):
	ar.append(map(int, raw_input().split()))
	
cont = 0
for k in xrange(n):
	for l in xrange(k + 1, n):
		if distance(ar[k], ar[l]) == int(distance(ar[k], ar[l])):
			cont += 1
			
print cont

Solution (Python):
import math
import itertools
N, D = map(int, input().split())
 
count = 0
all_list = []
for _ in range(N):
    p_list = list(map(int, input().split()))
    all_list.append(p_list)

comb_list = list(itertools.combinations(all_list, 2))
for f_list, l_list in comb_list:
    diff_list = [(i-j)**2 for i, j in zip(f_list, l_list)]
    dist = math.sqrt(sum(diff_list))
    if dist == int(dist):
        count += 1

print(count)

Solution (Python):
import numpy as np 


dim = list(map(int, input().split()))
N = dim[0]
D = dim[1]

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

x = np.array(x)
count = 0
for i in range(N):
	for j in range(N-i-1):
		if(np.linalg.norm(x[i]-x[i+j+1]).is_integer()==True):
			count += 1

print(count)

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

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

i = 0
j = N - 1
while i < N - 1:
    a = points[i]
    b = points[j]
    total = 0
    for d in range(D):
        total += (a[d] - b[d]) ** 2
    res = math.sqrt(total)
    if res.is_integer(): ans += 1
    j -= 1
    if i == j:
        i += 1
        j = N - 1

print(ans)

Solution (Python):
import math
def check(n):
    if isinstance(n,int):
        return True
    if isinstance(n,float):
        return n.is_integer()
    return False

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

count=0
dis=0
for i in range(n-1):
    for j in range(i+1,n): 
        for k in range(d): 
            
            dis+=abs(info[i][k]-info[j][k])**2
            
        
        dis2=math.sqrt(dis)
        
        if check(dis2)==True:
            count+=1
        dis=0 
    dis=0 
    
print(count)

Solution (Python):
from math import sqrt
N,D = map(int,input().split())
X = [[int(i) for i in input().split()] for j in range(N)]
count = 0

for i in range(N-1):
  for j in range(i+1,N):
    tmp = sqrt(sum([(a-b)**2 for a,b in zip(X[i],X[j])]))
    if tmp == int(tmp):
      count += 1
      
print(count)

Solution (Python):


import math as m

ls = input().split(" ")
n = int(ls[0])
d = int(ls[1])
Xs = []
ans = 0

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

for i in range(n - 1):
	for j in range(i + 1, n):
		if m.sqrt(sum([(a - b)**2 for a, b in zip(Xs[i], Xs[j])])).is_integer():
			ans += 1

print(ans)

Solution (Python):
import numpy as np
import math
N, D = map(int, input().split())
 
n = [list(map(int, input().split())) for i in range(N)]
n = np.array(n)
ans = 0
for j in range(n.shape[0]):
  for i in range(n.shape[0]):
    length = np.linalg.norm(n[i]-n[j])
    aaa = math.modf(length)[0]
    if aaa < 0.00001:
      ans +=1
ans = ans - n.shape[0]
ans = int(ans/2)
print(ans)

Solution (Python):
import math
import numpy as np

def distance(y, z, d):
    y = np.array(y)
    z = np.array(z)
    delta2 = (y-z)**2
    return math.sqrt(sum(delta2))

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

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

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

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

count = 0
for i in range(n-1):
  for j in range(i+1, n):
    distance = sum([(y-z) * (y-z) for y, z in zip(x[i], x[j])])
    if isqrt(distance) ** 2 == distance:
      count += 1
print(count)

Solution (Python):

import math


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

ans = 0
tmp_targ = 0

for k in range(n):
    list_x[k] = list(map(int, input().split()))



for l in range(n-1):
    for m in range(l+1,n):
        tmp_targ = 0
        for i1 in range(d):
            tmp_targ += (list_x[l][i1] - list_x[m][i1]) ** 2
        
        if isinstance(math.sqrt(tmp_targ), int) or math.sqrt(tmp_targ).is_integer():
            ans += 1

print(ans)

Solution (Python):
import math

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

for i in range(n):
    for j in range(n):

        if i != j:
            countwa = 0
            for k in range(d):
                countwa += abs(a[i][k] - a[j][k]) ** 2
            if float(math.sqrt(countwa)).is_integer():
                cnt += 1
print(cnt//2)

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

counter = 0
for i in range(N):
    for j in range(N-i-1):
        dsquare = 0
        for k in range(D):
            dsquare += (X[i][k] - X[i+j+1][k])**2
        n = 1
        while (n**2 <= dsquare):
            if (dsquare == n**2):
                counter += 1
                break
            else:
                n += 1
print(counter)

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

Solution (Python):
import math
n,d=map(int,input().split())
x=[list(map(int,input().split())) for _ in range(n)]
a=0
for i in range(n):
	for j in range(i+1,n):
		a += math.modf(math.sqrt(sum([abs(x[i][k] - x[j][k])**2 for k in range(d)])))[0] < 1e-9
print(a)

Solution (Python):
import math

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


elem = inputs()
N = elem[0]
D = elem[1]

points = []
for i in range(N):
    points.append(inputs())

anscount = 0
for i_pt in points:
    for j_pt in points:
        if i_pt == j_pt:
            break
        sumup = 0
        for k in range(D):
            sumup += abs(i_pt[k] - j_pt[k]) ** 2
        if(math.sqrt(sumup) % 1 == 0):
            anscount +=1

print(anscount)

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

count = 0
for i in range(len(x) - 1):
  for j in range(i + 1, len(x)):
    u = x[i] - x[j]
    if np.linalg.norm(u).is_integer():
      count += 1
print(count)

Solution (Python):
import math

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

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

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

print(ans)

Solution (Python):
import numpy as np
def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()

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

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

count = 0
for i in range(n-1):
    a=np.array(x[i])
    for j in range(i,n):
        if(i==j):
            continue
        b=np.array(x[j])
        l = np.linalg.norm(a-b)
        
        if(is_integer(l)):
            count += 1

print(count)

Solution (Python):
import numpy as np

n, d = list(map(int, input().split()))
xa = [np.array(list(map(int, input().split()))) for _ in range(n)]
s = 0
for i in range(n-1) :
    for j in range(i+1, n) :
        if np.linalg.norm(xa[i]-xa[j])%1 == 0.0:
            s += 1
print(s)

Solution (Python):
import numpy as np
N, D = (int(i) for i in input().split())
X = [[int(i) for i in input().split()] for i in range(N)]
a = np.zeros(D)
b = 0
count = 0
for l in range(N):
  for k in range(N):
    for i in range(D):
      a[i] = (X[l][i]-X[k][i])**2
      b = np.sqrt(sum(a))
    if b != 0 and b - int(b) == 0:
      count += 1
print(count//2)

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

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

count = 0
for i in range(N):
    t = N - i - 1
    
    for j in range(t):
        vec = np.sqrt(np.power(x[t] - x[j], 2).sum())
        count = count + 1 if vec % 1.0 == 0.0 else count

print(count)

Solution (Python):



N,D = map(int,input().split())
lst = [list(map(int,input().split())) for i in range(N)]
count = 0
for j in range(N-1):
    for i in range(j+1,N):
        a = 0
        for d in range(D):
           
            a+= (abs(lst[j][d] - lst[i][d]))**2
        if (a**0.5 % 1 == 0):
            count+=1
        
print(count)

Solution (Python):
import numpy as np

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

def norm(y,z,D):
    nrm = 0.0
    for i in range(D):
        nrm = nrm + (y[i] - z[i])*(y[i] - z[i])
    return np.sqrt(nrm)

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

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

Solution (Python):
import itertools

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

"""
itertools.product(range(a+1), range(b+1), range(c+1))
"""

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

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


if __name__ == "__main__":
    main()