Problem:
 Score : 200 points    Problem Statement 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 1 3 2
1 2
5 5
-2 8      Sample Output 1 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.        Sample Input 2 3 4
-3 7 8 2
-12 1 10 2
-2 8 9 3      Sample Output 2 2       Sample Input 3 5 1
1
2
3
4
5      Sample Output 3 10

Solution (Python):
import math
N, D = map(int, input().split())
X_l = []
for i in range(N):
    X_l.append([int(x) for x in input().split()])

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        dist = 0.0
        for d in range(D):
            dist+=(X_l[i][d]-X_l[j][d])**2
        dist = math.sqrt(dist)
        if dist.is_integer():
            cnt+=1
print(cnt)

Solution (Python):
import math

def distance(x,y):
    sum = 0
    for i in range(d):
        sum += (x[i] - y[i]) ** 2
    return math.sqrt(sum)

n, d = list(map(int, input().split()))
x = []
memoize = []
count = 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 or ((i,j) in memoize) or ((j, i) in memoize):
            continue

        if float.is_integer(distance(x[i], x[j])):
            count += 1

count = count // 2
print(count)

Solution (Python):
import math

N,D = list(map(int, input().split()))
list_X = []
ans = 0

for i in range(N):
    Xi = list(map(int, input().split()))
    list_X.append(Xi)

for i in range(N-1):
    for j in range(i+1,N):
        
        list_of_squares = [(list_X[i][k]-list_X[j][k])**2 for k in range(D)]
        sum_of_squares = sum(list_of_squares)
        distance = math.sqrt(sum_of_squares)

        if distance.is_integer() == True:
            ans+=1
        
print(ans)

Solution (Python):
import numpy

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

l = []
for v in range(n):
    l.append(list(map(int, input().split())))

ans = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        a = numpy.array(l[i])
        b = numpy.array(l[j])
        c = numpy.linalg.norm(b - a)
        if (c.is_integer()):
            ans += 1

print(ans)

Solution (Python):
import numpy

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

l = []
for v in range(n):
    l.append(list(map(int, input().split())))

ans = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        if i == j:
            continue
        a = numpy.array(l[i])
        b = numpy.array(l[j])
        c = numpy.linalg.norm(b - a)
        if (c.is_integer()):
            ans += 1

print(ans)

Solution (Python):
import math
N, D = map(int, input().split())

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

count = 0
for i in range(N - 1):
  for j in range(i + 1, N):
    d = 0
    for k in range(D):
      d += (points[i][k] - points[j][k]) ** 2
    d = math.sqrt(d)
    if (d == math.floor(d)):
      count += 1

print(count)

Solution (Python):
import numpy as np
N,D= list(map(int, input().split()))
A = []
ans = 0

for i in range(N):
    x = np.array(list(map(int, input().split())))
    A.append(x)
    
for i in range(N):
    for j in range(i+1,N):
        dist = np.linalg.norm(A[i]-A[j])
        if dist == int(dist):
            ans += 1

print(ans)

Solution (Python):

def judge_dist(i,j,P,D):
    dist = 0
    for k in range(D):
        dist += (P[i][k] - P[j][k])**2
    square = dist**(1/2)
    if square - int(square) == 0:
        return 1
    else:
        return 0 

def main():
    n,D=map(int,input().split())
    P=[list(map(int,input().split())) for _ in range(n)]
    res = 0
    for i in range(n):
        for j in range(n):
            if i < j:
                res += judge_dist(i,j,P,D)  
    print(res)

main()

Solution (Python):
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(n):
        if i >= j:
            continue
        dist = 0
        for k in range(d):
            dist += (x[i][k] - x[j][k]) ** 2
        for k in range (200):
            if dist == k**2:
                ans += 1
print(ans)

Solution (Python):
import math


def is_distance_integer(p1, p2):
    n = len(p1)

    total = 0
    for i in range(n):
        total += ((p1[i] - p2[i])**2)

    dist = int(math.sqrt(total))

    return (dist**2) == total


def count_pairs(points):
    cnt = 0
    n = len(points)

    for i in range(n):
        for j in range(i + 1, n):
            if is_distance_integer(points[i], points[j]):
                cnt += 1

    return cnt


def main():
    N, D = map(int, input().split())

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

    ans = count_pairs(points)

    print(ans)


