AtCoder Beginner Contest 133 - Good Distance

There are N points in a D-dimensional space.
The coordinates of the i-th point are (X_{i1}, X_{i2}, ..., X_{iD}).
The distance between two points with coordinates (y_1, y_2, ..., y_D) and (z_1, z_2, ..., z_D) is \sqrt{(y_1 - z_1)^2 + (y_2 - z_2)^2 + ... + (y_D - z_D)^2}.
How many pairs (i, j) (i < j) are there such that the distance between the i-th point and the j-th point is an integer?

-----Constraints-----
 - All values in input are integers.
 - 2 \leq N \leq 10
 - 1 \leq D \leq 10
 - -20 \leq X_{ij} \leq 20
 - No two given points have the same coordinates. That is, if i \neq j, there exists k such that X_{ik} \neq X_{jk}.

-----Input-----
Input is given from Standard Input in the following format:
N D
X_{11} X_{12} ... X_{1D}
X_{21} X_{22} ... X_{2D}
\vdots
X_{N1} X_{N2} ... X_{ND}

-----Output-----
Print the number of pairs (i, j) (i < j) such that the distance between the i-th point and the j-th point is an integer.

-----Sample Input-----
3 2
1 2
5 5
-2 8

-----Sample Output-----
1

The number of pairs with an integer distance is one, as follows:
 - The distance between the first point and the second point is \sqrt{|1-5|^2 + |2-5|^2} = 5, which is an integer.
 - The distance between the second point and the third point is \sqrt{|5-(-2)|^2 + |5-8|^2} = \sqrt{58}, which is not an integer.
 - The distance between the third point and the first point is \sqrt{|-2-1|^2+|8-2|^2} = 3\sqrt{5}, which is not an integer.

Difficulty: EASY

Starter code:

Solutions:
(n, d) = map(int, input().split())
point = []
for _ in range(n):
	point.append(list(map(int, input().split())))
ans = 0
for i in range(n - 1):
	for l in range(i, n):
		if i == l:
			continue
		dis = 0
		for f in range(d):
			dis += (point[i][f] - point[l][f]) ** 2
		dis = dis ** 0.5
		if dis.is_integer():
			ans += 1
print(ans)


(N, D) = map(int, input().split())
X = []
for i in range(N):
	X.append(list(map(int, input().split())))
ans = 0
for i in range(N):
	for j in range(i + 1, N):
		d = 0
		for k in range(D):
			d += (X[i][k] - X[j][k]) ** 2
		d = d ** (1 / 2)
		if int(d) == d:
			ans += 1
print(ans)


import math
(N, D) = list(map(int, input().split()))
sq = [list(map(int, input().split())) for i in range(N)]
ans = 0
for j in range(N - 1):
	for k in range(j + 1, N):
		s = 0
		for l in range(D):
			s += (sq[j][l] - sq[k][l]) ** 2
		if math.sqrt(s) % 1 == 0.0:
			ans += 1
print(ans)


(n, D) = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
res = 0
for i in range(n):
	for j in range(i + 1, n):
		d = sum(((l[i][k] - l[j][k]) ** 2 for k in range(D)))
		if int(d ** 0.5) ** 2 == d:
			res += 1
print(res)


import math

def main():
	(n, d) = list(map(int, input().split()))
	Xs = [list(map(int, input().split())) for _ in range(n)]
	ans = 0
	for (i, xi) in enumerate(Xs):
		for xj in Xs[i + 1:]:
			dis = 0
			for di in range(d):
				dis += (xi[di] - xj[di]) ** 2
			if math.sqrt(dis) % 1 == 0:
				ans += 1
	print(ans)

def __starting_point():
	main()
__starting_point()


(n, d) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		tmp = 0
		for k in range(d):
			tmp += (a[i][k] - a[j][k]) ** 2
		tmp **= 0.5
		if tmp == int(tmp):
			ans += 1
print(ans)


import math
(N, D) = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N - 1):
	for j in range(i + 1, N):
		d = 0
		for k in range(D):
			d += (X[i][k] - X[j][k]) ** 2
		if int(math.sqrt(d)) ** 2 == d:
			ans += 1
print(ans)


import itertools
(n, d) = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
c = list(itertools.combinations(range(n), 2))
ans = 0
for (a, b) in c:
	dist = 0
	for j in range(d):
		dist += (x[a][j] - x[b][j]) ** 2
	if dist ** (1 / 2) % 1 == 0:
		ans += 1
print(ans)


import math
from scipy.special import comb
(N, D) = map(int, input().split())
List = []
for i in range(N):
	x = list(map(int, input().split()))
	List.append(x)
ans = 0
for i in range(N - 1):
	y = List[i]
	for j in range(i + 1, N):
		z = List[j]
		sum = 0
		for j in range(D):
			sum += abs(y[j] - z[j]) ** 2
			s = math.sqrt(sum)
		if s.is_integer():
			ans += 1
print(ans)


import numpy as np
from itertools import combinations
import math
(N, D) = list(map(int, input().split()))
X = [list(map(int, input().split())) for i in range(N)]
res = 0
for (x, y) in combinations(X, 2):
	if (sum((np.array(x) - np.array(y)) ** 2) ** 0.5).is_integer():
		res += 1
print(res)


(N, D) = map(int, input().split())
X = [[int(x) for x in input().split()] for _ in range(N)]
ans = 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 int(dist ** 0.5) ** 2 == dist:
			ans += 1
print(ans)


(n, d) = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		s = 0
		for k in range(d):
			s += abs(x[i][k] - x[j][k]) ** 2
		s = s ** 0.5
		if s.is_integer():
			ans += 1
print(ans)


(N, D) = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
result = 0
for i in range(N - 1):
	for j in range(i + 1, N):
		result += (sum(((a - b) ** 2 for (a, b) in zip(X[i], X[j]))) ** 0.5).is_integer()
print(result)


(N, D) = 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)


import numpy as np
from itertools import combinations
(n, d) = map(int, input().split())
l = [np.array(input().split(), dtype=np.int64) for _ in range(n)]
ans = 0
dist = 0
for (a, b) in combinations(l, 2):
	dist = ((a - b) ** 2).sum()
	for j in range(dist + 1):
		if j ** 2 == dist:
			ans += 1
			continue
print(ans)


import math
(N, D) = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]

def check(i, j):
	dis = 0
	for k in range(D):
		dis += (X[i][k] - X[j][k]) ** 2
	if int(math.sqrt(dis)) ** 2 == dis:
		return 1
	else:
		return 0
ans = 0
for i in range(N):
	for j in range(i + 1, N):
		ans += check(i, j)
print(ans)


import itertools
(n, d) = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
count = 0
for (i, j) in itertools.product(l, l):
	s = sum([abs(i[k] - j[k]) ** 2 for k in range(d)])
	f = s ** 0.5 - int(s ** 0.5) == 0
	g = s != 0
	if f and g:
		count += 1
print(int(count / 2))


import math
(N, D) = map(int, input().split())
L = [list(map(int, input().split())) for i in range(N)]
ans = 0
for n in range(N):
	for n2 in range(n + 1, N):
		tmp = 0
		for d in range(D):
			tmp += abs(L[n][d] - L[n - n2][d]) ** 2
		if math.sqrt(tmp) % 1 == 0:
			ans += 1
print(ans)


(N, D) = map(int, input().split())
from itertools import combinations
l = []
ans = 0
for i in range(N):
	l.append(list(map(int, input().split())))
for (m, n) in combinations(l, 2):
	sv = 0
	for a in range(D):
		sv += abs(m[a] - n[a]) ** 2
	if sv ** (1 / 2) % 1 == 0:
		ans += 1
print(ans)


(N, D) = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(N)]
c = 0
for i in range(N - 1):
	for j in range(i + 1, N):
		c += (sum(((a - b) ** 2 for (a, b) in zip(x[i], x[j]))) ** 0.5).is_integer()
