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 = []
for i in range(N):
    temp = list(map(int, input().split()))
    X.append(temp)

ans = 0
for i in range(N):
    for j in range(i+1,N):
        dist = 0
        for d in range(D):
            dist += (X[i][d] - X[j][d])**2
        dist = math.sqrt(dist)
        if dist == float(int(dist)):
            ans += 1

print(ans)

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

count=0
for i in range(N-1):
  for j in range(i+1,N):
    dist=0
    for d in range(D):
      dist+=(List[i][d]-List[j][d])**2
    dist=math.sqrt(dist)
    if int(dist)==dist:
      count+=1
print(count)

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

ans = 0

for i in range(N):
    src = my_list[i]
    for j in range(i + 1, N):
        dst = my_list[j]
        sum = 0
        for k in range(len(src)):
            sum += (src[k] - dst[k]) **2
        if float.is_integer(math.sqrt(sum)):
            ans += 1
print(ans)

Solution (Python):
import math
def calc_distance(c1,c2):
  sum1 = 0
  for a1,a2 in zip(c1,c2):
    sum1 += (a1-a2)**2
  
  return math.sqrt(sum1)

def is_it_int(num):
  
  if num/int(num)==1:
    return True
  else:
    return False

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


ans = 0
for i in reversed(range(n)):
  for j in range(i):
    if is_it_int(calc_distance(list_of_coordinates[i],list_of_coordinates[j])):
      ans += 1
      
print(ans)

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

import math
def calculate_dis(x1,x2,D):
    distance=0
    for d in range(D):
        distance+=(x1[d]-x2[d])**2
    return math.sqrt(distance)




count=0
for n in range(N):
    
    for m in range(n,N):
        if n==m:
            continue
        
        dis=calculate_dis(X[n],X[m],D)
        
        if dis%1==0:
            count+=1
print(count)

Solution (Python):
import math

N, D = [int(x) for x in 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 + 1, N):
        sum = 0
        for k in range(D):
            sum += (x[i][k] - x[j][k]) ** 2
        if math.sqrt(sum).is_integer():
            ans += 1


print(ans)

Solution (Python):
import math

N, D = [int(x) for x in 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 + 1, N):
        sum = 0
        for k in range(D):
            sum += (x[i][k] - x[j][k]) ** 2
        if math.sqrt(sum).is_integer():
            ans += 1


print(ans)

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

x_list = np.array([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):
        l = math.sqrt(np.sum((x_list[j]-x_list[i])**2))
        if l.is_integer():
            ans += 1
print(ans)

Solution (Python):
from itertools import combinations
from math import sqrt


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

comb_list = list(combinations(X_list, 2))
res = 0

for i in range(len(comb_list)):
    x1 = comb_list[i][0]
    x2 = comb_list[i][1]

    dst_elements = [(x1[i] - x2[i])**2 for i in range(len(x1))]
    dst = sqrt(sum(dst_elements))
    if dst.is_integer():
        res += 1

print(res)

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

import math

def get_dist(ary1, ary2):
	tot = 0
	for i in range(len(ary1)):
		tot += (ary1[i] - ary2[i]) ** 2
	return math.sqrt(tot)

cnt = 0
for i in range(N):
	for j in range(i + 1, N):
		_ = get_dist(X[i], X[j])
		if _ == int(_):
			cnt += 1
			
print(cnt)

Solution (Python):
import math

n, d = list(map(int, input().split(' ')))
x = []
ans = 0

for _ in range(n):
    vec = list(map(int, input().split(' ')))
    x.append(vec)
    for i in range(len(x) - 1):
        s = 0
        for j in range(d):
            s += (x[i][j] - x[len(x) - 1][j]) * (x[i][j] - x[len(x) - 1][j])
        if math.sqrt(s).is_integer():
            ans += 1

print(ans)

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

Solution (Python):

import math

n, d = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        t = math.sqrt(sum([(l[i][k] - l[j][k]) * (l[i][k] - l[j][k]) for k in range(d)]))
        if t == math.ceil(t):
            ans += 1
print(ans)

Solution (Python):
import math

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

point = []
for _ in range(n):
    x = list(map(int, input().split()))
    point.append(x)

cnt = 0
for i in range(n-1):
    for j in range(i+1, n):
        dist = 0
        for d in range(D):
            dist += (point[i][d] - point[j][d])**2

        dist = math.sqrt(dist)
        if int(dist) == dist:
            cnt += 1

print(cnt)

Solution (Python):
from math import sqrt
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):
        d = 0
        for k in range(D):
            d += (X[i][k]-X[j][k])**2
        if sqrt(d).is_integer():
            ans += 1
