import numpy as np

import itertools



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

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



cnt = 0

for i1, i2 in itertools.product(list(range(n)), list(range(n))):

    if i1 == i2:

        continue

    x1 = np.array(x[i1])

    x2 = np.array(x[i2])

    d = sum(list([x ** 2 for x in list(x1 - x2)])) ** 0.5

    if d == int(d):

        cnt += 1



print((int(cnt / 2)))
n,d=list(map(int,input().split()))

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



cnt=0

for i in range(n-1):

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

  l1=l[i]

  l2=l[j]

  sum=0

  for y,z in zip(l1,l2):

   sum+=(y-z)**2

  dist=sum**0.5

  if dist==int(dist):

   cnt+=1

print(cnt)
import numpy as np
import itertools

n, d = list(map(int, input().split()))
x = [list(map(int, input().split())) for i in range(n)]
cnt = 0
for i1, i2 in itertools.product(list(range(n)), list(range(n))):
    if i1 == i2:
        continue
    x1 = np.array(x[i1])
    x2 = np.array(x[i2])
    d = sum(list([x**2 for x in list(x1 - x2)])) ** 0.5
    if d == int(d):
        cnt += 1
print((int(cnt / 2)))

n, d = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(n)]
cnt = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        l1 = l[i]
        l2 = l[j]
        sum = 0
        for y, z in zip(l1, l2):
            sum += (y - z) ** 2
        dist = sum**0.5
        if dist == int(dist):
            cnt += 1
print(cnt)

-import numpy as np -import itertools - -x = [list(map(int, input().split())) for i in range(n)] +l = [list(map(int, input().split())) for i in range(n)] -for i1, i2 in itertools.product(list(range(n)), list(range(n))): -    if i1 == i2: -        continue -    x1 = np.array(x[i1]) -    x2 = np.array(x[i2]) -    d = sum(list([x**2 for x in list(x1 - x2)])) ** 0.5 -    if d == int(d): -        cnt += 1 -print((int(cnt / 2))) +for i in range(n - 1): +    for j in range(i + 1, n): +        l1 = l[i] +        l2 = l[j] +        sum = 0 +        for y, z in zip(l1, l2): +            sum += (y - z) ** 2 +        dist = sum**0.5 +        if dist == int(dist): +            cnt += 1 +print(cnt)