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

x = [[int(i) for i in input().split()] for _ in range(n)]



ans = 0

for i in range(n):

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

        dd = 0

        for m in range(d):

            dd += (x[i][m] - x[j][m]) ** 2

        dd = dd**0.5

        if dd.is_integer():

            ans += 1



print(ans)

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

x = [[int(i) for i in input().split()] for _ in range(n)]



ans = 0

for i in range(n):

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

        dd = 0

        for m in range(d):

            dd += (x[i][m] - x[j][m]) ** 2

        dd = dd**0.5

        if dd % 1 ==0:

            ans += 1



print(ans)

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

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

-        if dd.is_integer(): +        if dd % 1 == 0: