import math

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

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



count = 0

a = 0

for i in range(N):

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

        for k in range(D):

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

        if math.sqrt(a) == int(math.sqrt(a)):

            count += 1

        a = 0



print(count)
import math

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

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



count=0

for i in range(n-1):

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

            c=0

            for k in range(d):

                  c+=(x[i][k]-x[j][k])**2

            if math.sqrt(c)==int(math.sqrt(c)):

                  count+=1

print(count)

import math

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

import math

n, d = list(map(int, input().split()))
x = [list(map(int, input().split())) for _ in range(n)]
count = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        c = 0
        for k in range(d):
            c += (x[i][k] - x[j][k]) ** 2
        if math.sqrt(c) == int(math.sqrt(c)):
            count += 1
print(count)

-N, D = list(map(int, input().split())) -X = [list(map(int, input().split())) for _ in range(N)] +n, d = list(map(int, input().split())) +x = [list(map(int, input().split())) for _ in range(n)] -a = 0 -for i in range(N): -    for j in range(i + 1, N): -        for k in range(D): -            a += (X[i][k] - X[j][k]) ** 2 -        if math.sqrt(a) == int(math.sqrt(a)): +for i in range(n - 1): +    for j in range(i + 1, n): +        c = 0 +        for k in range(d): +            c += (x[i][k] - x[j][k]) ** 2 +        if math.sqrt(c) == int(math.sqrt(c)): -        a = 0