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



X = []

ans = 0

for i in range(N):

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



    for j in range(i):

        dis = 0

        for k in range(D):

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

            if k == D-1:

                if (dis) ** (1/2) - int((dis) ** (1/2)) == 0:

                    ans += 1



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

X = []

for i in range(N):

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



ans = 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**(1/2)

        if int(d) == d:

            ans +=1



print(ans)    
N, D = list(map(int, input().split()))
X = []
ans = 0
for i in range(N):
    X.append(list(map(int, input().split())))
    for j in range(i):
        dis = 0
        for k in range(D):
            dis += (X[i][k] - X[j][k]) ** 2
            if k == D - 1:
                if (dis) ** (1 / 2) - int((dis) ** (1 / 2)) == 0:
                    ans += 1
print(ans)

N, D = list(map(int, input().split()))
X = []
for i in range(N):
    X.append(list(map(int, input().split())))
ans = 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 ** (1 / 2)
        if int(d) == d:
            ans += 1
print(ans)

+for i in range(N): +    X.append(list(map(int, input().split()))) -    X.append(list(map(int, input().split()))) -    for j in range(i): -        dis = 0 +    for j in range(i + 1, N): +        d = 0 -            dis += (X[i][k] - X[j][k]) ** 2 -            if k == D - 1: -                if (dis) ** (1 / 2) - int((dis) ** (1 / 2)) == 0: -                    ans += 1 +            d += (X[i][k] - X[j][k]) ** 2 +        d = d ** (1 / 2) +        if int(d) == d: +            ans += 1