print(ans)

Solution (Python):
import math

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

def main(): 

    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):
            result = 0
            for k in range(d):
                result += abs(x[i][k] - x[j][k])**2

            if is_integer_num(math.sqrt(result)):
                cnt += 1

    print(cnt)




if __name__ == "__main__":
    main()

Solution (Python):
import sys, math
input=sys.stdin.readline

N,D=map(int,input().split())
points=list(tuple(map(int,input().split())) for _ in range(N))
count=0

for i1 in range(N-1):
    for i2 in range(i1+1,N):
        sum_sq=sum((points[i1][j]-points[i2][j])**2 for j in range(D))
        if math.sqrt(sum_sq)==int(math.sqrt(sum_sq)):
            count+=1

print(count)

Solution (Python):
N,D = map(int, input().split())
X  = []
for n in range(N):
    x = list(map(int, input().split()))
    X.append(x)
    
import numpy as np
def distance(a,b):
    dis = 0
    for i in range(D):
        dis += (a[i]-b[i])**2
    return np.sqrt(dis)

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

Solution (Python):
import numpy

n, d = map(int, input().split())
x = [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):
        a = numpy.array(x[i])
        b = numpy.array(x[j])
        num=numpy.linalg.norm(a-b)
        if num.is_integer() == True:
            cnt += 1
print(cnt)

Solution (Python):
from math import sqrt
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 = sum([(y-z)**2 for y, z in zip(x[i], x[j])])
        if sqrt(dis).is_integer():
            cnt += 1

print(cnt)

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

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

Solution (Python):
import numpy as np
from numpy import linalg as LA

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

counter = 0
    
for i in range(N-1):
    for j in range(N-i-1):
        if LA.norm(X[i]-X[i+j+1], 2).is_integer() == True:
            counter += 1
            
print(counter)

Solution (Python):

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

count = 0
for i in range(n):
    for j in range(i+1, n):
        sq_dist = 0
        for k in range(d):
            sq_dist += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k])
        dist = math.sqrt(sq_dist)
        if dist.is_integer():
            count += 1
print(count)

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):
        dis=0
        for k in range(d):
            dis += (x[i][k] - x[j][k])**2 
        if (dis**.5).is_integer():
            count+=1
print(count)

Solution (Python):
from sys import stdin

n, d = [int(x) for x in stdin.readline().rstrip().split()]

x_lst = []
for _ in range(n):
  x_lst.append([int(x) for x in stdin.readline().rstrip().split()])

def calc_distance(l1, l2):
  return sum([(l1[x]-l2[x])**2 for x in range(d)])**0.5
  
count = 0
for i in range(n):
  for j in range(n):
    if i < j:
      di = calc_distance(x_lst[i], x_lst[j])
      if di == int(di):
        count += 1

print(count)