main()

Solution (Python):

import math

def calc(x1, x2):
    ans = 0
    for i in range(len(x1)):
        ans += (x1[i]-x2[i])**2
    return float(math.sqrt(ans))

def solve():
    N, D = list(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):
            ret = calc(X[i], X[j])
            if ret.is_integer():
                ans += 1

    print(ans)



if __name__ == "__main__":
    solve()

Solution (Python):
n, d = map(int, input().split())

mat = list()
for i in range(n):
    mat.append(list(map(int, input().split())))

total = 0
for a in range(n-1):
    for b in range(a+1, n):
        dist2 = 0
        for dx in range(d):
            d2 = mat[a][dx]-mat[b][dx]
            dist2 += d2*d2
        dist = dist2**0.5
        
        if dist - int(dist) < 10**-6:
            total += 1
print(total)

Solution (Python):
n,d = map(int,input().split(" "))
ar = []
count = 0
for i in range(n):
    l = list(map(int,input().split(" ")))
    ar.append(l)
for i in range(n):
    for j in range(i+1,n):
        c = 0
        for k in range(d):
            c += (ar[i][k] - ar[j][k]) ** 2
        for l in range(0,c+1):
            if l ** 2 == c:
                count += 1
print(count)

Solution (Python):
N, D = map(int, input().split())
X = [ list(map(int, input().split())) for _ in range(N) ]

sq_list = [ (n+1)**2 for n in range(400)]
cnt = 0
for i in range(N):
    for j in range(i+1, N):
        sq_d = sum([ (X[i][k] - X[j][k])**2 for k in range(D)] )
        if sq_d in sq_list:
            cnt += 1
print(cnt)

Solution (Python):
import numpy as np

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

points = []

cnt = 0

for _ in range(n):
  point = np.array(list(map(int, input().split())))
  for p in points:
    d = point - p
    if np.sqrt((d * d).sum()).is_integer():
      cnt += 1
  
  points.append(point)
  
print(cnt)

Solution (Python):
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):
        res = 0
        a = np.array(x[i])
        b = np.array(x[j])
        dist = np.linalg.norm(b - a)
        if dist % 1 == 0:
            cnt += 1
print(cnt)

Solution (Python):
input_data=input()
N,D=map(int,input_data.split())
X=[] 
for n in range(N) :
    X_data=input() 
    X.append(list(map(int,X_data.split())))

output=0

for i in range(N):
    for j in range(N):
        if i>j:
            dist=0
            for y, z in zip(X[i],X[j]):
                dist=dist+(y-z)**2
            if int(dist**(1/2))==dist**(1/2):
                output=output+1
            else:
                output=output+0
        else: pass
print(output)

Solution (Python):
import math
N,D = map(int, input().split())

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

for i in range(0, N):
    for j in range(i+1,N):
        x = 0
        for a,b in zip(X[i],X[j]):
            x += (a-b)**2
        x = math.sqrt(x)
        if x.is_integer():
            count += 1

print(count)

Solution (Python):
import numpy as np
N,D = map(int,input().split())

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

t=0
for i in range(N):
    for j in range(i+1,N):
        d = (X[i]-X[j])**2
        d = np.sum(d)
        if d**0.5==int(d**0.5):
            t += 1

print(t)

Solution (Python):
from math import sqrt
n, d = map(int, input().split())
a = []
for i in range(n):
    a.append(list(map(int, input().split())))
sol = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        dist = 0
        for k in range(d):
            dist += pow(a[i][k] - a[j][k], 2)
        if sqrt(dist) == int(sqrt(dist)):
            sol += 1
print(sol)

Solution (Python):
import itertools
import math
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
ret = 0

def calc(a, b):
    s = 0
    for i in range(D):
        s += (a[i] - b[i]) ** 2
    s = math.sqrt(s)
    if s // 1 == s:
        return 1
    return 0

X = list(itertools.combinations(X,2))
for a, b in X:
    ret += calc(a, b)

print(ret)

Solution (Python):





def main():
  N,D = map(int, input().split())
  Xn = [list(map(int, input().split())) for _ in range(N)]

  sqrtset = [i**2 for i in range(1000)]

  ans = 0
  for i in range(N):
    for j in range(i+1,N):
      sm = 0
      for d in range(D):
        sm += (Xn[i][d]-Xn[j][d])**2
      if sm in sqrtset:
        ans += 1

  print(ans)


