import math



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

x = [[0]*d for _ in range(n)]



for i in range(n):

    x[i] = list( map( int, input().split() ) )



count = 0

for i in range(n):

    for j in range(n):

        if i <= j:

            continue

        dist = 0

        for k in range(d):

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

        dist = math.sqrt(dist)

        if dist % 1 == 0:

            count += 1



print(count)

import math



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



point = [[0]*d for _ in range(n)]



for i in range(n):

    point[i] = list( map( int, input().split()))



count = 0

for i in range(n):

    for j in range(n):

        if i < j:

            sum = 0

            for k in range(d):

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

            sum = math.sqrt(sum)

            if sum % 1 == 0:

                count += 1

        else:

            continue



print(count)
import math

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

import math

n, d = list(map(int, input().split()))
point = [[0] * d for _ in range(n)]
for i in range(n):
    point[i] = list(map(int, input().split()))
count = 0
for i in range(n):
    for j in range(n):
        if i < j:
            sum = 0
            for k in range(d):
                sum += (point[i][k] - point[j][k]) ** 2
            sum = math.sqrt(sum)
            if sum % 1 == 0:
                count += 1
        else:
            continue
print(count)

-x = [[0] * d for _ in range(n)] +point = [[0] * d for _ in range(n)] -    x[i] = list(map(int, input().split())) +    point[i] = list(map(int, input().split())) -        if i <= j: +        if i < j: +            sum = 0 +            for k in range(d): +                sum += (point[i][k] - point[j][k]) ** 2 +            sum = math.sqrt(sum) +            if sum % 1 == 0: +                count += 1 +        else: -        dist = 0 -        for k in range(d): -            dist += (x[i][k] - x[j][k]) ** 2 -        dist = math.sqrt(dist) -        if dist % 1 == 0: -            count += 1