import numpy as np

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

X = np.zeros((N,D))

for i in range(N):

  X[i][:] = list(map(int, input().split()))



n = 0

for i in range(N):

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

    dist = np.linalg.norm(X[i]-X[j])

    if dist.is_integer():

      n += 1



print(n)
import numpy as np



_N, _D, *_X = open(0).read().split()

N = int(_N)

D = int(_D)

X = np.array(list(zip(*[list(map(int, iter(_X)))]*D)))



import itertools



ans = 0



for x, y in itertools.combinations(X, 2):

    d = np.linalg.norm(x - y)



    if d%1 == 0:

        ans += 1



print(ans)
import numpy as np

N, D = list(map(int, input().split()))
X = np.zeros((N, D))
for i in range(N):
    X[i][:] = list(map(int, input().split()))
n = 0
for i in range(N):
    for j in range(i + 1, N):
        dist = np.linalg.norm(X[i] - X[j])
        if dist.is_integer():
            n += 1
print(n)

import numpy as np

_N, _D, *_X = open(0).read().split()
N = int(_N)
D = int(_D)
X = np.array(list(zip(*[list(map(int, iter(_X)))] * D)))
import itertools

ans = 0
for x, y in itertools.combinations(X, 2):
    d = np.linalg.norm(x - y)
    if d % 1 == 0:
        ans += 1
print(ans)

-N, D = list(map(int, input().split())) -X = np.zeros((N, D)) -for i in range(N): -    X[i][:] = list(map(int, input().split())) -n = 0 -for i in range(N): -    for j in range(i + 1, N): -        dist = np.linalg.norm(X[i] - X[j]) -        if dist.is_integer(): -            n += 1 -print(n) +_N, _D, *_X = open(0).read().split() +N = int(_N) +D = int(_D) +X = np.array(list(zip(*[list(map(int, iter(_X)))] * D))) +import itertools + +ans = 0 +for x, y in itertools.combinations(X, 2): +    d = np.linalg.norm(x - y) +    if d % 1 == 0: +        ans += 1 +print(ans)