import numpy as np



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

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

count = 0

for i in range(N):

    for j in range(N):

        if j == i:

            continue

        dist = np.sqrt(sum([(points[i][d] - points[j][d]) ** 2 for d in range(D)]))

        if dist.is_integer():

            count += 1

print((count // 2))
import sys

sys.setrecursionlimit(10 ** 6)





def calc_dist(x, y):

    dist = 0

    for xi, yi in zip(x, y):

        dist += (yi - xi) ** 2

    return dist ** (1/2)





def main():

    N, D = list(map(int, sys.stdin.readline().rstrip().split()))

    X = [list(map(int, sys.stdin.readline().rstrip().split())) for _ in range(N)]



    ans = 0

    for i in range(N):

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

            dist = calc_dist(X[i], X[j])

            if dist.is_integer():

                ans += 1

    

    print(ans)





if __name__ == '__main__':

    main()
import numpy as np

N, D = list(map(int, input().split()))
points = [list(map(int, input().split())) for _ in range(N)]
count = 0
for i in range(N):
    for j in range(N):
        if j == i:
            continue
        dist = np.sqrt(sum([(points[i][d] - points[j][d]) ** 2 for d in range(D)]))
        if dist.is_integer():
            count += 1
print((count // 2))

import sys

sys.setrecursionlimit(10**6)


def calc_dist(x, y):
    dist = 0
    for xi, yi in zip(x, y):
        dist += (yi - xi) ** 2
    return dist ** (1 / 2)


def main():
    N, D = list(map(int, sys.stdin.readline().rstrip().split()))
    X = [list(map(int, sys.stdin.readline().rstrip().split())) for _ in range(N)]
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            dist = calc_dist(X[i], X[j])
            if dist.is_integer():
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()

-import numpy as np +import sys -N, D = list(map(int, input().split())) -points = [list(map(int, input().split())) for _ in range(N)] -count = 0 -for i in range(N): -    for j in range(N): -        if j == i: -            continue -        dist = np.sqrt(sum([(points[i][d] - points[j][d]) ** 2 for d in range(D)])) -        if dist.is_integer(): -            count += 1 -print((count // 2)) +sys.setrecursionlimit(10**6) + + +def calc_dist(x, y): +    dist = 0 +    for xi, yi in zip(x, y): +        dist += (yi - xi) ** 2 +    return dist ** (1 / 2) + + +def main(): +    N, D = list(map(int, sys.stdin.readline().rstrip().split())) +    X = [list(map(int, sys.stdin.readline().rstrip().split())) for _ in range(N)] +    ans = 0 +    for i in range(N): +        for j in range(i + 1, N): +            dist = calc_dist(X[i], X[j]) +            if dist.is_integer(): +                ans += 1 +    print(ans) + + +if __name__ == "__main__": +    main()