print(c)


from itertools import combinations
(n, d) = map(int, input().split())
l = []
ans = 0
for i in range(n):
	l.append(list(map(int, input().split())))
for (a, b) in combinations(l, 2):
	if sum(((a[i] - b[i]) ** 2 for i in range(d))) ** (1 / 2) % 1 == 0:
		ans += 1
print(ans)


(N, D) = [int(_) for _ in input().split()]
x = [[int(_) for _ in input().split()] for i in range(N)]
res = 0
for i in range(N):
	for j in range(i + 1, N):
		dd = 0
		for k in range(D):
			dd += (x[i][k] - x[j][k]) ** 2
		dd **= 0.5
		res += dd.is_integer()
print(res)


import math
(N, D) = map(int, input().split())
Dis = []
for i in range(N):
	A = list(map(int, input().split()))
	Dis.append(A)
ans = 0
plus = 0
for m in range(N - 1):
	for k in range(N - 1):
		for j in range(D):
			B = Dis[m][j] - Dis[m + k + 1][j]
			B = B ** 2
			plus += B
		plus = math.sqrt(plus)
		if round(plus) == plus:
			ans += 1
		plus = 0
		if m + k + 1 == N - 1:
			break
print(ans)


import itertools
(N, D) = map(int, input().split())
N_List = [i for i in range(N)]
ND_List = []
for i in range(N):
	ND_List.append(list(map(int, input().split())))
cnt = 0
for comb in itertools.combinations(N_List, 2):
	ans = 0
	for k in range(D):
		ans += (ND_List[comb[0]][k] - ND_List[comb[1]][k]) ** 2
	ans = ans ** 0.5
	if ans.is_integer():
		cnt += 1
print(cnt)


import math

def calc(num, list1, list2):
	s = 0
	for i in range(num):
		s += (list1[i] - list2[i]) ** 2
	d = math.sqrt(s)
	return d
(N, D) = map(int, input().split())
L = []
ans = 0
for i in range(N):
	L.append(list(map(int, input().split())))
for i in range(N):
	for j in range(i + 1, N):
		c = calc(D, L[i], L[j])
		if c.is_integer():
			ans += 1
print(ans)


(a, b) = map(int, input().split())
c = []
for i in range(a):
	c += [list(map(int, input().split()))]
count = 0
for i in range(a):
	for j in range(i + 1, a):
		k = sum([(c[i][t] - c[j][t]) ** 2 for t in range(b)])
		if int(k ** 0.5) ** 2 == k:
			count += 1
print(count)


(n, d) = map(int, input().split())
count = 0
X = [list(map(int, input().split())) for i in range(n)]
for x in range(n - 1):
	for y in range(x + 1, n):
		d = sum([(a - b) ** 2 for (a, b) in zip(X[x], X[y])]) ** 0.5
		if d == d // 1:
			count += 1
print(count)


import math
(n, d) = 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):
		dis = 0
		for k in range(d):
			dis += (x[i][k] - x[j][k]) ** 2
		if math.sqrt(dis) % 1 == 0:
			cnt += 1
print(cnt)


import math
(n, d) = list(map(int, input().split()))
li = [list(map(int, input().split())) for i in range(n)]
cnt = 0
sum = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		sum = 0
		for x in range(d):
			sum += abs(li[i][x] - li[j][x]) ** 2
		if math.sqrt(sum) % 1 == 0.0:
			cnt += 1
print(cnt)


(n, d) = map(int, input().split())
ans = 0
X = [list(map(int, input().split())) for _ in range(n)]
for (i, j) in enumerate(X):
	for k in X[i + 1:]:
		res = 0
		for l in range(d):
			res += (j[l] - k[l]) ** 2
		if res ** 0.5 - int(res ** 0.5) < 1e-09:
			ans += 1
print(ans)


(N, D) = map(int, input().split())
table = [input().split() for i in range(N)]
k = 0
for i in range(N):
	for j in range(N):
		if (sum(((int(table[i][l]) - int(table[j][l])) ** 2 for l in range(D))) ** 0.5).is_integer() == True:
			k = k + 1
print(int((k - N) / 2))


import math

def colcu(bli, ali, D):
	num = 0
	for i in range(D):
		num += (bli[i] - ali[i]) ** 2
	return math.sqrt(num)
(N, D) = map(int, input().split())
pli = []
for i in range(N):
	pli.append(list(map(int, input().split())))
an = 0
for i in range(N - 1):
	for t in range(i + 1, N):
		if colcu(pli[i], pli[t], D).is_integer():
			an += 1
print(an)


(n, d) = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		t = 0
		for l in range(d):
			t += (x[i][l] - x[j][l]) ** 2
		if t ** (1 / 2) % 1 == 0:
			ans += 1
print(ans)


import math

def calc_distance(Y, Z):
	temp = 0
	for (y, z) in zip(Y, Z):
		temp += (y - z) ** 2
	return temp

def is_integer(num):
	for k in range(1, num + 1):
		if k * k == num:
			return True
	else:
		return False
(N, D) = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
for i in range(len(X) - 1):
	for j in range(i, len(X)):
		distance = calc_distance(X[i], X[j])
		if is_integer(distance):
			cnt += 1
print(cnt)


(N, D) = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
import math
ans = 0
for i in range(N):
	X1 = X[i]
	for X2 in X[i + 1:]:
		if math.sqrt(sum([(x1 - x2) ** 2 for (x1, x2) in zip(X1, X2)])).is_integer():
			ans += 1
print(ans)


(N, D) = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
ans = 0
for i in range(N - 1):
	for j in range(i + 1, N):
		dis = 0
		for k in range(D):
			dis += (X[i][k] - X[j][k]) ** 2
		dis **= 0.5
		if dis == dis // 1:
			ans += 1
print(ans)


(n, d) = map(int, input().split())
x = [list(map(int, input().split())) for _ in [0] * n]
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		tmp = sum(((k - l) ** 2 for (k, l) in zip(x[i], x[j])))
		if (tmp ** 0.5).is_integer():
			ans += 1
print(ans)


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


import itertools
(N, D) = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
combi = list(itertools.combinations([i for i in range(N)], 2))
ans = 0
for c in combi:
	temp = 0
	for d in range(D):
		temp += (X[c[0]][d] - X[c[1]][d]) ** 2
	temp = temp ** 0.5
	if float.is_integer(temp):
		ans += 1
print(ans)


from itertools import *
(n, d) = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for (a, b) in combinations(x, 2):
	delta = 0
	for i in range(d):
		delta += (a[i] - b[i]) ** 2
	if (delta ** 0.5).is_integer():
		ans += 1
print(ans)


import math
from itertools import combinations
(N, D) = map(int, input().split())
X = [list(map(float, input().split())) for i in range(N)]
counter = [(sum([(a - b) ** 2 for (a, b) in zip(x0, x1)]) ** 0.5).is_integer() for (x0, x1) in combinations(X, 2)]
print(sum(counter))


import math
(N, D) = map(int, input().split())
X = []
ans = 0
for i in range(N):
	x = list(map(int, input().split()))
	X.append(x)
	for j in range(i):
		l = 0
		for k in range(D):
			l += (X[j][k] - x[k]) ** 2
		if int(math.sqrt(l)) ** 2 == l:
			ans += 1
print(ans)


import math
(n, d) = list(map(int, input().split()))
x = []
for i in range(n):
	xi = [int(s) for s in input().split()]
	x.append(xi)
count = 0
for i in range(0, n - 1):
	for j in range(i + 1, n):
		distance = 0
		for k in range(d):
			distance += (x[i][k] - x[j][k]) ** 2
		norm = math.sqrt(distance)
		if norm.is_integer():
			count += 1
print(count)


(N, D) = map(int, input().split())
X = [[int(i) for i in input().split()] for j in range(N)]
ans = 0
for i in range(N):
	for j in range(i + 1, N):
		L = 0
		for k in range(D):
			L += (X[i][k] - X[j][k]) ** 2
		M = L ** 0.5
		if M == int(M):
			ans += 1
print(ans)


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

def how_far(a, b):
	x = 0
	for s in range(0, d):
		x += (a[s] - b[s]) ** 2
	x = x ** (1 / 2)
	return x
count = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		kyori = how_far(p[i], p[j])
		true_kyori = int(kyori)
		if kyori == true_kyori:
			count += 1
print(count)


import itertools
(n, d) = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for (a, b) in itertools.combinations(X, r=2):
	s = sum(map(lambda x, y: (x - y) ** 2, a, b)) ** 0.5
	if s.is_integer():
		ans += 1
print(ans)


(n, d) = map(int, input().split())
count = 0
x_list = [list(map(int, input().split())) for _ in range(n)]
for i in range(n - 1):
	for j in range(i + 1, n):
		count += (sum(((a - b) ** 2 for (a, b) in zip(x_list[i], x_list[j]))) ** 0.5).is_integer()
print(count)


from math import sqrt
(n, d) = map(int, input().split())
xs = [tuple(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n - 1):
	xi = xs.pop()
	for xj in xs:
		o = sqrt(sum(((y - z) ** 2 for (y, z) in zip(xi, xj))))
		ans += o // 1 == o
print(ans)


(N, D) = map(int, input().split())
X = [list(map(int, input().split())) for x in range(N)]
l = []
for i in range(N):
	for j in range(i + 1, N):
		s = 0
		for k in range(D):
			s += (X[i][k] - X[j][k]) ** 2
		s = s ** 0.5
		if s - s // 1 == 0:
			l.append(s)
print(len(l))


(N, D) = map(int, input().split())
X = []
ans = 0
for i in range(N):
	X.append(list(map(int, input().split())))
import math
for i in range(N):
	for j in range(i + 1, N):
		lis_1 = X[i]
		lis_2 = X[j]
		cnt = 0
		for k in range(D):
			cnt += (lis_1[k] - lis_2[k]) ** 2
		cnt = math.sqrt(cnt)
		if cnt.is_integer():
			ans += 1
print(ans)


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


(n, d) = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
cnt = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		l1 = l[i]
		l2 = l[j]
		sum = 0
		for (y, z) in zip(l1, l2):
			sum += (y - z) ** 2
		dist = sum ** 0.5
		if dist == int(dist):
			cnt += 1
print(cnt)


(N, D) = map(int, input().split())
X = [list(map(float, input().split())) for i in range(N)]
cnt = 0
for i in range(N - 1):
	for j in range(N - i - 1):
		jj = j + i + 1
		dis = 0.0
		for k in range(D):
			dis += (X[i][k] - X[jj][k]) ** 2
		dis = dis ** 0.5
		if dis.is_integer():
			cnt += 1
print(cnt)


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


(N, D) = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
ans = 0
for i in range(N - 1):
	for j in range(1, N - i):
		L = 0
		for k in range(D):
			L += (X[i][k] - X[i + j][k]) ** 2
		L = L ** 0.5
		if L.is_integer() == True:
			ans += 1
print(ans)


import math
import itertools
(N, D) = list(map(int, input().split()))
cnt = 0
L = []
for i in range(N):
	X = list(map(int, input().split()))
	L.append(X)
for i in itertools.combinations(L, 2):
	(y, z, dis) = (i[0], i[1], 0)
	for (a, b) in zip(y, z):
		dis += (a - b) ** 2
	if math.sqrt(dis) == int(math.sqrt(dis)):
		cnt += 1
print(cnt)


import math
(n, d) = list(map(int, input().split()))
l = [list(map(int, input().split())) for l in range(n)]
ans = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		x = 0
		for k in range(d):
			x += (l[i][k] - l[j][k]) ** 2
		y = math.sqrt(x)
		(a, b) = math.modf(y)
		if a == 0:
			ans += 1
print(ans)


(N, D) = map(int, input().split())
l = [list(map(int, input().split())) for i in range(N)]
ans = 0
s = 0
for i in range(N):
	for j in range(i + 1, N):
		s = 0
		for d in range(D):
			s += (l[i][d] - l[j][d]) ** 2
		if s ** (1 / 2) % 1 == 0:
			ans += 1
print(ans)


import math
(N, D) = map(int, input().split())
S = []
C = 0
for i in range(N):
	S.append(list(map(int, input().split())))
for i in range(0, N - 1):
	for j in range(i + 1, N):
		tmp = 0
		for k in range(D):
			tmp += (S[i][k] - S[j][k]) ** 2
		tmp = math.sqrt(tmp)
		if tmp == int(tmp):
			C += 1
print(C)


from math import sqrt
(n, d) = map(int, input().split())
l = [input().split() for i in range(n)]
c = 0
d2 = 0
for i in range(n):
	for j in range(i + 1, n):
		s = 0
		for k in range(d):
			s += (int(l[i][k]) - int(l[j][k])) ** 2
		if sqrt(s).is_integer():
			c += 1
print(c)


(_, *x) = [t.split() for t in open(0)]
print(sum((sum(((int(i) - int(j)) ** 2 for (i, j) in zip(a, b))) ** 0.5 % 1 == 0 for a in x for b in x)) - len(x) >> 1)


(N, D) = map(int, input().split())
X = []
for i in range(N):
	X.append(list(map(int, input().split())))
ans = 0
import math
for i in range(0, N - 1):
	for j in range(i + 1, N):
		ans += math.sqrt(sum(((X[i][k] - X[j][k]) ** 2 for k in range(D)))).is_integer()
print(ans)


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


(n, d) = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		pw = 0
		for k in range(d):
			pw += (x[i][k] - x[j][k]) ** 2
		if pw ** 0.5 % 1 == 0:
			ans += 1
print(ans)


(n, d) = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
cnt = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		ans = 0
		for k in range(d):
			ans += (x[i][k] - x[j][k]) ** 2
		ans = ans ** (1 / 2)
		if ans % 1 == 0:
			cnt += 1
print(cnt)


(n, *x) = [list(map(int, t.split())) for t in open(0)]
print(sum((sum(((i - j) ** 2 for (i, j) in zip(a, b))) ** 0.5 % 1 == 0 for a in x for b in x)) - n[0] >> 1)


cnt = 0
(N, D) = map(int, input().split())
x = [list(map(int, input().split())) for i in range(N)]
ans = 0
for i in range(N):
	for j in range(i + 1, N):
		num = 0
		for k in range(D):
			num += (x[i][k] - x[j][k]) ** 2
		num = num ** 0.5
		if num.is_integer():
			ans += 1
print(ans)


import math
(n, d) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
p = 0
for i in range(0, n - 1):
	for j in range(i + 1, n):
		q = 0
		for k in range(0, d):
			q += (a[i][k] - a[j][k]) ** 2
		if int(math.sqrt(q)) == math.sqrt(q):
			p += 1
print(p)


import numpy as np
from scipy.special import comb
(n, d) = map(int, input().split())
x = []
total = 0
for i in range(n):
	x.append(list(map(int, input().split())))
for i in range(n):
	for j in range(n):
		if i != j:
			a = np.array(x[i])
			b = np.array(x[j])
			u = b - a
			if np.linalg.norm(u) == int(np.linalg.norm(u)):
				total += 1
print(int(total / 2))


(n, d) = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(n)]
f = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		l = sum(((X[i][a] - X[j][a]) ** 2 for a in range(d))) ** (1 / 2)
		if int(l) == l:
			f += 1
print(f)


(N, D) = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
S = {i ** 2 for i in range(1000)}
ans = sum((a != b and sum(((x - y) ** 2 for (x, y) in zip(a, b))) in S for a in X for b in X)) // 2
print(ans)


(n, d) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = 0
for i in range(n):
	for j in range(i + 1, n):
		s = 0
		for (c, e) in zip(a[i], a[j]):
			s += (c - e) ** 2
		if s ** 0.5 == int(s ** 0.5):
			b += 1
print(b)


def calc(D, a, b):
	d2 = 0
	for i in range(D):
		d2 += abs(a[i] - b[i]) ** 2
	return d2 ** 0.5
(N, D) = map(int, input().split())
lst = []
for i in range(N):
	lst.append(list(map(int, input().split())))
ans = 0
for i in range(N):
	for j in range(i + 1, N):
		d = calc(D, lst[i], lst[j])
		if int(d) == d:
			ans += 1
print(ans)


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


import math
(n, d) = list(map(int, input().split()))
xx = []
for i in range(n):
	xx.append(list(map(int, input().split())))

def distance(xx, d, i, j):
	ans = 0
	for u in range(d):
		ans += (xx[i][u] - xx[j][u]) ** 2
	if math.sqrt(ans).is_integer():
		return 1
	else:
		return 0
count = 0
for i in range(n):
	for j in range(i + 1, n):
		count += distance(xx, d, i, j)
print(count)


from math import sqrt
(N, D, A) = [int(x) for x in input().split()] + [[]]
exec('A+=[[int(x)for x in input().split()]];' * N)
C = 0
for i in range(N):
	for j in range(i + 1, N):
		S = k = 0
		exec('S+=(A[i][k]-A[j][k])**2;k+=1;' * D)
		C += 1 if int(sqrt(S)) == sqrt(S) else 0
print(C)


(N, D) = map(int, input().split())
lis = [list(map(int, input().split())) for i in range(N)]
count = 0
for j in range(N):
	for k in range(j):
		total = sum(((lis[j][m] - lis[k][m]) ** 2 for m in range(D)))
		sqr = total ** 0.5
		if sqr.is_integer():
			count += 1
print(count)


import math
(n, d) = map(int, input().split())
a = [[int(i) for i in input().split()] for l in range(n)]
c = 0
for i in range(n):
	for j in range(i + 1, n):
		sum = 0
		for (x, y) in zip(a[i], a[j]):
			sum += abs(x - y) ** 2
		if math.sqrt(sum) % 1 == 0:
			c += 1
print(c)


def dist(a, b):
	ans = 0
	for i in range(D):
		ans += (b[i] - a[i]) ** 2
	ans **= 0.5
	return ans
(N, D) = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
count = 0
for i in range(N - 1):
	for j in range(i + 1, N):
		if dist(X[i], X[j]).is_integer():
			count += 1
print(count)


def dist(ar1, ar2):
	s = 0
	for i in range(len(ar1)):
		s += (ar1[i] - ar2[i]) ** 2
	return (s ** 0.5).is_integer()
(n, d) = map(int, input().split())
ans = 0
arr = []
for _ in range(n):
	arr.append(list(map(int, input().split())))
for i in range(len(arr)):
	for j in range(i + 1, len(arr)):
		if dist(arr[i], arr[j]):
			ans += 1
print(ans)


(N, D) = map(int, input().split())
K = [list(map(int, input().split())) for x in range(N)]
ans = 0
for i in range(N - 1):
	for j in range(i + 1, N):
		goukei = 0
		for (a, b) in zip(K[i], K[j]):
			goukei += (a - b) ** 2
		ans += (goukei ** 0.5).is_integer()
print(ans)


(n, d) = map(int, input().split())
lists = []
for i in range(n):
	lis = list(map(int, input().split()))
	lists.append(lis)
cnt = 0
for i in range(0, n - 1):
	for j in range(i + 1, n):
		ans = 0
		for k in range(d):
			x = (lists[i][k] - lists[j][k]) ** 2
			ans += x
		ans = ans ** (1 / 2)
		if ans % 1 == 0:
			cnt += 1
print(cnt)


import math
(N, D) = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
seisu_count = 0
for l in range(N):
	for r in range(l + 1, N):
		total = 0
		for z in range(D):
			y_z = abs(X[l][z] - X[r][z])
			y_z_2 = y_z * y_z
			total += y_z_2
		sqr_total = math.sqrt(total)
		if sqr_total.is_integer():
			seisu_count += 1
print(seisu_count)


def main():
	(n, d) = map(int, input().split())
	ps = [[*map(int, input().split())] for _ in range(n)]
	square = [i ** 2 for i in range(1, 127)]
	cnt = 0
	for i in range(n - 1):
		for j in range(i + 1, n):
			if sum([(ps[i][k] - ps[j][k]) ** 2 for k in range(d)]) in square:
				cnt += 1
	print(cnt)

def __starting_point():
	main()
__starting_point()


import math
(N, D) = list(map(int, input().split()))
X = [[0] * D for i in range(N)]
for i in range(N):
	X[i] = list(map(int, input().split()))
count = 0
for i in range(N):
	ran = list(range(i + 1, N))
	for j in ran:
		dis = 0
		for d in range(D):
			dis += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d])
		dis = math.sqrt(dis)
		if dis.is_integer() == True:
			count += 1
print(count)


import numpy as np
(N, D) = map(int, input().split())
X = []
for i in range(N):
	X.append(list(map(int, input().split())))
dis = [[0 for i in range(N)] for j in range(N)]
for i in range(N):
	for j in range(i + 1, N):
		for k in range(D):
			dis[i][j] += (X[i][k] - X[j][k]) ** 2
dot = 0
for i in range(N):
	for j in range(i, N):
		dis[i][j] = np.sqrt(dis[i][j])
		if dis[i][j].is_integer() and dis[i][j] != 0:
			dot += 1
print(dot)


(N, D) = map(int, input().split())
x = [list(map(int, input().split())) for i in range(N)]
cnt = 0
d = 0
for i in range(N - 1):
	for j in range(i + 1, N):
		for k in range(D):
			d += (x[i][k] - x[j][k]) ** 2
		if d ** (1 / 2) % 1 == 0:
			cnt += 1
		d = 0
print(cnt)


import itertools
(n, d) = map(int, input().split())
points = []
for _ in range(n):
	point = list(map(int, input().split()))
	points.append(point)
combinations = list(itertools.combinations(points, 2))
dist_lists = []
ans = 0
for comb in combinations:
	A = comb[0]
	B = comb[1]
	tmp = 0
	for j in range(len(A)):
		tmp += (B[j] - A[j]) ** 2
	distance = tmp ** 0.5
	if distance.is_integer():
		ans += 1
print(ans)


def LI():
	return list(map(int, input().split()))

def I():
	return map(int, input().split())
mod = 10 ** 9 + 7

def main():
	(n, d) = map(int, input().split())
	x = [LI() for i in range(n)]
	ans = 0
	for i in range(n - 1):
		for j in range(i + 1, n):
			sm = 0
			for k in range(d):
				sm += (x[i][k] - x[j][k]) ** 2
			if sm ** 0.5 % 1 == 0:
				ans += 1
	print(ans)

def __starting_point():
	main()
__starting_point()


(N, D) = map(int, input().split())
P = [list(map(int, input().split())) for i in range(N)]
ans = 0
for i in range(N):
	for j in range(i):
		d = sum(((x - y) ** 2 for (x, y) in zip(P[i], P[j])))
		x = int(d ** 0.5)
		if x ** 2 == d:
			ans += 1
print(ans)


(n, d) = list(map(int, input().rstrip().split()))
m = []
for _ in range(n):
	arr = list(map(int, input().rstrip().split()))
	m.append(arr)
ans = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		a = 0
		for k in range(d):
			a += (m[i][k] - m[j][k]) ** 2
		x = int(a ** (1 / 2))
		if x ** 2 == a:
			ans += 1
print(ans)


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


