import math

import numpy as np



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



x = np.zeros([n, d])



for i in range(n):

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

    for j in range(d):

        x[i, j] = line[j]



cnt = 0



for i in range(n):

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

        xx = (x[i] - x[j]) ** 2

        dist = math.sqrt(xx.sum())

        if dist % 1 == 0:

            cnt += 1



print(cnt)
import math



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



x = [list(map(int, input().split())) for i in range(n)]



cnt = 0



for i in range(n):

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

        dist = 0

        for k in range(d):

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

        if math.sqrt(dist).is_integer():

            cnt += 1



print(cnt)
import math
import numpy as np

n, d = list(map(int, input().split()))
x = np.zeros([n, d])
for i in range(n):
    line = list(map(int, input().split()))
    for j in range(d):
        x[i, j] = line[j]
cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        xx = (x[i] - x[j]) ** 2
        dist = math.sqrt(xx.sum())
        if dist % 1 == 0:
            cnt += 1
print(cnt)

import math

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

-import numpy as np -x = np.zeros([n, d]) -for i in range(n): -    line = list(map(int, input().split())) -    for j in range(d): -        x[i, j] = line[j] +x = [list(map(int, input().split())) for i in range(n)] -        xx = (x[i] - x[j]) ** 2 -        dist = math.sqrt(xx.sum()) -        if dist % 1 == 0: +        dist = 0 +        for k in range(d): +            dist += (x[i][k] - x[j][k]) ** 2 +        if math.sqrt(dist).is_integer():