# coding: utf-8

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

X = []

ans = 0

for i in range(N):

    X.append(list(map(int, input().split())))

for i in range(N):

    for j in range(N):

        dist = 0

        if i == j:

            continue

        for d in range(D):

            dist += ((X[i][d] - X[j][d])**2)

        if dist**0.5 == int(dist**0.5):

            ans += 1

print((ans//2))
# coding: utf-8

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

ans = 0

X = []

for i in range(N):

    x = list(map(int, input().split()))

    X.append(x[:])

for i in range(N - 1):

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

        tmp = 0

        for k in range(D):

            tmp += (X[i][k] - X[j][k]) ** 2

        if int(tmp ** 0.5) == tmp ** 0.5:

            ans += 1

print(ans)
# coding: utf-8
N, D = list(map(int, input().split()))
X = []
ans = 0
for i in range(N):
    X.append(list(map(int, input().split())))
for i in range(N):
    for j in range(N):
        dist = 0
        if i == j:
            continue
        for d in range(D):
            dist += (X[i][d] - X[j][d]) ** 2
        if dist**0.5 == int(dist**0.5):
            ans += 1
print((ans // 2))

# coding: utf-8
N, D = list(map(int, input().split()))
ans = 0
X = []
for i in range(N):
    x = list(map(int, input().split()))
    X.append(x[:])
for i in range(N - 1):
    for j in range(i + 1, N):
        tmp = 0
        for k in range(D):
            tmp += (X[i][k] - X[j][k]) ** 2
        if int(tmp**0.5) == tmp**0.5:
            ans += 1
print(ans)

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