import numpy as np



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

X = []

for n in range(N):

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

#N個のリスト入力を受け取る



cnt = 0



for i in range(N):

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

        d = 0

        for k in range(D):

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

        d = d**0.5

        if d.is_integer() :

            cnt += 1



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

X = []

for n in range(N):

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

#N個のリスト入力を受け取る



cnt = 0



for i in range(N):

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

        d = 0

        for k in range(D):

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

        d = d**0.5

        if d.is_integer() :

            cnt += 1



print(cnt)
import numpy as np

N, D = list(map(int, input().split()))
X = []
for n in range(N):
    X.append(list(map(int, input().split())))
# N個のリスト入力を受け取る
cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        d = 0
        for k in range(D):
            d += (X[i][k] - X[j][k]) ** 2
        d = d**0.5
        if d.is_integer():
            cnt += 1
print(cnt)

N, D = list(map(int, input().split()))
X = []
for n in range(N):
    X.append(list(map(int, input().split())))
# N個のリスト入力を受け取る
cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        d = 0
        for k in range(D):
            d += (X[i][k] - X[j][k]) ** 2
        d = d**0.5
        if d.is_integer():
            cnt += 1
print(cnt)

-import numpy as np -