X_list = [list(map(int, input().split())) for _ in range(list(map(int, input().split()))[0])]
print((sum([sum([(x1 - x2) ** 2 for (x1, x2) in zip(x_lis1, x_lis2)]) ** 0.5 % 1 == 0 for x_lis1 in X_list for x_lis2 in X_list]) - len(X_list)) // 2)


(n, d) = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		x = 0
		for z in range(d):
			x += (l[i][z] - l[j][z]) ** 2
		if x ** 0.5 % 1 == 0:
			ans += 1
print(ans)


(n, d) = map(int, input().split())
pos = [list(map(int, input().split())) for _ in range(n)]
count = 0
for i in range(n):
	for j in range(i + 1, n):
		sumpos = 0
		for k in range(d):
			sumpos += (pos[i][k] - pos[j][k]) ** 2
		for l in range(sumpos + 1):
			if l ** 2 == sumpos:
				count += 1
print(count)


from itertools import combinations
(n, d) = map(int, input().split())
L = list((list(map(int, input().split())) for _ in range(n)))
C = list(combinations(L, 2))
ans = 0
for i in range(len(C)):
	total = 0
	for (a, b) in zip(C[i][0], C[i][1]):
		total += abs(a - b) ** 2
	if total ** 0.5 % 1 == 0:
		ans += 1
print(ans)


import math
(N, D) = list(map(int, input().split()))
ary = []
for _ in range(N):
	ary.append(list(map(int, input().split())))
counter = 0
ary_len = len(ary)
for i in range(ary_len - 1):
	for j in range(i + 1, ary_len):
		tmp = 0
		for k in range(D):
			tmp += pow(abs(ary[i][k] - ary[j][k]), 2)
		if math.sqrt(tmp) % 1 == 0:
			counter += 1
print(counter)


import math
(n, d) = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
a = 0
for i in range(n):
	for j in range(i + 1, n):
		a += math.modf(math.sqrt(sum([abs(x[i][k] - x[j][k]) ** 2 for k in range(d)])))[0] < 1e-09
print(a)


import itertools
import math
(n, d) = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
q = list(itertools.combinations(range(n), 2))
cnt = 0
for i in range(len(q)):
	ans = 0
	for j in range(d):
		ans += (x[q[i][0]][j] - x[q[i][1]][j]) ** 2
	ans = math.sqrt(ans)
	if ans == int(ans):
		cnt += 1
print(cnt)


import itertools
(a, b) = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(a)]
cnt = 0
sum_1 = []
for v in itertools.combinations(l, 2):
	sum = 0
	for i in range(b):
		sum += (v[0][i] - v[1][i]) ** 2
	if (sum ** 0.5).is_integer():
		cnt += 1
print(cnt)


from itertools import combinations
(n, d) = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
ans = 0
for (i, j) in combinations(x, 2):
	l = 0
	for k in range(d):
		l += (i[k] - j[k]) ** 2
	if int(l ** 0.5) ** 2 == l:
		ans += 1
print(ans)


import numpy as np
(N, D) = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
for i in range(N):
	for j in range(i + 1, N):
		if np.linalg.norm(np.array(X[i]) - np.array(X[j])).is_integer():
			cnt += 1
print(cnt)


f = lambda : map(int, input().split())
(n, d) = f()
ll = [list(f()) for _ in range(n)]
a = 0
for j in range(n):
	for i in range(j):
		a += sum(((ll[i][k] - ll[j][k]) ** 2 for k in range(d))) ** 0.5 % 1 == 0
print(a)


(n, d) = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(n)]
c = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		for k in range(d):
			diff = sum([(s - t) ** 2 for (s, t) in zip(X[i], X[j])])
		if (diff ** 0.5).is_integer():
			c += 1
print(c)


R = lambda : map(int, input().split())
sq = lambda x: int(x ** 0.5) ** 2 == x
d2 = lambda x, y: sum(((u - v) ** 2 for (u, v) in zip(x, y)))
(n, d) = R()
a = [tuple(R()) for _ in range(n)]
print(sum((sq(d2(a[i], a[j])) for i in range(n) for j in range(i))))


(N, D) = map(int, input().split())
L = []
hei = [i ** 2 for i in range(200)]
for i in range(N):
	l = list(map(int, input().split()))
	L.append(l)
ans = 0
for i in range(N):
	for j in range(i + 1, N):
		if sum(((L[i][k] - L[j][k]) ** 2 for k in range(D))) in hei:
			ans += 1
print(ans)


import math
(N, D) = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
c = 0
for i in range(N):
	for j in range(i + 1, N):
		d = math.sqrt(sum(map(lambda y, z: (y - z) ** 2, X[i], X[j])))
		if d == int(d):
			c += 1
print(c)


(n, b) = map(int, input().split())
xlist = [list(map(int, input().split())) for _ in range(n)]
from itertools import combinations
import numpy as np
xnumpy = np.array(xlist)
ans = 0
for (y, z) in combinations(xnumpy, 2):
	distance = ((y - z) ** 2).sum()
	for i in range(40 ** 2 * 10):
		if distance == i * i:
			ans += 1
print(ans)


(N, D) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
for i in range(N - 1):
	for j in range(i + 1, N):
		d = sum((abs(a[i][k] - a[j][k]) ** 2 for k in range(D))) ** 0.5
		cnt += d % 1 == 0
print(cnt)


import math
(n, d) = map(int, input().split())
x = [[int(x) for x in input().split()] for _ in range(n)]
cnt = 0
for i in range(n):
	for j in range(i + 1, n):
		sum = 0
		for (a, b) in zip(x[i], x[j]):
			sum += (a - b) * (a - b)
		if math.sqrt(sum).is_integer():
			cnt += 1
print(cnt)


(N, D) = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N):
	for j in range(i + 1, N):
		d = 0
		for k in range(D):
			d += (X[i][k] - X[j][k]) ** 2
		for l in range(1000):
			if l ** 2 == d:
				ans += 1
				break
print(ans)


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

def dis(X, Y):
	return math.sqrt(sum([pow(x - y, 2) for (x, y) in zip(X, Y)]))
ans = 0
for i in range(N):
	for j in range(i + 1, N):
		if dis(X[i], X[j]).is_integer():
			ans += 1
print(ans)


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()))
cnt = 0
for i in range(n - 1):
	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) == int(math.sqrt(dist)):
			cnt += 1
print(cnt)


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


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


from itertools import combinations
(n, d) = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
cmb = combinations([i for i in range(n)], 2)
cnt = 0
for (i, j) in cmb:
	dist = sum([(x[i][k] - x[j][k]) ** 2 for k in range(d)])
	for m in range(int(dist ** 0.5) + 1):
		if m ** 2 == dist:
			cnt += 1
print(cnt)


import itertools
import numpy as np
(N, D) = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
count = 0
for i in itertools.combinations(X, 2):
	if np.linalg.norm(list(map(lambda x, y: abs(x - y), i[0], i[1]))) % 1 == 0:
		count += 1
print(count)


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

def f(i):
	return i ** 0.5 - int(i ** 0.5) == 0.0
ans = 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
		ans += 1 if f(dist) else 0
print(ans)


import math
import itertools
(N, D) = map(int, input().split())
X = [0] * N
for i in range(N):
	X[i] = list(map(int, input().split()))
cnt = 0
for i in list(itertools.combinations(X, 2)):
	ans = 0
	for j in range(D):
		ans += abs((i[0][j] - i[1][j]) ** 2)
	if math.sqrt(ans).is_integer():
		cnt += 1
print(cnt)


(N, D) = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
ans = 0
for i in range(N):
	for j in range(N - i - 1):
		s = 0
		for (I, J) in zip(X[i], X[j + i + 1]):
			s += (I - J) ** 2
		if int(s ** 0.5) ** 2 == s:
			ans += 1
print(ans)