if __name__ == "__main__":
  main()

Solution (Python):
import math
N, D = map(int, input().split())
X =[]
distance = 0
ans = 0

for i in range(N):
    x = list(map(int, input().split()))
    X.append(x)

for i in range(N):
    for j in range(i + 1,N):
        for k in range(D):
            distance += (X[i][k] - X[j][k]) ** 2
        distance = math.sqrt(distance)
        if distance == math.ceil(distance):
            ans += 1
        distance = 0

print(ans)

Solution (Python):
import math

N, D = map(int, input().split())
point = []

for _ in range(N):
    point.append(tuple(map(int, input().split())))

ret = 0
for i in range(N):
    for j in range(i + 1, N):
        d = 0
        for a, b in zip(point[i], point[j]):
            d += (a - b) ** 2

        t = math.floor(math.sqrt(d))
        if t * t == d:
            ret += 1

print(ret)

Solution (Python):
n, d = list(map(int, input().split()))
p = []
ans = 0
for i in range(n):
  p.append(list(map(int, input().split())))
  for j in range(i):
    s = 0
    for k in range(d):
      s += (p[i][k] - p[j][k]) ** 2
    t = int(s ** 0.5 + 1e-7)
    if t * t == s:
      ans += 1
print(ans)

Solution (Python):
_,*x=open(0);print(sum(sum(eval(i+'-'+j)**2for i,j in zip(a.split(),b.split()))**.5%1==0for a in x for b in x)-len(x)>>1)

Solution (Python):
_,*x=open(0);print(sum(sum(eval(i+'-'+j)**2for i,j in zip(a.split(),b.split()))**.5%1==0for a in x for b in x)-len(x)>>1)

Solution (Python):
import math

N,D = list(map(int, input().split(" ")))
X = []

while True:
    try:
        X.append(list(map(int, input().split(" "))))
    except:
        break

def calc_dist(Y,Z):
	ans = 0
	for y, z in zip(Y,Z):
		ans += (y-z)**2
	return math.sqrt(ans)

ans = 0
for i in range(N-1):
	for j in range(i+1, N):
		dist = calc_dist(X[i], X[j])
		if dist.is_integer():
			ans += 1

print(ans)

Solution (Python):
_,*x=open(0);print(sum(sum((int(i)-int(j))**2for i,j in zip(a.split(),b.split()))**.5%1==0for a in x for b in x)-len(x)>>1)

Solution (Python):
N,D = map(int,input().rstrip().split())

maplist = []
for i in range(N):
    maplist.append(list(map(int,input().split())))
count = 0
for i in range(N-1):

    for j in range(i+1,N):
        dis = 0
        for k in range(D):
            dis += (maplist[i][k] - maplist[j][k]) ** 2
        dis = dis ** 0.5
        if float(int(dis)) == dis:
            count += 1
print(count)

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

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

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

Solution (Python):
n, d = map(int, input().split())
li = [list(map(int, input().split())) for i in range(n)]

cnt = 0

for i in range(len(li) - 1):
  for j in range(i+1, len(li)):
    total = 0
    for k in range(d):
      total += (li[i][k] - li[j][k])**2
    
    f = (total**0.5)
    if f.is_integer():
      cnt += 1
print(cnt)

Solution (Python):


import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n,d = [int(i) for i in readline().split()]
x = [[int(i) for i in readline().split()] for _ in range(n)]

sq = {i*i for i in range(1000)}

ans = 0
for i in range(n):
    for j in range(i+1,n):
        dist = sum((x[i][k] - x[j][k])**2 for k in range(d))
        if dist in sq: ans += 1


print(ans)

Solution (Python):
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)

Solution (Python):
import sys
def d(v1,v2):
    r = 0
    for x,y in zip(v1,v2):
        r += (x-y)**2
    if r == int(r**0.5) * int(r**0.5):
        return True
    return False


N, D = map(int, input().split())
vs = []
for line in sys.stdin:
    vs.append(list(map(int, line.split())))

rr = 0
for i in range(N):
    for j in range(N-i-1):
        if d(vs[i], vs[i+j+1]):
            rr += 1
