import numpy

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

listx = []

count = 0

for i in range(N):

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

    listx.append(x)



for j in range(0, N):

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

        a = numpy.array(listx[j])

        b = numpy.array(listx[k])

        u = b - a

        c = float(numpy.linalg.norm(u))

        if c.is_integer() :

            count += 1

print(count)
def LI(): return list(map(int,input().split()))

N,D = LI()

X = [LI() for _ in range(N)]

ans = 0

for i in range(N):

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

        temp = 0

        for k in range(D):

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

        if temp **0.5%1==0:

            ans += 1

print(ans)
import numpy

N, D = list(map(int, input().split()))
listx = []
count = 0
for i in range(N):
    x = list(map(int, input().split()))
    listx.append(x)
for j in range(0, N):
    for k in range(j + 1, N):
        a = numpy.array(listx[j])
        b = numpy.array(listx[k])
        u = b - a
        c = float(numpy.linalg.norm(u))
        if c.is_integer():
            count += 1
print(count)

def LI():
    return list(map(int, input().split()))


N, D = LI()
X = [LI() for _ in range(N)]
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        temp = 0
        for k in range(D):
            temp += (X[j][k] - X[i][k]) ** 2
        if temp**0.5 % 1 == 0:
            ans += 1
print(ans)

-import numpy +def LI(): +    return list(map(int, input().split())) -N, D = list(map(int, input().split())) -listx = [] -count = 0 + +N, D = LI() +X = [LI() for _ in range(N)] +ans = 0 -    x = list(map(int, input().split())) -    listx.append(x) -for j in range(0, N): -    for k in range(j + 1, N): -        a = numpy.array(listx[j]) -        b = numpy.array(listx[k]) -        u = b - a -        c = float(numpy.linalg.norm(u)) -        if c.is_integer(): -            count += 1 -print(count) +    for j in range(i + 1, N): +        temp = 0 +        for k in range(D): +            temp += (X[j][k] - X[i][k]) ** 2 +        if temp**0.5 % 1 == 0: +            ans += 1 +print(ans)