N, M = list(map(int, input().split()))

X = [tuple(map(int, input().split())) for _ in [0]*N]



cnt = 0

for i, x in enumerate(X):

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

        d = 0

        for y, z in zip(x, X[j]):

            d += (y-z)**2

        if (d**0.5).is_integer():

            cnt += 1



print(cnt)

N, D, *X = list(map(int, open(0).read().split()))

*X, = list(zip(*[iter(X)]*D))



cnt = 0

for i, x in enumerate(X):

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

        d = 0

        for y, z in zip(x, X[j]):

            d += (y-z)**2

        if (d**0.5).is_integer():

            cnt += 1



print(cnt)

N, M = list(map(int, input().split()))
X = [tuple(map(int, input().split())) for _ in [0] * N]
cnt = 0
for i, x in enumerate(X):
    for j in range(i + 1, N):
        d = 0
        for y, z in zip(x, X[j]):
            d += (y - z) ** 2
        if (d**0.5).is_integer():
            cnt += 1
print(cnt)

N, D, *X = list(map(int, open(0).read().split()))
(*X,) = list(zip(*[iter(X)] * D))
cnt = 0
for i, x in enumerate(X):
    for j in range(i + 1, N):
        d = 0
        for y, z in zip(x, X[j]):
            d += (y - z) ** 2
        if (d**0.5).is_integer():
            cnt += 1
print(cnt)

-N, M = list(map(int, input().split())) -X = [tuple(map(int, input().split())) for _ in [0] * N] +N, D, *X = list(map(int, open(0).read().split())) +(*X,) = list(zip(*[iter(X)] * D))