import math



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

x = []

cnt = 0

sum = 0

for _ in range(n):

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

    x.append(tmp)



for i in range(n):

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

        sum = 0

        for k in range(d):

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

        distance = math.sqrt(sum)

        if distance.is_integer():

            cnt += 1



print(cnt)

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

x = []

cnt = 0

sum = 0

for _ in range(n):

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

    x.append(tmp)



for i in range(n):

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

        sum = 0

        for k in range(d):

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

        distance = sum ** 0.5

        if distance.is_integer():

            cnt += 1



print(cnt)

import math

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

n, d = list(map(int, input().split()))
x = []
cnt = 0
sum = 0
for _ in range(n):
    tmp = list(map(int, input().split()))
    x.append(tmp)
for i in range(n):
    for j in range(i + 1, n):
        sum = 0
        for k in range(d):
            sum += (x[i][k] - x[j][k]) ** 2
        distance = sum**0.5
        if distance.is_integer():
            cnt += 1
print(cnt)

-import math - -        distance = math.sqrt(sum) +        distance = sum**0.5