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(i**2 == s for i in range(1000)):

            ans += 1



print(ans)

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



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

S = {i**2 for i in range(1000)}

ans = sum(

    a != b and sum((x - y)**2 for x, y in zip(a, b)) in S

    for a in X

    for b in X

) // 2



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(i**2 == s for i in range(1000)):
            ans += 1
print(ans)

N, D = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
S = {i**2 for i in range(1000)}
ans = (
    sum(a != b and sum((x - y) ** 2 for x, y in zip(a, b)) in S for a in X for b in X)
    // 2
)
print(ans)

-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(i**2 == s for i in range(1000)): -            ans += 1 +X = [list(map(int, input().split())) for _ in range(N)] +S = {i**2 for i in range(1000)} +ans = ( +    sum(a != b and sum((x - y) ** 2 for x, y in zip(a, b)) in S for a in X for b in X) +    // 2 +)