Solution (Python):
n, d = list(map(int, input().split()))
v = [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 = 0
    for k in range(d):
      dist += (v[i][k]-v[j][k])**2
    dist = dist**(1/2)
    if dist.is_integer():
      ans += 1
print(ans)

Solution (Python):
import sys
from bisect import *
from collections import *
from heapq import *
from itertools import *
from math import *
from operator import *
import numpy as np

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N,D = map(int, input().split())
    XS = [list(map(int, input().split())) for _ in range(N)]
    ans = 0
    for i,j in combinations(XS, 2):
        total = sum([(x-y)**2 for x,y in zip(i,j)])
        if total == floor(sqrt(total))**2: ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
n,d=map(int,input().split())
v=[]
for i in range(n):
  v.append(np.array(list(map(int,input().split()))))
  
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    dist=np.linalg.norm(v[i]-v[j], ord = 2)
    if int(dist) == dist:
      ans += 1

print(ans)

Solution (Python):
N, D = map(int,input().split())
x = [[0]*D]*N
for i in range(N):
  x[i] = list(map(int,input().split()))

count = 0
for i in range(N-1):
  for j in range(i+1,N):
    dist = 0
    for m in range(D):
      dist += (x[i][m] - x[j][m]) **2
    if (dist ** 0.5) % 1 == 0:
      count += 1
print(count)

Solution (Python):
import math
n, d = map(int, input().split())
lst = [list(map(int, 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 += (lst[i][k] - lst[j][k]) ** 2
        if math.sqrt(dis).is_integer():
            cnt += 1
print(cnt)

Solution (Python):
import numpy as np

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

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

X_arr = np.array(X_lis)

count = 0

for i in range(N):
    for j in range(i+1, N):
        squared_d = np.sum((X_arr[i] - X_arr[j]) ** 2)
        if (squared_d)**(1/2) == int(squared_d**(1/2)):
            count += 1

print(count)

Solution (Python):
while True:
    try:
        N, D = map(int, input().split())
        P = []
        for i in range(N):
            P.append(list(map(int, input().split())))
            
        ans = 0
        for i in range(N-1):
            for j in range(i+1, N):
                distance = 0
                for k in range(D):
                    distance += (P[i][k] - P[j][k]) ** 2
                if distance == int(distance ** 0.5) ** 2:
                    ans += 1
        print(ans)
    except:
        break

Solution (Python):
import math
N,D = map(int,input().split())
L = [list(map(int, input().split())) for i in range(N)]
c = 0
for i in range(N):
    for j in range(i+1,N):
        di = 0
        for k in range(D):
            di += (L[i][k]-L[j][k])**2
        if math.sqrt(di).is_integer():
            c += 1 
print(c)

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

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

ans=0
for i in range(0,n):
  for j in range(i+1,n):
    dis=0
    for k in range(d):
      dis+=abs(X[i][k]-X[j][k])**2
    if math.sqrt(dis)==int(math.sqrt(dis)):
      ans+=1
print(ans)

Solution (Python):
import math
import itertools

if __name__ == '__main__':
    N, D = map(int, input().split())
    X = [list(map(int, input().split())) for _ in range(N)]
    count = 0
    for x in itertools.combinations(X,2):
        m = math.sqrt(sum( [ ((x[0][i] - x[1][i]) ** 2) for i in range(D)] ))
        if m.is_integer():
            count += 1
    print(count)

Solution (Python):
def distance(y,z):
    ans = 0
    for i,j in zip(y,z):
        ans += (i - j)**2
    return ans**0.5

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

for i in range(n-1):
    for j in range(i+1, n):
        tmp = distance(x_arr[i],x_arr[j])
        if tmp//1 == tmp:
            cnt += 1

print(cnt)

Solution (Python):
n, d = list(map(int, input().split()))
x = [list(map(int,input().split())) for _ in range(n)]
num = 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
        root = dis ** 0.5
        if root.is_integer():
            num += 1
print(num)

Solution (Python):
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-1):
    for j in range(i+1, n):
        distance = 0
        for k in range(d):
            distance += (x[i][k] - x[j][k]) ** 2 
        if math.sqrt(distance).is_integer():
            ans += 1
print(ans)

Solution (Python):
import numpy as np

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

for i in range(n):
    if i < n-1:
        for j in range(i+1, n):
            s = 0
            for t in range(d):
                s += np.power((x[j][t]-x[i][t]), 2)
            if np.sqrt(s).is_integer():
                ans += 1

print(ans)

Solution (Python):
def sq(x,y):
    tot = 0
    for i in range(D):
        tot += (x[i]-y[i])**2
    return tot
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):
        x = X[i]
        y = X[j]
        if abs(round(sq(x,y)**0.5,1)**2-sq(x,y))<10**(-8):
            cnt += 1
print(cnt)

Solution (Python):
import math
N,D=map(int,input().split())
d=[None]*N
for i in range(N):
  d[i]=list(map(int,input().split()))

ans=0
for i in range(N-1):
  for j in range(i+1,N):
    sum=0
    for p in range(D):
      sum=sum+(d[i][p]-d[j][p])**2
    if (math.sqrt(sum)).is_integer():
      ans=ans+1
print(ans)

Solution (Python):
import math
n, d = map(int, input().split())
x = [list(map(int,input().split())) for _ in range(n)]
counter = 0
for i in range(n):
    for j in range(i+1, n):
        dif = [(x[i][di] - x[j][di])**2 for di in range(d)]
        sumdif = sum(dif)
        if sumdif == int(math.sqrt(sumdif))**2:
            counter += 1
print(counter)

Solution (Python):
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):
    a = 0
    for d in range(D):
      a += (X[i][d]-X[j][d])**2
    for l in range(a+1):
      if l**2==a:
        ans+=1
print(ans)

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

Solution (Python):
import itertools

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

clist=list(itertools.combinations(x,2))
res=0
for c in clist:
  dist=sum([(c[0][i]-c[1][i])**2 for i in range(len(c[0]))])**0.5
  if dist==int(dist):
    res+=1
print(res)

Solution (Python):
from sys import exit, stderr, stdin
input = stdin.readline
def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return


def main():
    N,D = [int(n) for n in input().split()]
    ans = 0
    X = [[0 for __ in range(D)] for _ in range(N)]
    for i in range(N):
        X[i] = [int(n) for n in input().split()]
    
    for i in range(N):
        d = 0
        for j in range(i+1,N):
            d = sum([pow(y-z,2) for y,z in zip(X[i],X[j])])
            
            d **= 0.5
            if d/1 == d//1:
                ans += 1
    print(ans)
if __name__ == "__main__":
    main()

Solution (Python):
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-1):
    for j in range(i+1, n):
        s = 0
        for k in range(d):
            s += (x[i][k] - x[j][k]) ** 2
        if math.sqrt(s).is_integer():
            ans += 1
