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

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



ans = 0

for i in range(N):

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

    d = 0

    for k in range(D):

      d += pow(X[i][k] - X[j][k], 2)

    if pow(int(d ** 0.5), 2) == d:

      ans += 1



print(ans)
N, D = list(map(int, input().split()))

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



def nasu(x, y):

  t = 0

  for i in range(D):

    t += (X[x][i] - X[y][i]) ** 2

  t **= (1 / 2)

  if t == int(t):

    return 1

  else:

    return 0





ans = 0

for i in range(N - 1):

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

    ans += nasu(i, j)



print(ans)
N, D = list(map(int, input().split()))
X = [list(map(int, input().split())) for i in range(N)]
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        d = 0
        for k in range(D):
            d += pow(X[i][k] - X[j][k], 2)
        if pow(int(d**0.5), 2) == d:
            ans += 1
print(ans)

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


def nasu(x, y):
    t = 0
    for i in range(D):
        t += (X[x][i] - X[y][i]) ** 2
    t **= 1 / 2
    if t == int(t):
        return 1
    else:
        return 0


ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        ans += nasu(i, j)
print(ans)

-X = [list(map(int, input().split())) for i in range(N)] +X = [list(map(int, input().split())) for _ in range(N)] + + +def nasu(x, y): +    t = 0 +    for i in range(D): +        t += (X[x][i] - X[y][i]) ** 2 +    t **= 1 / 2 +    if t == int(t): +        return 1 +    else: +        return 0 + + -for i in range(N): +for i in range(N - 1): -        d = 0 -        for k in range(D): -            d += pow(X[i][k] - X[j][k], 2) -        if pow(int(d**0.5), 2) == d: -            ans += 1 +        ans += nasu(i, j)