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

X = []

for _ in range(n):

    X.append([int(x) for x in input().split()])

ans = 0

for i in range(n - 1):

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

        s = sum((X[i][d] - X[j][d])**2 for d in range(d))

        if any(k**2 == s for k in range(1000)):

            ans += 1

print(ans)

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

X = []

for _ in range(n):

    X.append([int(x) for x in input().split()])

ans = 0

for i in range(n - 1):

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

    s = sum((X[i][d] - X[j][d])**2 for d in range(d))

    if (s ** .5).is_integer():

        ans += 1

print(ans)
n, d = list(map(int, input().split()))
X = []
for _ in range(n):
    X.append([int(x) for x in input().split()])
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        s = sum((X[i][d] - X[j][d]) ** 2 for d in range(d))
        if any(k**2 == s for k in range(1000)):
            ans += 1
print(ans)

n, d = list(map(int, input().split()))
X = []
for _ in range(n):
    X.append([int(x) for x in input().split()])
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        s = sum((X[i][d] - X[j][d]) ** 2 for d in range(d))
        if (s**0.5).is_integer():
            ans += 1
print(ans)

-        if any(k**2 == s for k in range(1000)): +        if (s**0.5).is_integer():