(n, d) = map(int, input().split())
x = [[0]] * n
for i in range(n):
	x[i] = [int(i) for i in input().split()]
s = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		a = sum(((x[j][k] - x[i][k]) ** 2 for k in range(d))) ** 0.5
		if a // 1 == a:
			s += 1
print(s)


(n, d) = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		a = 0
		for k in range(d):
			a += (l[i][k] - l[j][k]) ** 2
		a **= 0.5
		if a.is_integer():
			ans += 1
print(ans)


(N, D) = (int(x) for x in input().split())
X = [None] * N
for i in range(N):
	X[i] = [float(x) for x in input().split()]
count = 0
for i in range(N - 1):
	for j in range(i + 1, N):
		sq = [(X[i][k] - X[j][k]) ** 2 for k in range(D)]
		dist = sum(sq) ** 0.5
		if dist == int(dist):
			count += 1
print(count)


(n, d) = map(int, input().split())
x = [[int(a) for a in input().split()] for _ in range(n)]
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		s = sum([(a - b) * (a - b) for (a, b) in zip(x[i], x[j])])
		t = int(s ** 0.5)
		if s == t * t:
			ans += 1
print(ans)


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


import math

def solve(y, z):
	res = 0
	for i in range(len(y)):
		res += (y[i] - z[i]) ** 2
	return math.sqrt(res)
(n, d) = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		dist = solve(x[i], x[j])
		if int(dist) == dist:
			ans += 1
print(ans)


(N, D) = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
a = 0
for i in range(1, N):
	for j in X[i:]:
		W = 0
		for d in range(D):
			W += (X[i - 1][d] - j[d]) ** 2
		if W ** (1 / 2) == int(W ** (1 / 2)):
			a += 1
print(a)


(n, d) = map(int, input().split())
x = [tuple(map(int, input().split())) for i in range(n)]
c = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		di = 0
		for k in range(d):
			di += (x[i][k] - x[j][k]) ** 2
		if di ** 0.5 % 1 == 0.0:
			c += 1
print(c)


(N, D) = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
count = 0
for i in range(N):
	for j in range(i + 1, N):
		count += (sum(((y - z) ** 2 for (y, z) in zip(X[i], X[j]))) ** 0.5).is_integer()
print(count)


import sys
input = sys.stdin.readline
import itertools
import math
import numpy as np

def main():
	numbers = []
	(n, m) = map(int, input().split())
	numbers = np.array([list(map(int, input().split())) for _ in range(n)])
	ans = 0
	length = 0
	count = 0
	for (idx, pair) in enumerate(itertools.combinations(numbers, 2)):
		tmp_A = np.array(pair[0])
		tmp_B = np.array(pair[1])
		length = (tmp_A - tmp_B) ** 2
		ans = math.sqrt(sum(length))
		if ans.is_integer() == True:
			count += 1
		else:
			continue
	print(count)

def __starting_point():
	main()
__starting_point()


(N, D) = map(int, input().split())
X = []
for i in range(N):
	X.append(list(map(int, input().split())))
count = 0
for i in range(N):
	for j in range(N):
		if i >= j:
			continue
		d = 0
		for k in range(D):
			d += pow(abs(X[i][k] - X[j][k]), 2)
		d = float(pow(d, 0.5))
		if d.is_integer():
			count += 1
print(count)


(n, d) = list(map(int, input().split()))
X = []
for i in range(n):
	a = list(map(int, input().split()))
	X.append(a)
count = 0
for i in range(n):
	for j in range(i + 1, n):
		norm = 0
		for k in range(d):
			diff = abs(X[i][k] - X[j][k])
			norm += diff * diff
		can = False
		for k in range(1, norm + 1):
			if k * k == norm:
				can = True
		if can:
			count += 1
print(count)


from math import sqrt

def main():
	(N, D) = list(map(int, input().split()))
	ans = 0
	X = [list(map(int, input().split())) for _ in range(N)]
	for i in range(N - 1):
		for j in range(i + 1, N):
			tmp = sum([(X[i][k] - X[j][k]) ** 2 for k in range(D)])
			if tmp == int(sqrt(tmp)) ** 2:
				ans += 1
	print(ans)

def __starting_point():
	main()
__starting_point()


(n, d) = list(map(int, input().split()))
t = []
ans = 0
for i in range(n):
	c = list(map(int, input().split()))
	t.append(c)
for k in range(0, n - 1):
	for j in range(k + 1, n):
		sumsum = 0
		for l in range(d):
			sumsum += (t[k][l] - t[j][l]) ** 2
		dis = sumsum ** (1 / 2)
		if dis.is_integer() == True:
			ans += 1
print(ans)


(n, d) = map(int, input().split())
xs = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for (i, y) in enumerate(xs):
	for z in xs[i + 1:]:
		s = sum([(a - b) ** 2 for (a, b) in zip(y, z)]) ** (1 / 2)
		if s == s // 1:
			ans += 1
print(ans)


from math import floor, sqrt
(n, d) = map(int, input().split())
X = []

def f(i, j):
	sm = 0
	for k in range(d):
		sm += (X[i][k] - X[j][k]) ** 2
	return floor(sqrt(sm)) ** 2 == sm
for _ in range(n):
	X.append(list(map(int, input().split())))
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		if f(i, j):
			ans += 1
print(ans)


(n, d) = map(int, input().split())
A = [list(map(int, input().split())) for i in range(n)]
cnt = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		X = 0
		for k in range(d):
			X += (A[i][k] - A[j][k]) ** 2
		if X ** 0.5 == X ** 0.5 // 1:
			cnt += 1
print(cnt)


import numpy as np
import math
(n, d) = map(int, input().split())
x_l = [np.array(list(map(int, input().split()))) for _ in range(n)]
ans = 0
p = set()
for (i, x) in enumerate(x_l):
	for (j, y) in enumerate(x_l):
		if i != j:
			if str(min([i, j])) + '_' + str(max([i, j])) not in p:
				d = math.sqrt(sum((x - y) ** 2))
				if d.is_integer():
					ans += 1
					p.add(str(min([i, j])) + '_' + str(max([i, j])))
print(ans)


import math
(N, D) = 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):
		buf = 0
		for k in range(len(X[0])):
			buf += (X[i][k] - X[j][k]) ** 2
		buf = math.sqrt(buf)
		if int(buf) == buf:
			cnt += 1
print(cnt)


import math
(n, d) = map(int, input().split(' '))
clist = []
for i in range(n):
	xlist = list(map(int, input().split(' ')))
	clist.append(xlist)

def dis(ylist, zlist):
	distance = 0
	for i in range(d):
		distance += (ylist[i] - zlist[i]) ** 2
	sqdis = math.sqrt(distance)
	return sqdis
countdis = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		if dis(clist[i], clist[j]) % 1 == 0:
			countdis += 1
print(countdis)


(n, m) = (int(_) for _ in input().split())
l = [list((int(_) for _ in input().split())) for i in range(n)]
res = 0
for i in range(n):
	for ii in range(i + 1, n):
		if sum([(l[i][x] - l[ii][x]) ** 2 for x in range(m)]) ** (1 / 2) % 1 == 0:
			res += 1
print(res)


from typing import List
from math import sqrt

def distance(x1: List[int], x2: List[int]) -> float:
	total = 0
	for (a, b) in zip(x1, x2):
		total += (a - b) ** 2
	return sqrt(total)
nd = list(map(int, input().split()))
(n, d) = (nd[0], nd[1])
xs = [list(map(int, input().split())) for _ in range(n)]
size = len(xs)
result = 0
for i in range(size):
	for j in range(i + 1, size):
		if distance(xs[i], xs[j]).is_integer():
			result += 1
print(result)


