# coding: utf-8

import numpy as np

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

cnt = 0

X = []

for i in range(n):

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

    X.append(x[:])

X = np.array(X)

for i in range(n):

    X_tmp = X[:]

    X_tmp -= X[i]

    for i in range(n):

        x = X_tmp[i]

        x_sq = x**2

        x_sq = np.sqrt(sum(x_sq))

        if x_sq % 1 == 0:

            cnt += 1

print(((cnt-n)//2))
# 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
import numpy as np

n, d = list(map(int, input().split()))
cnt = 0
X = []
for i in range(n):
    x = list(map(int, input().split()))
    X.append(x[:])
X = np.array(X)
for i in range(n):
    X_tmp = X[:]
    X_tmp -= X[i]
    for i in range(n):
        x = X_tmp[i]
        x_sq = x**2
        x_sq = np.sqrt(sum(x_sq))
        if x_sq % 1 == 0:
            cnt += 1
print(((cnt - n) // 2))

# 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))

-import numpy as np - -n, d = list(map(int, input().split())) -cnt = 0 +N, D = list(map(int, input().split())) -for i in range(n): -    x = list(map(int, input().split())) -    X.append(x[:]) -X = np.array(X) -for i in range(n): -    X_tmp = X[:] -    X_tmp -= X[i] -    for i in range(n): -        x = X_tmp[i] -        x_sq = x**2 -        x_sq = np.sqrt(sum(x_sq)) -        if x_sq % 1 == 0: -            cnt += 1 -print(((cnt - n) // 2)) +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))