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

X=[]

for _ in range(n):

    X.append(list(map(int,input().split())))



f=0

for i in range(n-1):

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

    l=0

    for a in range(d):

      l+=(X[i][a]-X[j][a])**2

    if int(l**(1/2))==l**(1/2):

        f+=1

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

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

f=0

for i in range(n-1):

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

    l=0

    for a in range(d):

      l+=(X[i][a]-X[j][a])**2

    if int(l**(1/2))==l**(1/2):

        f+=1

print(f)
n, d = list(map(int, input().split()))
X = []
for _ in range(n):
    X.append(list(map(int, input().split())))
f = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        l = 0
        for a in range(d):
            l += (X[i][a] - X[j][a]) ** 2
        if int(l ** (1 / 2)) == l ** (1 / 2):
            f += 1
print(f)

n, d = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(n)]
f = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        l = 0
        for a in range(d):
            l += (X[i][a] - X[j][a]) ** 2
        if int(l ** (1 / 2)) == l ** (1 / 2):
            f += 1
print(f)

-X = [] -for _ in range(n): -    X.append(list(map(int, input().split()))) +X = [list(map(int, input().split())) for _ in range(n)]