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

a =[[int(x) for x in input().split()] for i in range(n)]

cnt =0

sei = [i*i for i in range(10000)]



for i in range(n):

  for j in range(i):

    dis = sum( [((a[i][k] - a[j][k] )*(a[i][k] - a[j][k])) for k in range(d)])

    if dis in sei:

        cnt +=1

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

xd = [(list(int(_) for _ in input().split())) for i in range(n)]

ans =0

for i in range(n):

  x1 = xd[i]

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

    x2 = xd[j]

    dis =0

    for x,y in zip(x1,x2):

      dis += (y-x) **2

    k = dis **0.5



    if int(k)**2 ==dis:

      ans +=1

print(ans)
n, d = list(map(int, input().split()))
a = [[int(x) for x in input().split()] for i in range(n)]
cnt = 0
sei = [i * i for i in range(10000)]
for i in range(n):
    for j in range(i):
        dis = sum([((a[i][k] - a[j][k]) * (a[i][k] - a[j][k])) for k in range(d)])
        if dis in sei:
            cnt += 1
print(cnt)

n, d = list(map(int, input().split()))
xd = [(list(int(_) for _ in input().split())) for i in range(n)]
ans = 0
for i in range(n):
    x1 = xd[i]
    for j in range(i + 1, n):
        x2 = xd[j]
        dis = 0
        for x, y in zip(x1, x2):
            dis += (y - x) ** 2
        k = dis**0.5
        if int(k) ** 2 == dis:
            ans += 1
print(ans)

-a = [[int(x) for x in input().split()] for i in range(n)] -cnt = 0 -sei = [i * i for i in range(10000)] +xd = [(list(int(_) for _ in input().split())) for i in range(n)] +ans = 0 -    for j in range(i): -        dis = sum([((a[i][k] - a[j][k]) * (a[i][k] - a[j][k])) for k in range(d)]) -        if dis in sei: -            cnt += 1 -print(cnt) +    x1 = xd[i] +    for j in range(i + 1, n): +        x2 = xd[j] +        dis = 0 +        for x, y in zip(x1, x2): +            dis += (y - x) ** 2 +        k = dis**0.5 +        if int(k) ** 2 == dis: +            ans += 1 +print(ans)