import numpy as np

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

v=[]

for i in range(n):

  v.append(np.array(list(map(int,input().split()))))

  

ans=0

for i in range(n-1):

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

    dist=np.linalg.norm(v[i]-v[j], ord = 2)

    if int(dist) == dist:

      ans += 1



print(ans)
n, d = list(map(int, input().split()))

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

ans = 0

for i in range(n):

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

    dist = 0

    for k in range(d):

      dist += (v[i][k]-v[j][k])**2

    dist = dist**(1/2)

    if dist.is_integer():

      ans += 1

print(ans)

import numpy as np

n, d = list(map(int, input().split()))
v = []
for i in range(n):
    v.append(np.array(list(map(int, input().split()))))
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        dist = np.linalg.norm(v[i] - v[j], ord=2)
        if int(dist) == dist:
            ans += 1
print(ans)

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

-import numpy as np - -v = [] +v = [list(map(int, input().split())) for i in range(n)] +ans = 0 -    v.append(np.array(list(map(int, input().split())))) -ans = 0 -for i in range(n - 1): -        dist = np.linalg.norm(v[i] - v[j], ord=2) -        if int(dist) == dist: +        dist = 0 +        for k in range(d): +            dist += (v[i][k] - v[j][k]) ** 2 +        dist = dist ** (1 / 2) +        if dist.is_integer():