print(ans)

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

Solution (Python):
n, d = map(int, input().split())
a = [[int(i) for i in input().split()] for i in range(n)]
ans = 0
def dis(x,y):
    T = []
    for i in range(len(x)):
        T.append((x[i]-y[i])**2)
    return sum(T)
for i in range(n):
    for j in range(i+1,n):
        r = dis(a[i], a[j])
        for k in range(r + 1):
            if k ** 2 == r:
                ans += 1
print(ans)

Solution (Python):
import math
import numpy as np
n, d = map(int, input().split())
a = []
cnt = 0
for x in range(n):
    a.append(list(map(int, input().split())))
for i in range(len(a)):
    for j in range(len(a)):
        if i < j:
            dis = np.array(a[i]) - np.array(a[j])
            if np.linalg.norm(dis).is_integer():
                cnt += 1
print(cnt)

Solution (Python):
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):
  for j in range(i+1,n):
    temp = 0
    for k in range(d):
      temp += (x[i][k] - x[j][k]) ** 2
    l = math.sqrt(temp)
    if l.is_integer():
      ans += 1
print(ans)

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

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)

count =	0
for i in range(n):
    for j in range(i+1, n):
        dist = np.linalg.norm(x[i] - x[j])
        if dist == int(dist):
            count += 1

print(count)

Solution (Python):
n,d = map(int,input().split())
co = []
for i in range(n):
    co.append(tuple(int(j) for j in input().split()))
