from scipy.spatial import distance





def solve(string):

    n, d, *x = list(map(int, string.split()))

    x = [tuple(c) for c in zip(*[iter(x)] * d)]

    dist = distance.cdist(x, x)

    return str(((dist == dist.astype("int32")).sum() - n) // 2)





if __name__ == '__main__':

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

    print((solve('{} {}\n'.format(n, m)+'\n'.join([eval(input()) for _ in range(n)]))))

import math

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

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

counter = 0

for i, x0 in enumerate(X): 

    for x1 in X[i+1:]:

        if math.sqrt(sum([(a-b)**2 for a, b in zip(x0,x1)])).is_integer():

            counter+=1

print(counter)

from scipy.spatial import distance


def solve(string):
    n, d, *x = list(map(int, string.split()))
    x = [tuple(c) for c in zip(*[iter(x)] * d)]
    dist = distance.cdist(x, x)
    return str(((dist == dist.astype("int32")).sum() - n) // 2)


if __name__ == "__main__":
    n, m = list(map(int, input().split()))
    print(
        (solve("{} {}\n".format(n, m) + "\n".join([eval(input()) for _ in range(n)])))
    )

import math

N, D = list(map(int, input().split()))
X = [list(map(float, input().split())) for i in range(N)]
counter = 0
for i, x0 in enumerate(X):
    for x1 in X[i + 1 :]:
        if math.sqrt(sum([(a - b) ** 2 for a, b in zip(x0, x1)])).is_integer():
            counter += 1
print(counter)

-from scipy.spatial import distance +import math - -def solve(string): -    n, d, *x = list(map(int, string.split())) -    x = [tuple(c) for c in zip(*[iter(x)] * d)] -    dist = distance.cdist(x, x) -    return str(((dist == dist.astype("int32")).sum() - n) // 2) - - -if __name__ == "__main__": -    n, m = list(map(int, input().split())) -    print( -        (solve("{} {}\n".format(n, m) + "\n".join([eval(input()) for _ in range(n)]))) -    ) +N, D = list(map(int, input().split())) +X = [list(map(float, input().split())) for i in range(N)] +counter = 0 +for i, x0 in enumerate(X): +    for x1 in X[i + 1 :]: +        if math.sqrt(sum([(a - b) ** 2 for a, b in zip(x0, x1)])).is_integer(): +            counter += 1 +print(counter)