import math
(n, d) = (int(i) for i in input().split())
list_x = [[int(i) for i in input().split()] for j in range(0, n)]
count = 0
tmp = 0
for i in range(0, n):
	for j in range(i + 1, n):
		for k in range(0, d):
			tmp += pow(list_x[i][k] - list_x[j][k], 2)
		tmp = math.sqrt(tmp)
		if tmp.is_integer():
			count += 1
		tmp = 0
print(count)


a = list(map(int, input().split()))
b = []
for i in range(a[0]):
	b.append(list(map(int, input().split())))
c = 0
for i in range(a[0] - 1):
	for j in range(i + 1, a[0]):
		x = 0
		for k in range(a[1]):
			x = x + (b[i][k] - b[j][k]) ** 2
		x = x ** 0.5
		if x % 1 == 0:
			c = c + 1
print(c)


((n, d), *xx) = [list(map(int, s.split())) for s in open(0)]
from itertools import combinations
ans = 0
for (i, j) in combinations(range(n), 2):
	s = sum(((a - b) ** 2 for (a, b) in zip(xx[i], xx[j])))
	if s == round(s ** 0.5) ** 2:
		ans += 1
print(ans)


import math
(a, aa) = map(int, input().split())
b = [list(map(int, input().split())) for i in range(a)]
d = 0
for i in range(a - 1):
	for j in range(i + 1, a):
		c = 0
		for k in range(aa):
			c += (b[i][k] - b[j][k]) * (b[i][k] - b[j][k])
		c = math.sqrt(c)
		if c % 1 == 0:
			d += 1
print(d)


import itertools
(N, D) = map(int, input().split())
count = 0
lst = []
for n in range(N):
	X = list(map(int, input().split()))
	lst.append(X)
c = list(itertools.combinations(lst, 2))
lst2 = []
for a in c:
	d2 = 0
	for (x, y) in zip(a[0], a[1]):
		s = (x - y) ** 2
		d2 += s
	d = d2 ** 0.5
	if d.is_integer():
		lst2.append(d)
print(len(lst2))


(n, d) = map(int, input().split())
data = [input().split() for i in range(n)]
ans = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		sum = 0
		for k in range(d):
			sum += (int(data[i][k]) - int(data[j][k])) ** 2
		temp = sum ** 0.5
		if temp.is_integer() == True:
			ans += 1
print(ans)


(N, D) = map(int, input().split())
m = [list(map(int, input().split())) for _ in range(N)]
c = 0
for i in range(N):
	for j in range(i + 1, N):
		S = 0
		for p in range(D):
			S += (m[i][p] - m[j][p]) ** 2
		if S ** 0.5 - int(S ** 0.5) == 0:
			c += 1
print(c)


(N, D) = map(int, input().split())
X = [list(map(int, input().split())) for j in range(N)]
count_ = 0
for j in range(0, N):
	for i in range(0, N):
		sum_ = 0
		for d in range(D):
			sum_ += (X[i][d] - X[j][d]) ** 2
		if sum_ ** 0.5 % 1 == 0:
			count_ += 1
print(int((count_ - N) / 2))


(n, d) = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for (i, Y) in enumerate(X[:-1]):
	for (j, Z) in enumerate(X[i + 1:]):
		res = 0
		for (y, z) in zip(Y, Z):
			res += (y - z) ** 2
		if res ** 0.5 % 1 == 0:
			ans += 1
print(ans)


(N, D) = map(int, input().split())
X = [[int(i) for i in input().split()] for _ in range(N)]
count = 0
for i in range(N):
	for j in range(i + 1, N):
		res = sum([(X[i][k] - X[j][k]) ** 2 for k in range(D)])
		if res ** 0.5 % 1 == 0:
			count += 1
print(count)


(n, d) = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		d2 = sum(((y - z) ** 2 for (y, z) in zip(x[i], x[j])))
		if d2 ** 0.5 % 1 == 0:
			ans += 1
print(ans)


(N, D) = map(int, input().split())
c = 0
X = []
for i in range(N):
	X.append(list(map(int, input().split())))
for j in range(N):
	for k in range(j + 1, N):
		tmp = sum([(X[j][l] - X[k][l]) ** 2 for l in range(D)])
		if tmp in [y ** 2 for y in range(130)]:
			c += 1
print(c)


import sys
from io import StringIO
import unittest
from math import sqrt

class TestClass(unittest.TestCase):

	def assertIO(self, input, output):
		(stdout, stdin) = (sys.stdout, sys.stdin)
		(sys.stdout, sys.stdin) = (StringIO(), StringIO(input))
		resolve()
		sys.stdout.seek(0)
		out = sys.stdout.read()[:-1]
		(sys.stdout, sys.stdin) = (stdout, stdin)
		self.assertEqual(out, output)

	def test_入力例_1(self):
		input = '3 2\n1 2\n5 5\n-2 8'
		output = '1'
		self.assertIO(input, output)

	def test_入力例_2(self):
		input = '3 4\n-3 7 8 2\n-12 1 10 2\n-2 8 9 3'
		output = '2'
		self.assertIO(input, output)

	def test_入力例_3(self):
		input = '5 1\n1\n2\n3\n4\n5'
		output = '10'
		self.assertIO(input, output)

def resolve():
	(N, D) = list(map(int, input().split()))
	X = [list(map(int, input().split())) for _ in range(N)]
	ans = 0
	for (i, x1) in enumerate(X):
		for x2 in X[i + 1:]:
			tmp = 0
			for j in range(D):
				tmp += (x2[j] - x1[j]) ** 2
			tmp = sqrt(tmp)
			if tmp.is_integer() == True:
				ans += 1
	print(ans)

def __starting_point():
	resolve()
__starting_point()


import math
(n, d) = list(map(int, input().split()))
lst = []
for i in range(n):
	x = list(map(int, input().split()))
	lst.append(x)

def check(lst, a, b):
	tmp = 0
	for i in range(len(lst[a])):
		tmp = tmp + (lst[a][i] - lst[b][i]) ** 2
	tmp = math.sqrt(tmp)
	if tmp // 1 == tmp:
		return 1
	else:
		return 0
ans = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		ans = ans + check(lst, i, j)
print(ans)


(N, D) = map(int, input().split())
ans = 0
A = []
for x in range(N):
	X = list(map(int, input().split()))
	for y in range(len(A)):
		s = 0
		for z in range(D):
			s += (A[y][z] - X[z]) ** 2
		if s ** (1 / 2) * 10 % 10 == 0:
			ans += 1
	A.append(X)
print(ans)


(n, d) = map(int, input().split())
A = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n):
	for j in range(i):
		dis = sum([(A[i][k] - A[j][k]) ** 2 for k in range(d)])
		if dis ** (1 / 2) == int(dis ** (1 / 2)):
			ans += 1
print(ans)


(N, D) = map(int, input().split())
X = [input().split() for i in range(N)]
count = 0
d_2 = 0
d = 0
for i in range(1, N):
	for j in range(0, i):
		d_2 = 0
		d = 0
		for k in range(D):
			d_2 += (float(X[i][k]) - float(X[j][k])) ** 2
		d = d_2 ** (1 / 2)
		if d.is_integer() == True:
			count += 1
print('{}'.format(count))


from itertools import combinations
(a, (n, d)) = (0, list(map(int, input().split())))
for i in [sum([abs(i[0][j] - i[1][j]) ** 2 for j in range(d)]) ** 0.5 for i in list(combinations([list(map(int, input().split())) for i in range(n)], 2))]:
	if i.is_integer():
		a += 1
print(a)


(n, d) = map(int, input().split())
x = [[int(a) for a in input().split(' ')] for _ in range(n)]
cnt = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		dis = 0
		for k in range(d):
			dis += (x[i][k] - x[j][k]) ** 2
		if (dis ** 0.5).is_integer():
			cnt += 1
print(cnt)


(n, d) = map(int, input().split())
w = [list(map(int, input().split())) for a in range(n)]
c = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		b = 0
		for m in range(d):
			b += (w[i][m] - w[j][m]) ** 2
		if b ** 0.5 == float(int(b ** 0.5)):
			c += 1
