import math



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

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

count = 0

tmp = []



for i in range(N):

    r1 = X[i]

    for j in range(N):

        t = str(i)+str(j)

        if i == j or t in tmp or str(j)+str(i) in tmp:

            continue



        r2 = X[j]

        ls = [(r1[j] - r2[j])**2 for j in range(D)]

        res = math.sqrt(sum(ls))



        if res % 1 == 0:

            count += 1

        tmp.append(t)



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):

    r1 = X[i]

    for j in range(N-1, -1, -1):

        if i == j:

            break

        r2 = X[j]

        ls = [(r1[j] - r2[j])**2 for j in range(D)]

        res = math.sqrt(sum(ls))

        if res % 1 == 0:

            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
tmp = []
for i in range(N):
    r1 = X[i]
    for j in range(N):
        t = str(i) + str(j)
        if i == j or t in tmp or str(j) + str(i) in tmp:
            continue
        r2 = X[j]
        ls = [(r1[j] - r2[j]) ** 2 for j in range(D)]
        res = math.sqrt(sum(ls))
        if res % 1 == 0:
            count += 1
        tmp.append(t)
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):
    r1 = X[i]
    for j in range(N - 1, -1, -1):
        if i == j:
            break
        r2 = X[j]
        ls = [(r1[j] - r2[j]) ** 2 for j in range(D)]
        res = math.sqrt(sum(ls))
        if res % 1 == 0:
            count += 1
print(count)

-tmp = [] -    for j in range(N): -        t = str(i) + str(j) -        if i == j or t in tmp or str(j) + str(i) in tmp: -            continue +    for j in range(N - 1, -1, -1): +        if i == j: +            break -        tmp.append(t)