print(rr)

Solution (Python):
n, d = input().split(" ")
p = [[int(i) for i in input().split()] for i in range(int(n))]
counter = 0
for i in range(int(n)):
    for j in range(int(n)):
        if i > j or i == j:
            continue
        else:
            dist = 0
            for k in range(int(d)):
                dist += (p[i][k] - p[j][k]) ** 2
            if (dist ** (1 / 2)).is_integer():
                counter += 1
print(counter)

Solution (Python):
import sys
from math import sqrt

def dist(I, J, D):
    d = 0
    for k in range(D):
        d += pow(I[k] - J[k], 2)
    if int(sqrt(d)) ** 2 == d: return 1
    else: return 0

def solve():
    input = sys.stdin.readline
    N, D = map(int, input().split())
    X = [[int(i) for i in input().split()] for n in range(N)]
    count = 0
    for i in range(N-1):
        for j in range(i + 1, N):
            count += dist(X[i], X[j], D)
    print(count)

    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
import math

s = input().split(" ")
n = int(s[0])
d = int(s[1])
list = []
count = 0
for i in range(n):
  list.append([float(a) for a in input().split(" ")])
for i1 in range(n):
  for i2 in range(i1, n):
    if i1 != i2:
      dist = 0.0
      for j in range(d):
        dist += (list[i1][j] - list[i2][j]) * (list[i1][j] - list[i2][j])
      sqrt = math.sqrt(dist)
      if sqrt.is_integer():
        count += 1
print(count)

Solution (Python):
N,D = map(int,input().split())
li =[]
import math
def dist(a,b):
    li2 = []
    for k in range(D):
        li2.append((a[k]-b[k])**2)
    return math.sqrt(sum(li2))
for _ in range(N):
    X = list(map(int,input().split()))
    li.append(X)
cnt = 0
for i in range(N):
    for j in range(N):
        x = li[i]
        y = li[j]
        dis = dist(x,y)
        if dis == 0:
            pass
        else:
            if dis.is_integer():
                cnt +=1
print(int(cnt/2))

Solution (Python):
import math
firstvar = input()
n = int(firstvar.split(" ")[0])
d = int(firstvar.split(" ")[1])
current = 0;
points = []
while current < n:
    points.append(input().split(" "))
    current = current + 1
current = 0
answer = 0
done = []
while current < n:
    current2 = 0
    while current2 < n:
        if current2 != current and not [current, current2] in done:
            total = 0
            current3 = 0
            while current3 < d:
                total = total + pow(int(points[current][current3]) - int(points[current2][current3]), 2)
                current3 = current3 + 1
            total = math.sqrt(total)
            if total == int(total):
                answer += 1
            done.append([current2, current])
        current2 = current2 + 1
    current = current + 1
print(answer)

Solution (Python):
N, D = map(int ,input().split())
li = []
for i in range(N):
    l = list(map(int, input().split()))
    li.append(l)
count = 0

for i in range(N-1):
    for j in range(N-1-i):
        a = 0
        for k in range(D):
            a += (li[i][k]-li[j+i+1][k])**2
        a = a**.5
        if a%1 == 0:
            count += 1

print(count)

Solution (Python):
import math
N, D = map(int, input().split())
X = []
for i in range(N):
    X.append(list(map(int, input().split())))
counter = 0
set256 = {i ** 2 % 256 for i in range(256)}
for i in range(N - 1):
    for j in range(N - i - 1):
        d = 0
        for k in range(D):
            d += (X[i][k] - X[i + j + 1][k]) ** 2
        if {d % 256} & set256 != set():
            r = math.sqrt(d)
            if r == int(r):
                counter += 1
print(counter)

Solution (Python):
N, D = map(int,input().split())
dots = []
for i in range(N):
  dot = [int(v) for v in input().split()]
  dots.append(dot)

answer = 0
for i in range(N-1):
  for j in range(i+1,N):
    d1,d2 = (dots[i],dots[j])
    distance = (sum([(v1-v2)**2 for v1,v2 in zip(d1,d2)]))**0.5
    if distance.is_integer():
      answer += 1
print(answer)

Solution (Python):
args = input().split()
n = int(args[0])
d = int(args[1])
points = []
for i in range(n):
    points.append([int(p) for p in input().split()])