flag = 0
for i in range(n):
    for j in range(i+1,n):
        sq = 0
        for k in range(d):
            sq = sq + (co[i][k]-co[j][k])**2
        sqrt = sq**(1/2)
        if float(int(sqrt)) == sqrt:
            flag = flag + 1

print(flag)

Solution (Python):
import numpy as np
N,D=map(int,input().split())
A=[]
for i in range(N):
    B=list(map(int,input().split()))
    A.append(B)

all_diffs = np.expand_dims(A, axis=1) - np.expand_dims(A, axis=0)
degree_distance = np.sqrt(np.sum(all_diffs ** 2, axis=-1))

Q=0
for i in range(N):
    for j in range(N):
        if degree_distance[i][j].is_integer()==True:
            Q+=1
            
        
print(int((Q-N)/2))

Solution (Python):
n, d = input().split()
a = []

pair = 0
for i in range(int(n)):
    a.append(input().split())

for i in range(int(n)):
    for j in range(i+1, int(n)):
        t = 0
        for k in range(int(d)):
           
            t+=(int(a[i][k]) - int(a[j][k])) * (int(a[i][k]) - int(a[j][k]))

        t**=0.5
        if t == int(t):
            pair += 1
print(pair)

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

def jadge(one ,two):
    z = 0
    for i in range(d):
        z += (one[i] - two[i]) ** 2
    z = math.sqrt(z)
    if z == int(z):
        return 1
    else:
        return 0
for one in range(n-1):
    for two in range(one+1,n):
        ans += jadge(x[one], x[two])
print(ans)

Solution (Python):
from math import sqrt


def distance_calculator(coordinates1, coordinates2, d):
    distance = 0
    for i in range(d):
        distance += (coordinates1[i] - coordinates2[i]) ** 2
    return sqrt(distance)


n, d = map(int, input().split())
points = [[]] * n
for i in range(n):
    points[i] = list(map(int, input().split()))
answer = 0
for i in range(n):
    for j in range(i + 1, n):
        distance = distance_calculator(points[i], points[j], d)
        if int(distance) == distance:
            answer += 1
print(answer)

Solution (Python):
n,d = map(int,input().split())
def lens(a,b):
    s = 0
    for i,j in zip(a,b):
        s+=(i-j)**2
    return s**0.5
c = []
ans = 0
for _ in range(n):
    c.append(list(map(int,input().split())))
for i in range(n):
    for j in range(i):
        l = lens(c[i],c[j])
        if l == int(l):
            ans+=1
print(ans)

Solution (Python):
import sys
from math import ceil
from operator import itemgetter as get

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

def iinput():
    return int(input())

def finput():
    return float(input())

def tinput():
    return input().split()

def rinput():
    return map(int, tinput())

def rlinput():
    return list(rinput())

def nod(a, b):
    while b: 
        a, b = b, a % b
    return a
 
def calc(n, c, d):
    return n - n // c - n // d + n // (c * d // nod(c, d))   


def main():
    res, x = 0, []
    n, d = rinput()
    for i in range(n):
        x.append(rlinput())
     
    for o in range(n - 1):
        for u in range(o + 1, n):
            if ((sum((i - j) ** 2 for i, j in zip(x[o], x[u]))) ** 0.5).is_integer():
                res += 1
    print(res)
main()

Solution (Python):
import math

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

Solution (Python):
import math
n, d = map(int, input().split())
points = [0]*n

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

count = 0 
for i in range(n-1):
	for j in range(i+1, n):
		dist = math.sqrt(sum(pow(points[i][k] - points[j][k], 2) for k in range(d)))
		if dist == int(dist):
			count += 1
print(count)

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b



def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2



def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)



def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def func(x1, x2):
    r = 0
    for i in range(len(x1)):
        r += (x1[i] - x2[i]) ** 2

    a = int(sqrt(r))
    return a ** 2 == r or (a - 1) ** 2 == r or (a + 1) ** 2 == r


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

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

    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            ans += func(dot[i], dot[j])
    print(ans)


