import math



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

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



cnt = 0

for i in range(N):

    for j in range(i, N):

        tmp = 0

        if i == j:

            continue

        for k in range(D):

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

        if math.sqrt(tmp).is_integer():

            cnt += 1

        

print(cnt)
import math



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

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



cnt = 0

for i in range(N):

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

        tmp = 0

        for k in range(D):

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

        if math.sqrt(tmp).is_integer():

            cnt += 1

        

print(cnt)
import math

N, D = list(map(int, input().split()))
X = [list(map(int, input().split())) for i in range(N)]
cnt = 0
for i in range(N):
    for j in range(i, N):
        tmp = 0
        if i == j:
            continue
        for k in range(D):
            tmp += (X[i][k] - X[j][k]) ** 2
        if math.sqrt(tmp).is_integer():
            cnt += 1
print(cnt)

import math

N, D = list(map(int, input().split()))
X = [list(map(int, input().split())) for i in range(N)]
cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        tmp = 0
        for k in range(D):
            tmp += (X[i][k] - X[j][k]) ** 2
        if math.sqrt(tmp).is_integer():
            cnt += 1
print(cnt)

-    for j in range(i, N): +    for j in range(i + 1, N): -        if i == j: -            continue