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

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

l=len(X)

cnt=0

for i in range(l):

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

  t=sum((X[i][d]-X[j][d])**2for d in range(D))**0.5

  if t==int(t):cnt+=1

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

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

l=len(X)

cnt=0

for i in range(l):

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

  t=sum((X[i][d]-X[j][d])**2for d in range(D))**0.5

  cnt+=t==int(t)

print(cnt)
N, D = list(map(int, input().split()))
X = [list(map(int, input().split())) for i in range(N)]
l = len(X)
cnt = 0
for i in range(l):
    for j in range(i + 1, l):
        t = sum((X[i][d] - X[j][d]) ** 2 for d in range(D)) ** 0.5
        if t == int(t):
            cnt += 1
print(cnt)

N, D = list(map(int, input().split()))
X = [list(map(int, input().split())) for i in range(N)]
l = len(X)
cnt = 0
for i in range(l):
    for j in range(i + 1, l):
        t = sum((X[i][d] - X[j][d]) ** 2 for d in range(D)) ** 0.5
        cnt += t == int(t)
print(cnt)

-        if t == int(t): -            cnt += 1 +        cnt += t == int(t)