def isSquare(n):
    if n == 1:
        return True
    for i in range(2, n + 1):
        tmp = 0
        while n % i == 0:
            n = n // i
            tmp += 1
        if tmp % 2 != 0:
            return False
        if n == 1:
            return True

cnt = 0
for i in range(n):
    left = points[i]
    for j in range(i + 1, n):
        right = points[j]
        tmp = []
        for p in range(d):
            tmp.append(left[p] - right[p])
        dis = 0
        for k in tmp:
            dis += k ** 2
        if isSquare(dis):
            cnt += 1
        
print(cnt)

Solution (Python):
import numpy as np

n, d = map(int, input().split())
s = [np.asarray(list(map(int, input().split()))) for i in range(n)]

counter = 0

for i in range(n):
    for j in range(i+1, n):
        ans = np.sqrt(np.sum((s[i] - s[j]) ** 2))
        if ans == int(ans):
            counter += 1

print(counter)

Solution (Python):
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):
		il, jl = X[i], X[j]
		distance = 0
		for d in range(D):
			distance += (il[d] - jl[d])** 2
		distance **= 0.5
		
		if distance == int(distance):
			count += 1
print(count)

Solution (Python):



from itertools import combinations
import math

IA = lambda: [int(x) for x in input().split()]
IM = lambda N: [IA() for _ in range(N)]

N, D = IA()
X = IM(N)

ans = 0
for x, y in combinations(X, 2):
    t = sum((u - v)**2 for u,v in zip(x, y))
    ans += math.sqrt(t).is_integer()
print(ans)

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

ans = 0
for i in range(n):
    for k in range(i+1,n):
        dist = 0
        for j in range(d):
            dist += (x[i][j]-x[k][j])**2
        if dist == (math.floor(dist**0.5))**2:
            ans += 1
print(ans)

Solution (Python):



from itertools import combinations
import math

IA = lambda: [int(x) for x in input().split()]
IM = lambda N: [IA() for _ in range(N)]

N, D = IA()
X = IM(N)

ans = 0
for x, y in combinations(X, 2):
    t = sum((u - v)**2 for u,v in zip(x, y))
    ans += int(math.sqrt(t))**2 == t
print(ans)

Solution (Python):

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

def distance(j_list, i_list):
 n = len(j_list)

 dist2 = 0
 
 for k in range(n):
   dist2 = dist2 + (j_list[k] - i_list[k])**2
   
 dist = dist2 ** 0.5
 return dist

nd_list = []
for i in range(n) :
  n_i = list(map(int, input().split()))
  nd_list.append(n_i)

count = 0

for i in range(n-1) :
  for j in range(i+1,n):
   dist = distance(nd_list[j], nd_list[i])
   dist_int = int(dist)
   if (dist - dist_int) == 0 :
     count = count + 1

print(count)

Solution (Python):

import math
N, D = map(int, input().split())
s = []
for i in range(N):
    s += [list(map(int, input().split()))]
count = 0
for i in range(N):
    for j in range(i + 1, N):
        x = 0.0
        for a in range(D):
            x += abs((s[i][a]- s[j][a])**2)
        b = math.sqrt(x)
        if (b.is_integer()):
            count+=1
print(count)

Solution (Python):
N,D = map(int,input().split())
position = []
for i in range(N):
    position.append(input().split())

import math
def distance(vector1,vector2):
    sum = 0
    for i in range(D):
        sum += (float(vector1[i])-float(vector2[i]))**2
    return math.sqrt(sum)

ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        if distance(position[i],position[j]).is_integer():
            ans += 1

print(ans)

Solution (Python):
n,d=map(int,input().split())
x=[[int(i) for i in input().split()]for i in range(n)]

cnt=0
for i in range(n-1):
    for j in range(i,n):
        if i==j:
            pass

        else:
            ans=0

            for y,z in zip(x[i],x[j]):
                ans+=(y-z)**2
            if pow(ans,1/2) == ans//pow(ans,1/2):
                cnt+=1

print(cnt)

Solution (Python):
import itertools
import numpy

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

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


cnt = 0
grid2 = list(itertools.combinations(grid, 2))
for i in grid2:
    x = numpy.array(i[0])
    y = numpy.array(i[1])
  
    dis = numpy.linalg.norm(y - x)
    
    if (dis.is_integer()):
        
        cnt += 1

  