if __name__ == '__main__':
    main()

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

cnt = 0
for i in range(n):
    for j in range(i+1,n):
        dd = 0
        for d_ in range(d):
            diff = x[i][d_] - x[j][d_]
            dd += diff**2
        if math.sqrt(dd).is_integer():
            cnt += 1
        

print(cnt)

Solution (Python):
import math
n, d = map(int, input().split())
x = [None]*n
ans = 0

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

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
        res = math.sqrt(res)
        if res.is_integer():
            ans += 1
print(ans)

Solution (Python):
import math

n,d = map(int,input().split())
loc = [list(map(int,input().split())) for _ in range(n)]
dis = []
ans = 0
for i in range(n):
  for j in range(i+1,n):
    dis_k = 0
    for k in range(d):
      dis_k += (loc[i][k]-loc[j][k])**2
    dis.append(dis_k)
    
for d in dis:
  for i in range(1,math.ceil(math.sqrt(d))+1):
    if i**2 ==d:
      ans += 1
      break
    else:
      pass
    
print(ans)

Solution (Python):
N,D=map(int,input().split())
X=[list(map(int,input().split())) for i 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)

Solution (Python):
nd=list(map(int,input().split()))
listx=[]
count=0
for i in range(nd[0]):
    listx=listx+[list(map(int,input().split()))]
for i in range(nd[0]-1):
    for k in range(i+1,nd[0]):
        d2=0
        for n in range(nd[1]):
            d2+=(listx[i][n]-listx[k][n])**2
        if float.is_integer(d2**0.5)==True:
                count+=1
print(count)

Solution (Python):
nd=list(map(int,input().split()))
listx=[]
count=0
for i in range(nd[0]):
    listx=listx+[list(map(int,input().split()))]
for i in range(nd[0]-1):
    for k in range(i+1,nd[0]):
        d2=0
        for n in range(nd[1]):
            d2+=(listx[i][n]-listx[k][n])**2
        if float.is_integer(d2**0.5)==True:
                count+=1
print(count)

Solution (Python):
import math

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

ans=0

for i in range(n):
  for j in range(i+1,n):
    temp=0
    for k in range(d):
      temp+=(x[i][k]-x[j][k])**2
    
    temp=math.sqrt(temp)
    if temp==int(temp):
      ans+=1

print(ans)

Solution (Python):
import sys
import math
input = sys.stdin.readline
N,D = map(int, input().split())
ans = 0
point = [[] * N for _ in range(N)]
for i in range(N):
	point[i] = list(map(int, input().split()))

for i in range(N):
	for j in range(i+1,N):
		tmp = 0
		for k in range(D):
			tmp += (point[i][k]-point[j][k])*(point[i][k]-point[j][k])
		tmp = math.sqrt(tmp)
		if tmp.is_integer():
			ans += 1
print(ans)

Solution (Python):
from math import sqrt

count = 0
n, d = map(int, input().split())
x = [[int(xx) for xx in input().split()] for _ in range(n)]

for y in range(n - 1):
    for z in range(y + 1, n):
        if sqrt(sum((i - j) ** 2 for i, j in zip(x[y], x[z]))).is_integer():
            count += 1
print(count)

Solution (Python):
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):
        dist2 = 0
        for d in range(D):
            dist2 += (X[i][d] - X[j][d])**2
        dist = math.sqrt(dist2)
        if dist.is_integer():
            ans += 1

print(ans)

Solution (Python):
import sys
import math
from copy import deepcopy
from collections import deque
sys.setrecursionlimit(20000000)


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

    count = 0

    def diff(a, b):
        sm = 0
        for i in range(D):
            sm += ((a[i] - b[i]) ** 2)

        return sm

    for p in range(len(P) - 1):
        s = 0
        for x in range(p+1, len(P)):
            s = diff(P[p], P[x])

            if str(s**0.5)[-1] == '0':
                count += 1

    print(count)


if __name__ == '__main__':
    main()