print(c)


import math
(N, D) = list(map(int, input().split()))
Xarray = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N - 1):
	for j in range(i + 1, N):
		sum = 0
		for k in range(D):
			sum += abs(Xarray[i][k] - Xarray[j][k]) ** 2
		if math.sqrt(sum).is_integer():
			ans += 1
print(ans)


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


(n, d) = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		sm = 0
		for k in range(d):
			sm += (x[i][k] - x[j][k]) ** 2
		if sm == round(sm ** 0.5) ** 2:
			ans += 1
print(ans)


(n, *l) = [list(map(int, s.split())) for s in open(0)]
cnt = 0
for i in range(len(l) - 1):
	for j in range(i + 1, len(l)):
		dist = 0
		for d in range(n[1]):
			dist += (l[i][d] - l[j][d]) ** 2
		if dist ** 0.5 % 1 == 0:
			cnt += 1
print(cnt)


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


(N, D) = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
c = 0
for i in range(N):
	for j in range(i + 1, N):
		c += (sum(((X[i][p] - X[j][p]) ** 2 for p in range(D))) ** 0.5).is_integer()
print(c)


(N, D, *X) = map(int, open(0).read().split())
(*X,) = zip(*[iter(X)] * D)
cnt = 0
for (i, x) in enumerate(X):
	for j in range(i + 1, N):
		d = 0
		for (y, z) in zip(x, X[j]):
			d += (y - z) ** 2
		if (d ** 0.5).is_integer():
			cnt += 1
print(cnt)


(n, b) = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
count = 0
for i in range(n):
	for j in range(i + 1, n):
		t = 0
		for k in range(b):
			t += (x[i][k] - x[j][k]) ** 2
		t = t ** (1 / 2)
		if t.is_integer():
			count += 1
print(count)


(N, D) = map(int, input().split())
X = [tuple(map(int, input().split())) for _ in range(N)]
r = 0
for p in X:
	for q in X:
		if p != q:
			d = sum([(x - y) ** 2 for (x, y) in zip(p, q)]) ** 0.5
			if int(d) == d:
				r += 1
print(r // 2)


(n, d) = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n):
	for j in range(i):
		ans += (sum(((a - b) ** 2 for (a, b) in zip(x[i], x[j]))) ** 0.5).is_integer()
print(ans)


(n, d) = map(int, input().split())
import numpy as np
xlist = [list(map(int, input().split())) for i in range(n)]
xarray = np.array(xlist)
ans = 0
for i in range(n):
	for j in range(i + 1, n):
		if np.linalg.norm(xarray[i] - xarray[j]) == int(np.linalg.norm(xarray[i] - xarray[j])):
			ans += 1
print(ans)


(N, D) = map(int, input().split())
a = [input().split() for i in range(N)]
c = 0
for i in range(N - 1):
	for j in range(i + 1, N):
		b = 0
		for m in range(D):
			b += (int(a[i][m]) - int(a[j][m])) ** 2
		if b ** 0.5 == float(int(b ** 0.5)):
			c += 1
print(c)


from math import sqrt
(N, D) = [int(i) for i in input().split()]
XS = [list((int(i) for i in input().split())) for _ in range(N)]
cnt = 0
for i in range(N):
	for j in range(i + 1, N):
		if sqrt(sum(((y - z) ** 2 for (y, z) in zip(XS[i], XS[j])))).is_integer():
			cnt += 1
print(cnt)


from numpy import array
from numpy.linalg import norm
(n, d) = map(int, input().split())
X = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		if norm(array(X[i]) - array(X[j])).is_integer():
			ans += 1
print(ans)


(N, D) = [int(i) for i in input().split()]
X = []
for i in range(N):
	X += [[int(i) for i in input().split()]]
a = 0
for i in range(N):
	for j in range(i):
		y = 0
		for k in range(D):
			y += (X[i][k] - X[j][k]) ** 2
		if y == int(y ** 0.5) ** 2:
			a += 1
print(a)


(N, D) = [int(i) for i in input().split()]
xs = [[int(i) for i in input().split()] for _ in range(N)]
res = 0
for i in range(len(xs)):
	for j in range(i):
		d = sum(((xs[i][k] - xs[j][k]) ** 2 for k in range(D))) ** 0.5
		if d.is_integer():
			res += 1
print(res)


(n, d) = (int(x) for x in input().split())
x = [[int(x) for x in input().split()] for i in range(n)]
c = 0
for i in range(n):
	for j in range(i + 1, n):
		sum = 0
		for k in range(d):
			sum += (x[i][k] - x[j][k]) ** 2
		dis = sum ** 0.5
		if dis.is_integer():
			c += 1
print(c)


(n, d) = map(int, input().split())
dots = []
ans = 0
for _ in range(n):
	t = list(map(int, input().split()))
	if len(dots) != 0:
		for l in dots:
			a = [(y - z) ** 2 for (y, z) in zip(t, l)]
			if (sum(a) ** 0.5).is_integer():
				ans += 1
	dots.append(t)
print(ans)


(N, D) = map(int, input().split())
L = [list(map(int, input().split())) for i in range(N)]
n = 0
for i in range(N):
	for j in range(i):
		DD = 0
		for k in range(D):
			DD += (L[i][k] - L[j][k]) ** 2
		if any((n ** 2 == DD for n in range(1, 128))):
			n += 1
print(n)


f = lambda : map(int, input().split())
(n, d) = f()
x = [list(f()) for _ in range(n)]
print(sum((sum(((s - t) ** 2 for (s, t) in zip(x[i], x[j]))) ** 0.5 % 1 == 0 for j in range(n) for i in range(j))))


(n, d) = list(map(int, input().split()))
x = []
for i in range(n):
	p = list(map(int, input().split()))
	x.append(p)
ans = 0
for i in range(len(x) - 1):
	for j in range(i + 1, len(x)):
		dis = 0
		for k in range(d):
			dis += (x[i][k] - x[j][k]) ** 2
		if int(dis ** (1 / 2)) == dis ** (1 / 2):
			ans += 1
print(ans)


(n, d) = map(int, input().split())
X = []
for _ in range(n):
	X.append([int(x) for x in input().split()])
ans = 0
for i in range(n):
	for j in range(i):
		s = sum(((X[i][k] - X[j][k]) ** 2 for k in range(d)))
		if (s ** 0.5).is_integer():
			ans += 1
print(ans)


(n, d) = map(int, input().split())
l = []
cnt = 0
for _ in range(n):
	l.append(list(map(int, input().split())))
for i in range(n - 1):
	for j in range(i + 1, n):
		calc = 0
		for h in range(d):
			calc += (l[i][h] - l[j][h]) ** 2
		if int(calc ** 0.5) == calc ** 0.5:
			cnt += 1
print(cnt)


import math
(n, d) = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
s = 0
for i in range(n):
	for j in range(n):
		if i <= j:
			continue
		s += math.sqrt(sum([(y - z) ** 2 for (y, z) in zip(x[i], x[j])])).is_integer()
print(s)


(n, d) = map(int, input().split())
x = list((list(map(int, input().split())) for _ in range(n)))
ans = 0
for i in range(len(x)):
	for j in range(i + 1, len(x)):
		dist = sum(((x - y) ** 2 for (x, y) in zip(x[i], x[j]))) ** 0.5
		if dist.is_integer():
			ans += 1
print(ans)


(N, D) = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N):
	for j in range(i + 1, N):
		if (sum([(X[i][k] - X[j][k]) ** 2 for k in range(D)]) ** 0.5).is_integer():
			ans += 1
print(ans)


(n, d) = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
An = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		c = 0
		for k in range(d):
			c += (x[i][k] - x[j][k]) ** 2
		if c ** 0.5 % 1 == 0:
			An += 1
print(An)