n,d = list(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):

    s = 0

    for k in range(d):

      s += abs(x[i][k] - x[j][k])**2

    s = s**0.5

    if s.is_integer(): ans += 1

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

n, d = list(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)

-        s = 0 +        t = 0 -            s += abs(x[i][k] - x[j][k]) ** 2 -        s = s**0.5 -        if s.is_integer(): +            t += abs(x[i][k] - x[j][k]) ** 2 +        t **= 0.5 +        if t.is_integer():