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-----
3 2
1 2
5 5
-2 8

-----Sample Output-----
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.

Difficulty: introductory

Starter code:

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

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

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

print(cnt)


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

print(result)

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

cnt = 0
for i in list(itertools.combinations(X, 2)):
    ans = 0
    for j in range(D):
        ans += abs((i[0][j] - i[1][j])**2)
    if math.sqrt(ans).is_integer():
        cnt += 1
print(cnt)

import math
N,D=list(map(int,input().split()))
sq=[list(map(int,input().split())) for i in range(N)]
ans=0
for j in range(N-1):
    for k in range(j+1,N):
        s=0
        for l in range(D):
            s+=(sq[j][l]-sq[k][l])**2
        if math.sqrt(s)%1==0.0:
            ans+=1
print(ans)


import math


def calc_distance(Y, Z):
    temp = 0
    for y, z in zip(Y, Z):
        temp += (y-z)**2
    return temp


def is_integer(num):
    for k in range(1, num+1):
        if k*k == num:
            return True
    else:
        return False


N, D = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
for i in range(len(X)-1):
    for j in range(i, len(X)):
        distance = calc_distance(X[i], X[j])
        if is_integer(distance):
            cnt += 1
print(cnt)


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


n,d=list(map(int,input().split()))
x=[]
for i in range(n):
    p=list(map(int,input().split()))
    x.append(p)
ans=0
for i in range(len(x)-1):
    for j in range(i+1,len(x)):
        dis=0
        for k in range(d):
            dis+=(x[i][k]-x[j][k])**2
        if int(dis**(1/2))==dis**(1/2):
            ans+=1
print(ans)


import math
from scipy.special import comb
N,D=map(int,input().split())
List=[]

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

ans=0
for i in range(N-1):
    y=List[i]

    for j in range(i+1,N):
        z=List[j]
        sum=0
        for j in range(D):
            sum+=abs(y[j]-z[j])**2
            s=math.sqrt(sum)
            
        if s.is_integer():
            ans+=1
                
print(ans)

def main():
    n, d = map(int, input().split())
    ps = [[*map(int, input().split())] for _ in range(n)]
    square = [i**2 for i in range(1, 127)]
    cnt = 0
    for i in range(n-1):
        for j in range(i+1, n):
            if sum([(ps[i][k] - ps[j][k]) ** 2 for k in range(d)]) in square:
                cnt += 1
    print(cnt)

def __starting_point():
    main()
__starting_point()