print(cnt)

Solution (Python):
import math

n,m = [int(i) for i in input().split()]
table = [[int(i) for i in input().split()] for n in range(n)]

count = 0

for i in range(n):
    for j in range(i+1,n,1):
        distance = 0
        total = 0
        for k in range(m):
            total += (table[i][k] - table[j][k]) ** 2
        distance = math.sqrt(total)
        if distance.is_integer() == True:
            count += 1

print(count)

Solution (Python):
N, D = map(int, input().split())
zahyo = [list(map(int, input().split())) for _ in range(N)]

ans = 0
for i in range(N):
    for j in range(i+1, N):
        distance = (sum([(a-b)**2 for a, b in zip(zahyo[i], zahyo[j])]))**(1/2)
        if distance == int(distance):
            ans += 1
print(ans)

Solution (Python):
N, D = map(int, input().split())
X = [[int(x) for x in input().split()] for _ in range(N)]

def issq(n):
    """n is a square number."""
    for i in range(n + 1):
        if i * i == n:
            return True
        if i * i > n:
            return False

def distsq(X, Y):
    return sum((x - y) ** 2 for x, y in zip(X, Y))

n = sum(1 for i in range(len(X))
          for j in range(i + 1, len(X))
          if issq(distsq(X[i], X[j])))

print(n)

Solution (Python):
import sys
import math
import numpy as np


def input():
    return sys.stdin.readline().rstrip()


def dist(y, z, d):
    ret = 0.0
    for i in range(d):
        ret += pow(y[i] - z[i], 2)
    return pow(ret, 0.5)


def main():
    n, d = [int(e) for e in input().split()]
    x = [[int(e) for e in input().split()] for _ in range(n)]

    ans = 0
    for i in range(n):
        for j in range(i + 1, n):
            dist_yz = dist(x[i], x[j], d)
            if math.ceil(dist_yz) == math.floor(dist_yz):
                ans += 1
    print(ans)


main()

Solution (Python):
import math

def distance(a,b,D):
    sum = 0
    for i in range(D):
        sum += (a[i]-b[i]) ** 2
    tmp = math.sqrt(sum)
    if tmp % 1 == 0:
        return 1
    else:
        return 0 

N,D = map(int,input().split())
X = []
count = 0

for i in range(N):
    tmp = list(map(int,input().split()))
    X.append(tmp)

for i in range(N-1):
    for j in range(i+1,N):
        
        count += distance(X[i],X[j],D)

print(count)

Solution (Python):
from math import sqrt
N, D = map(int, input().split(' '))
 
coordinate_list = list()
 

for i in range(N):
    coordinate = list(input().split())
    coordinate = list(map(int, coordinate))
    coordinate_list.append(coordinate)
 
def make_dis_list(D, coordinate_list):
    distance_list = list()
    for i, coordinate in enumerate(coordinate_list):
        for j in range(i+1, N):
            distance_list.append(measure_distance(coordinate, coordinate_list[j], D))
    return distance_list
 
def measure_distance(a, b, D):
    square_dist = 0
    for i in range(D):
        square_dist += (a[i] - b[i])**2
    return sqrt(square_dist)
 
def int_counter(nums):
    counter = 0
    for num in nums:
        if int(num) == num: counter += 1
    return counter
 
distance_list = make_dis_list(D, coordinate_list)
print(int_counter(distance_list))

Solution (Python):
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):
    tmp = 0
    for k in range(D):
      tmp += abs(X[i][k]-X[j][k])**2
    tmp = tmp**0.5
    if tmp == int(tmp):
      ans += 1
print(ans)

Solution (Python):
squares = []
for i in range(0, 16001):
	squares.append(i*i)
N, D = map(int, input().split())
X = []
for i in range(0, N):
	X.append(list(map(int, input().split())))
cnt = 0
for i in range(0, N):
	for j in range(i+1, N):
		sqdist = 0
		for k in range(0, D):
			sqdist += (X[i][k]-X[j][k])**2
		if sqdist in squares:
			cnt += 1
print(cnt)

Solution (Python):
from math import sqrt
N, D = map(int, input().split())
xs = [list(map(int, input().split())) for i in range(N)]