#
# abc133 b
#
import sys
from io import StringIO
import unittest
from math import sqrt


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 2
1 2
5 5
-2 8"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3 4
-3 7 8 2
-12 1 10 2
-2 8 9 3"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """5 1
1
2
3
4
5"""
        output = """10"""
        self.assertIO(input, output)


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

    ans = 0
    for i, x1 in enumerate(X):
        for x2 in X[i+1:]:
            tmp = 0
            for j in range(D):
                tmp += (x2[j]-x1[j])**2
            tmp = sqrt(tmp)
            if tmp.is_integer() == True:
                ans += 1

    print(ans)


def __starting_point():
    # unittest.main()
    resolve()

__starting_point()

import math


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

    for i, xi in enumerate(Xs):
        for xj in Xs[i+1:]:
            dis = 0
            for di in range(d):
                dis += (xi[di] - xj[di])**2

            if math.sqrt(dis) % 1 == 0:
                ans += 1

    print(ans)


def __starting_point():
    main()

__starting_point()

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

print(ans)    

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

for i in range(n-1):
    for j in range(i+1,n):
        sum = 0
        for x in range(d):
            sum += abs(li[i][x]-li[j][x])**2
        
        if math.sqrt(sum) % 1 == 0.0:
            cnt += 1

print(cnt)


from typing import List
from math import sqrt


def distance(x1: List[int], x2: List[int]) -> float:
    total = 0
    for a, b in zip(x1, x2):
        total += (a - b) ** 2
    return sqrt(total)


nd = list(map(int, input().split()))
n, d = nd[0], nd[1]
xs = [list(map(int, input().split())) for _ in range(n)]
size = len(xs)
result = 0

for i in range(size):
    for j in range(i + 1, size):
        if distance(xs[i], xs[j]).is_integer():
            result += 1

print(result)


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

X = [[0]*d for _ in range(n)]

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

cnt = 0

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


import numpy as np
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):
        if np.linalg.norm(np.array(X[i])-np.array(X[j])).is_integer():
            cnt += 1
print(cnt)

from itertools import combinations

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

cmb = combinations([i for i in range(n)],2)
cnt = 0
for i,j in cmb:
    dist = sum([(x[i][k] - x[j][k])**2 for k in range(d)])
    for m in range(int(dist**0.5)+1):
        if m**2 == dist:
            cnt += 1
print(cnt)

n,d=map(int,input().split())
point=[]
for _ in range(n):
    point.append(list(map(int,input().split())))
ans=0
for i in range(n-1):
    for l in range(i,n):
        if i==l:
            continue
        dis=0
        for f in range(d):
            dis+=(point[i][f]-point[l][f])**2
        dis=dis**(0.5)
        #print(dis)
        if dis.is_integer():
            ans+=1
print(ans)

n ,d = list(map(int, input().split()))
t = []
ans = 0

for i in range(n):
  c = list(map(int,input().split()))
  t.append(c)
  
for k in range(0, n-1):
  for j in range(k+1, n):
    sumsum = 0 
    for l in range(d):
      sumsum += (t[k][l]-t[j][l])**2
    dis = sumsum**(1/2)
    
    if dis.is_integer() == True:
        ans += 1
print(ans)  


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

n,d = map(int,input().split())
data = [input().split() for i in range(n)]
ans = 0
for i in range(n - 1):
    for j in range(i+1 , n):
        sum = 0
        for k in range(d):
            sum += (int(data[i][k]) - int(data[j][k])) **2
        temp = sum ** 0.5
        if  temp.is_integer() == True:
            ans += 1
print(ans)

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

cnt = 0
for i in range(N-1):
  for j in range(N-i-1):
    jj = j+i+1
    dis = 0.0
    for k in range(D):
      dis += (X[i][k] - X[jj][k])**2
    dis = dis**0.5
    if dis.is_integer():
      cnt += 1

print(cnt)

import math
n, d = list(map(int,input().split()))
lst = []
for i in range(n):
    x = list(map(int,input().split()))
    lst.append(x)
def check (lst, a, b):
    tmp = 0
    for i in range(len(lst[a])):
        tmp = tmp + (lst[a][i] - lst[b][i])**2
    tmp = math.sqrt(tmp)
    if (tmp//1 == tmp):
        return (1)
    else:
        return (0)
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        ans = ans + check(lst, i, j)
print(ans)


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-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)==int(math.sqrt(tmp)):
            ans+=1
print(ans)

import math

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

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

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

count = 0
for i in range(N):
    ran = list(range(i+1,N))
    for j in ran:
        dis = 0
        for d in range(D):
            dis += (X[i][d] - X[j][d]) *  (X[i][d] - X[j][d])
        
        dis = math.sqrt(dis)
        if dis.is_integer() == True:
            count += 1

print(count)


n,d=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
t=0
for i in range(n):
  for j in range(i+1,n):
    s=0
    for b,c in zip(a[i],a[j]):
      s+=(b-c)**2
    if s**0.5==int(s**0.5):
      t+=1

print(t)

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):
    dis = 0
    for d in range(D):
      dis += (X[i][d] - X[j][d])**2
    dis = math.sqrt(dis)
    ans += dis.is_integer()

print(ans)

import math

N,D=map(int,input().split())
Dis=[]
for i in range(N):
    A=list(map(int,input().split()))
    Dis.append(A)
ans=0
plus=0
for m in range(N-1):
    for k in range(N-1):
        for j in range(D):
            B=Dis[m][j]-Dis[m+k+1][j]
            B=B**2
            plus+=B
        plus=math.sqrt(plus)
        if round(plus)==plus:
            ans+=1
        plus=0
        if m+k+1==N-1:
            break
print(ans)

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

    return ans

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

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

print(count)

import numpy as np
from itertools import combinations
import math

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

res = 0
for x, y in combinations(X, 2):
    if((sum((np.array(x)-np.array(y))**2)**0.5).is_integer()):
        res += 1
print(res)


N,D=list(map(int,input().split()))
X=[list(map(int,input().split())) for _ in range(N)]
ans=0
for i in range(N):
    for j in range(i+1,N):
        d=0
        for k in range(D):
            d+=(X[i][k]-X[j][k])**2
        for l in range(1000):
            if l**2==d:
                ans+=1
                break
print(ans)


import numpy as np
from scipy.special import comb
n,d=map(int,input().split())
x=[]
total=0
for i in range(n):
    x.append(list(map(int,input().split())))
for i in range(n):
    for j in range(n):
        if i!=j:
            a=np.array(x[i])
            b=np.array(x[j])
            u=b-a
            if np.linalg.norm(u)==int(np.linalg.norm(u)):
                total+=1
print(int(total/2))

import itertools

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

combi=list(itertools.combinations([i for i in range(N)],2 ))

ans=0

for c in combi:
	temp=0
	for d in range(D):
		temp+=(X[c[0]][d]-X[c[1]][d])**2
	temp=temp**.5
	if float.is_integer(temp):ans+=1

print(ans)

n,d = map(int,input().split())
lists = []
for i in range(n):
    lis = list(map(int,input().split()))
    lists.append(lis)
cnt = 0
for i in range(0,n-1):
    for j in range(i+1,n):
        ans = 0
        for k in range(d):
            x = (lists[i][k]-lists[j][k])**2
            ans += x
        ans = ans**(1/2)
        y = ans.is_integer()
        if y == True:
            cnt += 1
print(cnt)

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

Xarray = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        sum = 0
        for k in range(D):
            sum += abs(Xarray[i][k] - Xarray[j][k]) ** 2
        
        if math.sqrt(sum).is_integer():
            ans += 1

print(ans)

import math
n,d=list(map(int,input().split()))
x = []
for _ in range(n):
    l = list(map(int, input().split()))
    x.append(l)
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) == int(math.sqrt(tmp)):
            cnt += 1
print(cnt)


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

def check(i, j):
    dis = 0
    for k in range(D):
        dis += (X[i][k] - X[j][k])**2
    
    if int(math.sqrt(dis))**2 == dis:
        return 1
    else:
        return 0

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


import math
n,d = map(int,input().split(" "))
clist = []

for i in range(n):
    xlist = list(map(int,input().split(" ")))
    clist.append(xlist)

def dis(ylist,zlist):
    distance = 0
    for i in range(d):
        distance += (ylist[i] - zlist[i]) ** 2
    sqdis = math.sqrt(distance)
    return(sqdis)

countdis = 0

for i in range(n-1):
    for j in range(i+1,n):
        if dis(clist[i],clist[j]) % 1 == 0:
            countdis += 1

print(countdis)

import itertools
import math

n,d = map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]
q = list(itertools.combinations(range(n),2))
cnt = 0
for i in range(len(q)):
    ans = 0
    for j in range(d):
        ans += (x[q[i][0]][j] - x[q[i][1]][j])**2
    ans = math.sqrt(ans)
    if ans == int(ans):
        cnt += 1

print(cnt)

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

from itertools import combinations
import numpy as np
xnumpy = np.array(xlist)
ans = 0
for y, z in combinations(xnumpy, 2):
    distance = ((y -z)**2).sum()
    for i in range((40**2)*10):
        if distance == i*i:
            ans += 1
print(ans)        

from math import sqrt

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

XS = [list(int(i) for i in input().split()) for _ in range(N)]

cnt = 0
for i in range(N):
  for j in range(i+1, N):
    if sqrt(sum((y - z) ** 2 for y, z in zip(XS[i], XS[j]))).is_integer():
      cnt += 1
      
print(cnt)


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

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


def distance(xx,d,i,j):
    ans = 0
    for u in range(d):
        ans+=((xx[i][u]-xx[j][u])**2)
    if math.sqrt(ans).is_integer():
         return 1
    else :
        return 0
    
count =0
for i in range(n):
    for j in range(i+1,n):
        count += distance(xx,d,i,j)
print (count)


import math
n, d = list(map(int, input().split()))
x = []

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

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


from itertools import combinations
n,d = map(int,input().split())
L = list(list(map(int,input().split())) for _ in range(n))
C = list(combinations(L,2))
ans = 0
for i in range(len(C)):
  total = 0
  for a,b in zip(C[i][0],C[i][1]):
    total += abs(a - b)**2
  
  if (total**0.5)%1 == 0:
    ans += 1
print(ans)

def dist(ar1, ar2):
    s = 0
    for i in range(len(ar1)):
        s += (ar1[i] - ar2[i]) ** 2
    return (s ** .5).is_integer()

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

for i in range(len(arr)):
    for j in range(i + 1, len(arr)):
        if dist(arr[i], arr[j]):
            ans += 1
print(ans)

n, d = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
t = 0
for i in range(n):
  for j in range(i+1, n):
    s = 0
    for b, c in zip(a[i], a[j]):
      s += (b - c) ** 2
    if s ** 0.5 == int(s ** 0.5):
      t += 1
print(t)

import math

N,D = list(map(int,input().split()))
L = []
ans = 0 
for _ in range(N):
  X = list(map(int,input().split()))
  L.append(X)
for i in range(N - 1):
  for j in range(i + 1,N):
    con = 0
    for k in range(D):
      con += (L[i][k] - L[j][k]) ** 2
    if  int(math.sqrt(con)) ** 2 == con:
      ans += 1

print(ans)


import itertools 
N, D = map(int, input().split())
count = 0
lst = []
for n in range(N):
    X = list(map(int, input().split()))
    lst.append(X)
c = list(itertools.combinations(lst, 2))

lst2 = []
for a in c:
    d2 = 0
    for x, y in zip(a[0], a[1]):
        s = (x - y) ** 2
        d2 += s
    d = d2 ** 0.5
    if d.is_integer():
        lst2.append(d)
print(len(lst2))

n,d =map(int,input().split())
l= [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n):
    for j in range(i+1,n):
        a = 0
        for k in range(d):
            a += (l[i][k] - l[j][k])**2
        a **=0.5
        if a.is_integer():
            ans +=1
print(ans)

import math

N, D = map(int, input().split())
coordinates = []
ans = 0
for _ in range(N):
  X = list(map(int, input().split()))
  coordinates.append(X)
for i in range(N):
  for j in range(i+1, N):
    dist = 0
    for k in range(D):
      dist += (coordinates[i][k] - coordinates[j][k])**2
    dist = math.sqrt(dist)
    if dist == dist//1:
      ans += 1
print(ans)

import itertools

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

combinations = list(itertools.combinations(points, 2))
dist_lists = []
ans = 0
for comb in combinations:
  A = comb[0]
  B = comb[1]

  tmp = 0
  for j in range(len(A)):
    tmp += (B[j] - A[j])**2
  
  distance = tmp**(0.5)

  if distance.is_integer():
    ans += 1
print(ans)

import math

def colcu (bli,ali,D):
    num = 0
    for i in range(D):
        num += (bli[i] - ali[i]) ** 2
    return math.sqrt(num)

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

an = 0
for i in range(N-1):
 for t in range(i+1,N):
     if colcu(pli[i],pli[t],D).is_integer():
         an += 1
print(an)

n, d = map(int,input().split())
pos = [list(map(int,input().split())) for _ in range(n)]
count = 0
for i in range(n):
    for j in range(i+1,n):
        sumpos = 0
        for k in range(d):
            sumpos += (pos[i][k] - pos[j][k]) ** 2
        for l in range(sumpos + 1):
            if l ** 2 == sumpos:
                count += 1
print(count)

# numpyを使わない解法
import math
n, d = (int(i) for i in input().split())
list_x = [[int(i) for i in input().split()] for j in range(0, n)]
count = 0
tmp = 0
for i in range(0, n):
    for j in range(i + 1, n):
        for k in range(0, d):
            tmp += pow(list_x[i][k] - list_x[j][k], 2)
        tmp = math.sqrt(tmp)
        if tmp.is_integer(): count += 1
        tmp = 0
print(count)

#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline
import itertools
import math
import numpy as np

def main():
    numbers=[]
    #n = int(input())
    n,m = map(int,input().split())
    #numbers=list(map(int,input().split()))
    numbers=np.array([list(map(int,input().split())) for _ in range(n)])
    ans=0
    length=0
    count=0

    for idx,pair in enumerate(itertools.combinations(numbers,2)):
        tmp_A=np.array(pair[0])
        tmp_B=np.array(pair[1])
        length=(tmp_A-tmp_B)**2
        ans=math.sqrt(sum(length))
        if ans.is_integer()==True:
            count+=1
        else:
            continue
    print(count)



def __starting_point():
    main()  
__starting_point()

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

import numpy as np
import math
n, d = map(int,input().split())
x_l = [ np.array(list(map(int, input().split()))) for _ in range(n)  ]

ans = 0
p = set()
for i,x in enumerate(x_l):
    for j,y in enumerate(x_l):
        if i != j:
            if str(min([i,j]))+'_'+str(max([i,j])) not in p:
                d = math.sqrt(sum((x-y)**2))
                if d.is_integer():
                    ans += 1
                    p.add(str(min([i,j]))+'_'+str(max([i,j])))
print(ans)

def LI(): return list(map(int, input().split()))
def I(): return map(int, input().split())
mod = 10**9 + 7

def main():
  n, d = map(int, input().split())
  x = [LI() for i in range(n)]
  ans = 0
  for i in range(n-1):
    for j in range(i+1, n):
      sm = 0
      for k in range(d):
        sm += (x[i][k] - x[j][k]) ** 2
      if sm ** 0.5 % 1 == 0:
        ans += 1
  print(ans)
  

def __starting_point():
  main()
__starting_point()

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

cnt = 0
for comb in itertools.combinations(N_List,2):
    ans = 0
    for k in range(D):
        ans += (ND_List[comb[0]][k] - ND_List[comb[1]][k])**2
    ans =ans**0.5
    if ans.is_integer():
        cnt += 1
print(cnt)

from numpy import array
from numpy.linalg import norm
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):
    if norm(array(X[i])-array(X[j])).is_integer():
      ans += 1
print(ans)

import math
import itertools

N, D = list(map(int, input().split()))
cnt = 0
L = []

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

for i in itertools.combinations(L,2):
    y, z, dis = i[0], i[1], 0
    for a, b in zip(y, z):
        dis += (a-b)**2
    if math.sqrt(dis) == int(math.sqrt(dis)):
        cnt += 1

print(cnt)


n, d = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = 0
for i in range(n):
    for j in range(i + 1, n):
        s = 0
        for c, e in zip(a[i], a[j]):
            s += (c - e) ** 2
        if s ** 0.5 == int(s ** 0.5):
            b += 1
print(b)

from math import floor, sqrt
n,d=map(int,input().split())
X = []
def f(i,j):
    sm = 0
    for k in range(d):
        sm += (X[i][k]-X[j][k])**2
    return floor(sqrt(sm))**2 == sm
for _ in range(n):
    X.append(list(map(int,input().split())))
ans = 0
for i in range(n):
    for j in range(i+1,n):
        if f(i,j):
            ans += 1
print(ans)

N,D = (int(x) for x in input().split())
X = [None]*N
for i in range(N):
  X[i] = [float(x) for x in input().split()]
count = 0
for i in range(N-1):
  for j in range(i+1,N):
    sq = [(X[i][k]-X[j][k])**2 for k in range(D)]
    dist = sum(sq)**0.5
    if dist == int(dist):
      count += 1
print(count)

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

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

print(cnt)

import numpy as np
from itertools import combinations
import math

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

res = 0
for x, y in combinations(X, 2):
    distance = 0
    for i in range(D):
        distance += (x[i] - y[i])**2
    distance = math.sqrt(distance)
    if(distance.is_integer()):
        res += 1

print(res)


n,d = map(int,input().split())
lists = []
for i in range(n):
    lis = list(map(int,input().split()))
    lists.append(lis)
cnt = 0
for i in range(0,n-1):
    for j in range(i+1,n):
        ans = 0
        for k in range(d):
            x = (lists[i][k]-lists[j][k])**2
            ans += x
        ans = ans**(1/2)
    
        if ans % 1 == 0:
            cnt += 1
print(cnt)

n,d=list(map(int,input().split()))
x=[0]*n
for i in range(n):
  x[i]=list(map(int,input().split()))
  
def f(i):
  return (i**0.5-int(i**0.5))==0.0
  
ans=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
    ans+=1 if f(dist) else 0
print(ans)


import math
n,d = list(map(int, input().split()))
l = [list(map(int, input().split())) for l in range(n)]
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        x = 0
        for k in range(d):
            x += (l[i][k]-l[j][k])**2
        
        y = math.sqrt(x)
        a,b = math.modf(y)
        if a == 0:
            ans += 1
print(ans)



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

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

seisu_count = 0
for l in range(N):

    for r in range(l+1, N):
        total = 0
        for z in range(D):
            y_z = abs(X[l][z] - X[r][z])
            y_z_2 = y_z * y_z
            total += y_z_2
        
        sqr_total = math.sqrt(total)
        if sqr_total.is_integer():
            seisu_count += 1

print(seisu_count)

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

for i in range(N):
    for j in range(i+1,N):
        L = 0
        for k in range(D):
            L += (X[i][k] - X[j][k]) ** 2
        M = L ** 0.5
        if(M == int(M)):
            ans += 1

print(ans)

N,D=map(int,input().split())
X=[list(map(int,input().split())) for x in range(N)]
l=[]
for i in range(N):
    for j in range(i+1,N):
        s=0
        for k in range(D):
            s+=(X[i][k]-X[j][k])**2
        s=s**0.5
        if s-(s//1)==0:
            l.append(s)
print(len(l))

n,d = map(int,input().split())
import numpy as np
xlist = [list(map(int,input().split())) for i in range(n)]
xarray = np.array(xlist)
ans = 0
for i in range(n):
  for j in range(i+1,n):
    if np.linalg.norm(xarray[i]-xarray[j])==int(np.linalg.norm(xarray[i]-xarray[j])):
      ans+=1
print(ans)

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

import itertools
import numpy as np
N,D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]
count=0
for i in itertools.combinations(X,2):
  if np.linalg.norm(list(map(lambda x,y:abs(x-y),i[0],i[1])))%1==0:count+=1
print(count)

import numpy as np
from itertools import combinations
n,d=map(int,input().split())
l= [np.array(input().split() ,dtype=np.int64) for _ in range(n)]
ans=0
dist=0
for a,b in combinations(l,2):
    dist=((a-b)**2).sum()
    for j in range(dist+1):
        if  j**2 == dist:
            ans+=1
            continue
print(ans)

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

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

count = 0
d_2 = 0
d = 0

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

print("{}".format(count))

n,d = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(n)]
ans = 0
from math import sqrt
for i in range(n):
  for j in range(i+1,n):
    dis = 0
    for k in range(d):
      dis += (x[i][k]-x[j][k])**2
    if sqrt(dis) == int(sqrt(dis)):
      ans += 1
print(ans)

import math
n,d=map(int,input().split())
x=[[int(x) for x in input().split()]for _ in range(n)]
cnt=0
for i in range(n):
    for j in range(i+1,n):
        sum=0
        for a,b in zip(x[i],x[j]):
            sum+=(a-b)*(a-b)
        if math.sqrt(sum).is_integer():
            cnt+=1
print(cnt)

n, d = list(map(int, input().split()))
x = [[0 for j in range(d)]for i in range(n)]
for i in range(n):
    x[i] = list(map(int, input().split()))
ans = 0
for i in range(n):
    for j in range(i):
        dist = 0
        for k in range(d):
            dist += (x[i][k] - x[j][k]) ** 2
        dist = dist**(1/2)
        if dist - int(dist) == 0:
            ans += 1
print(ans)


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

def how_far(a,b):
  x = 0
  for s in range(0,d):
    x += (a[s] - b[s]) ** 2
  x = x ** (1/2)
  return x
count = 0
for i in range(n-1):
  for j in range(i+1,n):
    kyori = how_far(p[i],p[j])
    true_kyori = int(kyori)
    if kyori == true_kyori:
      count += 1
      
print(count)
      


import math

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

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

counter = 0
ary_len = len(ary)
for i in range(ary_len - 1):
    for j in range(i+1,ary_len):
        tmp = 0
        for k in range(D):
            tmp += pow(abs(ary[i][k]-ary[j][k]),2)
        if math.sqrt(tmp) % 1 == 0:
            counter += 1
print(counter)


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


import numpy as np

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

# Compute each distances
dis = [[0 for i in range(N)] for j in range(N)]
for i in range(N):
  for j in range(i+1, N):
    for k in range(D):
      dis[i][j] += (X[i][k]-X[j][k])**2 # OK!

# Check integer or not
dot = 0
for i in range(N):
  for j in range(i, N):
    dis[i][j] = np.sqrt(dis[i][j])
    if dis[i][j].is_integer() and dis[i][j] != 0:
      dot += 1

print(dot)

n,d = map(int,input().split())
import numpy as np
xlist = [list(map(int,input().split())) for i in range(n)]
xarray = np.array(xlist)
ans = 0
for i in range(n):
  for j in range(i+1,n):
    if np.linalg.norm(xarray[i]-xarray[j]).is_integer():
      ans+=1
print(ans)

import itertools

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

c = list(itertools.combinations(range(n), 2))
ans = 0
for a, b in c:
    dist = 0
    for j in range(d):
        dist += (x[a][j]-x[b][j])**2
    if dist**(1/2) % 1 == 0:
        ans += 1
print(ans)

n,d=list(map(int, input().rstrip().split()))
m=[]
for _ in range(n):
    arr=list(map(int, input().rstrip().split()))
    m.append(arr)
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        a = 0
        for k in range(d):
            a += (m[i][k] - m[j][k])**2
        x = int(a**(1/2))
        if x**2 == a:
            ans+=1
print(ans)


import math

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

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

count = 0
for i in range(n):
    for j in range(i + 1, n):
        norm = 0
        for k in range(d):
            diff = abs(X[i][k] - X[j][k])
            norm += diff * diff
        can = False
        for k in range(1, norm + 1):
            if(k * k == norm):
                can = True
        if(can):
            count += 1

print(count)


N,D=map(int, input().split())
X=[]
for i in range(N):
    X.append(list(map(int, input().split())))
count=0
for i in range(N):
    for j in range(N):
        if i >= j: continue
        d=0
        for k in range(D):
            d+=pow(abs(X[i][k]-X[j][k]),2)
        d=float(pow(d, 0.5))
        if d.is_integer(): count+=1
print(count)

def calc(D, a, b):
    d2 = 0
    for i in range(D):
        d2 += abs(a[i] - b[i])**2

    return d2**0.5

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

ans = 0

for i in range(N):
    for j in range(i+1, N):
        d = calc(D, lst[i], lst[j])
        if int(d) == d:
            ans += 1

print(ans)

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

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

# coding: utf-8
from math import sqrt

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

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

    print(ans)

def __starting_point():
    main()

__starting_point()

import math

def solve(y, z):
  res = 0
  for i in range(len(y)):
    res += (y[i]-z[i])**2
  return math.sqrt(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):
    dist = solve(x[i], x[j])
    if int(dist) == dist: ans += 1
print(ans)

import math

def calc(num, list1, list2):
  s = 0
  for i in range(num):
    s += (list1[i] - list2[i]) ** 2
  d = math.sqrt(s)
  return d

N, D = map(int, input().split())
L = []
ans = 0

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

for i in range(N):
  for j in range(i+1, N):
    c = calc(D, L[i], L[j])
    if c.is_integer():
      ans += 1

print(ans)