ans = 0
for i in range(N):
    for j in range(i+1, N):
        dist_sum = sum([ (xs[i][k] - xs[j][k])**2 for k in range(D)])
        dist = sqrt(dist_sum)
        if dist % 1 == 0:
            ans += 1
print(ans)

Solution (Python):
n, d = map(int, input().split())
dots = [list(map(int, input().split())) for _ in range(n)]

def culc_dist(dot1, dot2):
    dist = 0
    for i in range(len(dot1)):
        dist += (dot1[i] - dot2[i]) ** 2
    dist = dist ** (0.5)
    return dist

ans = 0

for i in range(n):
    for j in range(i + 1, n):
        dist = culc_dist(dots[i], dots[j])
        if dist.is_integer():
            ans += 1

print(ans)

Solution (Python):
import itertools
import math

def q37(n, d, x):
    count = 0
    for i in itertools.combinations(x, 2):
        c = 0
        for l in range(d):
            c += (i[0][l] - i[1][l])**2

        if math.sqrt(c).is_integer():
            count += 1
        
    return count

N, D = [int(i) for i in input().split()]

x = []
for n in range(N):
    x.append([int(i) for i in input().split()])

print(q37(N, D, x))

Solution (Python):
import itertools
import math

dist = lambda X,Y: math.sqrt(sum((x-y)**2 for x,y in zip(X,Y)))

def solve():
    N, D = [int(s) for s in input().split() if s]
    X = []
    cnt = 0
    for _ in range(N):
        X.append([int(s) for s in input().split() if s])
    for x1,x2 in itertools.combinations(X,2):
        if dist(x1,x2).is_integer():
            cnt+=1
    print(cnt)

solve()

Solution (Python):
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)

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):
		dist = 0
		for k in range(D):
			dist += (X[i][k] - X[j][k]) ** 2
			
		if dist == int(dist ** 0.5) ** 2:
			count += 1
		
print(count)

Solution (Python):


import sys
import copy
import math

sys.setrecursionlimit(1000000)





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

X = [[int(x) for x in input().split()] for i in range(N)]

ans = 0


def isSquared(n):
    return n == math.floor(math.sqrt(n)) ** 2


for i in range(N):
    for j in range(N):
        if i < j:
            ssum = 0
            for k in range(D):
                ssum += (X[i][k] - X[j][k]) ** 2
            ans += isSquared(ssum)


print(ans)

Solution (Python):
import operator

N, D = map(int, input().split())
points = []
for n in range(N):
    points.append(tuple(map(int, input().split())))

o = 0
for n in range(N):
    for j in range(n+1, N):
        dist = sum(map(operator.pow, list(map(operator.sub, points[n], points[j])), [2]*D))**(1/2)
        if dist == int(dist):
            o += 1
print(o)

Solution (Python):
from itertools import combinations
import numpy as np


n, d = map(int, input().split())
vals = [[int(i) for i in input().split()] for _ in range(n)] 

result=0
for i, j in combinations(vals, 2):
    a = np.array(i)
    b = np.array(j)
    dist = (abs(sum((a-b)**2)))**0.5
    if dist.is_integer():
        result+=1
    

print("{}".format(result))

Solution (Python):
import sys, itertools, collections
sys.setrecursionlimit(10000)

read_ints = lambda: list(map(int, input().split()))
read_int  = lambda: int(input())

SQS = {i * i for i in range(127)}

n, d = read_ints()
p = [read_ints() for _ in range(n)]

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        dist_sq = sum(
            (p[i][k] - p[j][k]) * (p[i][k] - p[j][k])
            for k in range(d)
        )
        if dist_sq in SQS:
            ans += 1

print(ans)

Solution (Python):
import numpy as np
def solve(n, d, x):
    x = np.asarray(x)
    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            y = x[i]
            z = x[j]
            d = np.linalg.norm(y-z)
            if abs(int(d)**2 - d**2) < 1e-5:
                ans += 1
    return ans

n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
print(solve(n, d, x))

Solution (Python):
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):
    tmp = 0
    for k in range(D):
      tmp += abs(X[i][k]-X[j][k])**2
    tmp = tmp**0.5
    if tmp == int(tmp):
      ans += 1
print(ans)

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