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



Sample input:
3 2
1 2
5 5
-2 8


Sample output:
1

Submission status: Accepted

Solution code:
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
def func(A,B):
    a = 0
    for k in range(D):
        a += (A[k] - B[k])**2
    a = math.sqrt(a)
    return a
for i in range(N):
    for j in range(i,N):
        sum_x = 0
        int_x = 0
        if i == j:
            continue
        sum_x = func(X[i],X[j])
        int_x = int(sum_x)
        if sum_x == int_x:
            count += 1
print(count)

Submission status: Accepted

Solution code:
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):
        norm = 0
        for k in range(d):
            diff = abs(x[i][k] - x[j][k])
            norm += diff**2
        flag = 0
        for k in range(norm+1):
            if k**2 == norm:
                flag = 1
        if flag:
            ans += 1
print(ans)

Submission status: Accepted

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

for i in range(n-1):
    for s in range(i+1,n):
        dist = 0
        for j in range(d):
            dist += (x[i][j]-x[s][j])**2
        dist = mt.sqrt(dist)
        if dist.is_integer()==True:
            count += 1
print(count)

Submission status: Accepted

Solution code:
N,D = list(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(N):
    for j in range(i+1,N):        
        length = 0      
        for k in range(D):          
            diff = abs(X[i][k]-X[j][k])
            length += diff**2           
        l = 0            
        while l < length+1:
            if l**2 == length:
                count+=1
                break
            l+=1
print(count)

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
x = []

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

def distance(x, y):
  d = 0
  for i in range(len(x)):
    d += (x[i]-y[i])**2
  return d ** (1/2)

count = 0

for i in range(n):
  for j in range(i+1, n):
    if distance(x[i], x[j]) % 1 == 0:
      count += 1

print(count)

Submission status: Accepted

Solution code:
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')


N,D=map(int,input().split())
X=[list(map(int,input().split())) for _ in range(N)]
a=0
cnt=0

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

Submission status: Accepted

Solution code:
import math


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

Submission status: Accepted

Solution code:
import numpy as np

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

X = np.zeros((N, D), np.float)
for i in range(N):
  X[i,] = [int(x) for x in input().split()]

def dist(X1, X2):
  return np.linalg.norm(X1-X2)

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

Submission status: Accepted

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

def func(i,j):
	global list1
	global d
	cout = 0
	for k in range(d):
		cout += (list1[i][k] - list1[j][k])**2
	return math.sqrt(cout)

count = 0

for i in range(0,n-1):
	for j in range(i+1,n):
		judge = func(i,j)
		if judge.is_integer():
			count += 1
print(count)

Submission status: Accepted

Solution code:
from sys import stdin
import math
import itertools

n,d = [int(x) for x in stdin.readline().rstrip().split()]
li = [tuple(map(int,stdin.readline().rstrip().split())) for _ in range(n)]

li2 = list(itertools.combinations(li, 2))

point  = 0

for i in range(len(li2)):
    score = 0
    for j in range(d):
        score += int(li2[i][1][j] - li2[i][0][j])**2
    if round(math.sqrt(score)) - math.sqrt(score) == 0.0:
        point += 1
print(point)

Submission status: Accepted

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

count = 0
for a in range(N):
  for b in range(a+1, N):
    sumX = 0
    for c in range(D):
      sumX += (X[a][c]-X[b][c])**2
    if math.sqrt(sumX)%1 == 0:
      count += 1
print(count)

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
points = [list(map(int, input().split())) for _ in range(n)]
res = 0
for i in range(n):
    for j in range(i+1, n):
        l = sum(map(lambda x: x ** 2, [a - b for a, b in zip(points[i], points[j])]))
        for k in range(200):
            if l == k ** 2:
                res += 1
                break

print(res)

Submission status: Accepted

Solution code:
import math
x=list(input().split())
n=int(x[0])
d=int(x[1])
zahyou=[]
count=0
for i in range(n):
  zahyou.append(list(input().split()))
for i in range(n-1,0,-1):
  for j in range(i):
    total=0
    for k in range(d):
      total=total+(int(zahyou[i][k])-int(zahyou[j][k]))**2
    
    if math.sqrt(total).is_integer():
      count+=1
print(count)

Submission status: Accepted

Solution code:
import math

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

list_coordinates = [ [ int(i) for i in input().split() ] for j in range(N) ]

list_distance_between_pts = []


for i in range(N-1):
	for j in range(i+1, N):
		distance_square = 0
		for l in range(D):
			distance_square += (list_coordinates[i][l] - list_coordinates[j][l])**2
		
		distance = math.sqrt(distance_square)
		
		if distance.is_integer() == True:
			list_distance_between_pts.append(distance)

count_interger_distance = len(list_distance_between_pts)

print(count_interger_distance)

Submission status: Accepted

Solution code:
import math
n,d = map(int,input().split())
li = [list(map(int,input().split())) for i in range(n)]
cnt = 0
sum_d = 0
for i in range(n):
    for j in range(n):
        if i<j:
            ans = math.sqrt(sum(abs(li[i][k]-li[j][k])**2 for k in range(d)))
            if ans.is_integer() == True:
                cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import math

n,d=map(int,input().split())
ans=[]
cnt=0
for _ in range(n):
    ans.append(list(map(int,input().rstrip().split())))
for i in range(n):
    for j in range(n):
        if i >= j:
            continue
        else:
            result = math.sqrt(sum(abs(ans[i][k]-ans[j][k])**2 for k in range(d)))
            if result.is_integer():
                cnt += 1
            else:
                continue
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
n, d = map(int, input().split())
x = np.array([[int(i) for i in input().split(" ")] for j in range(n)])
c = 0
for i in range(1,n):
    t = x[:-1*i,:]-x[1*i:,:]
    t = np.sqrt(np.sum(t*t, axis=1))
    c += np.sum(t%1==0)
print(c)

Submission status: Accepted

Solution code:
n, d = [int(i) for i in input().split()]

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


count = 0
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

        if s ** 0.5 % 1 == 0:
            count += 1

print(count)

Submission status: Accepted

Solution code:
n,d = map(int,input().split())
x = [list(map(int,input().split())) for hoge in range(n)]
y = x
count = 0
tmp = 0
for i in range(n):
         for j in range(n):
                  for k in range(d):
                           tmp += (x[i][k] - y[j][k]) ** 2
                  if (tmp ** (1/2)).is_integer():
                           count += 1
                           tmp = 0
                  else:
                           tmp = 0
print((count-n)//2)

Submission status: Accepted

Solution code:
import numpy as np
import math
n,d = map(int,input().split())
a = []
for i in range(n):
    a.append([x for x in map(int,input().split())])

a = np.array(a)
ctn = 0
for i in range(0,n-1):
    for j in range(i+1,n):
        if np.sqrt(np.sum((a[i]-a[j])**2)) % 1 == 0:
            ctn +=1

print(ctn)

Submission status: Accepted

Solution code:
from itertools import combinations
from math import sqrt
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

res = 0
for Y,Z in combinations(X, 2):
    r = sqrt(sum((y-z)**2 for y,z in zip(Y,Z)))
    if r == float(int(r)):
        res += 1
print(res)

Submission status: Accepted

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

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

aaa_list = []
cnt = 0
#print(X_list)

for i in range(N):
    for j in range(i+1,N):
        for k in range(D):
            aaa_list.append(abs(X_list[i][k]-X_list[j][k])**2)
        judge_aaa = (sum(aaa_list))**0.5
        #print(judge_aaa)
        if judge_aaa.is_integer() :
            cnt +=1
        aaa_list.clear()

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
from itertools import combinations
n, d = [int(i) for i in sys.stdin.readline().split()]
xs = []
for i in range(n):
    xs.append([int(i) for i in sys.stdin.readline().split()])
cnt = 0
for (x, y) in combinations(xs, 2):
    if (math.sqrt(sum([(_x - _y)**2 for _x, _y in zip(x, y)])) % 1 == 0):
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import math

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

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

def distance(x, y):
    dist = 0
    for i in range(d):
        dist += (x[i] - y[i]) ** 2

    return round(math.sqrt(dist), 2)

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]
z=0
for i in range(n):
    for j in range(n):
        if i==j:
            continue
        y=0
        for k in range(d):
            y+=(x[i][k]-x[j][k])**2
        if y**0.5==int(y**0.5):
            z+=1
print(z//2)

Submission status: Accepted

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

Submission status: Accepted

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

a = 0
X = []

while a < n :
    X.append(input().split())
    a += 1

i = 0
j = 0
p = 0
wa = 0
count = 0

while i < n :
    p = 1
    while i + p < n :
        wa = 0
        j = 0
        while j < d :
            wa += pow(int(X[i][j]) - int(X[i + p][j]), 2)
            j += 1
        p += 1
        if (wa ** .5).is_integer() :
            count += 1
    i += 1

print(count)

Submission status: Accepted

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

for i in range(n): #1個目のセット
    for j in range(i+1,n): #2個目のセット
        for k in range(d): #セットからの取り出し
            t += (x[i][k]-x[j][k])**2
        tem = t**0.5
        t = 0
        if tem.is_integer():
            ans += 1

print(ans)

Submission status: Accepted

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

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

ans = 0

def dist(a,b):
    dist = 0
    for j in range (len(a)):
        dist += (a[j]-b[j])**2
    return(dist**0.5 == int(dist**0.5))
    
for k in range (len(X)):
    for l in range (k+1, len(X)):
        ans += (dist(X[k],X[l]))

print(ans)

Submission status: Accepted

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

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

#二重ループで各点の距離を計算
score = 0
for i in range(len(list_N)):
    for j in range(i+1, len(list_N)):
        val = 0

        for a, b in zip(list_N[i], list_N[j]):
            val += (a-b)**2

        val = val**0.5
        
        if val.is_integer():
            score += 1

print(score)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
N, D = map(int, input().split())
X = [[int(i) for i in input().split()] for j in range(N)]

ans = 0
d2 = 0
for j in range(N):
    for i in range(j):
        d2 = 0
        for k in range(D):
            d2 += (X[i][k] - X[j][k])**2
        d = np.sqrt(d2)
        if d.is_integer():
            ans += 1
            
print(ans)

Submission status: Accepted

Solution code:
import math

def dist(p1, p2):
    total = 0
    for x, y in zip(p1, p2):
        total += (x - y) ** 2
    return total

N, D = map(int, input().split())
point_list = [None] * N

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

count = 0
for i in range(N):
    for j in range(i + 1, N):
        dis = math.sqrt(dist(point_list[i], point_list[j]))
        if dis == int(dis):
            count += 1
print(count)

Submission status: Accepted

Solution code:
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):
        cnt=0
        for k in range(d):
            cnt+=(x[i][k]-x[j][k])**2
        if (cnt**0.5).is_integer() and cnt!=0:
            ans+=1
print(ans)

Submission status: Accepted

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

square = [i**2 for i in range(500)]
ans = 0
for i in range(N):
  for j in range(i):
    x = X[i]
    y = X[j]
    dist = 0
    for k in range(D):
      dist += (x[k] - y[k])**2
    if dist in square:
      ans += 1
      
print(ans)

Submission status: Accepted

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

cnt = 0

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


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

print(cnt)

Submission status: Accepted

Solution code:
n,d = map(int, input().split())
a =[[int(x) for x in input().split()] for i in range(n)]
cnt =0
sei = [i*i for i in range(10000)]

for i in range(n):
  for j in range(i):
    dis = sum( [((a[i][k] - a[j][k] )*(a[i][k] - a[j][k])) for k in range(d)])
    if dis in sei:
        cnt +=1
print(cnt)

Submission status: Accepted

Solution code:
n, d = [int(i) for i in input().split()]
x =[[int(i) for i in input().split()] for j in range(n)]
squares = set([i * i for i in range(1000)])
count = 0
for i in range(n):
	for j in range(i):
		dist = sum([(x[i][k] - x[j][k]) * (x[i][k] - x[j][k]) for k in range(d)])
		if dist in squares:
			count += 1
print(count)

Submission status: Accepted

Solution code:
import numpy as np
n,d = list(map(int,input().split()))
x = [np.array(input().split(), dtype=np.int64) for _ in range(n)]
cnt = 0
for i in range(n):
    for j in range(n):
        if i !=j:
            #print('i : '+str(i)+'  j : '+str(j))
            #print((np.linalg.norm(x[i]-x[j])))
            if (np.linalg.norm(x[i]-x[j]))%1==0:
                cnt +=1
print(cnt//2)

Submission status: Accepted

Solution code:
import math

n, d = map(int, input().split())
a = []
for l in range(n):
    a.append(list(map(int, input().split())))
res = 0
temp = 0
for x in a:
    for i in range(0, n):
        temp = 0
        for j in range(0, d):
            temp += (x[j] - a[i][j]) ** 2
        temp = math.sqrt(temp)
        if temp.is_integer():
            res += 1

print((res - n) // 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
from itertools import combinations

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

vec_L = []

for val in range(n):
    a_vec = list(map(int,input().split()))
    vec_L.append(a_vec)

a = list(range(n))

comb = list(combinations(a,2))

counter_L = []


for val in comb:
    
    vec1 = np.array(vec_L[val[0]])
    vec2 = np.array(vec_L[val[1]])
    ans = np.linalg.norm(vec1 - vec2)
    counter_L.append(ans.is_integer())

print(counter_L.count(True))

Submission status: Accepted

Solution code:
import copy
import math

n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
y = copy.deepcopy(x)
cnt = 0
inside = 0
for nx, i in enumerate(x[:]):
  # print(i)
  for ny, j in enumerate(y[:]):
    # print(j)
    inside = 0
    if nx != ny:
      for item in range(d):
        inside += (i[item] - j[item]) ** 2
        # print('inside = %d' % inside)
      root = math.sqrt(inside)
      if root.is_integer():
        cnt += 1
print(int(cnt / 2))

Submission status: Accepted

Solution code:
import math

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

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

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


cnt = 0
for i in range(n):
    for j in range(i+1,n):
        if dist(points[i],points[j]).is_integer():
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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
#input
n,d = map(int,input().split())
list_of_coordinates = []
for i in range(n):
  list_of_coordinates.append(list(map(int,input().split())))

#solve
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)

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
X=[]
for n in range(N):
    x=list(map(int,input().split()))
    X.append(x)
#print(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)


#print(calculate_dis(X[0],X[1],D))
#print(calculate_dis(X[0],X[2],D))
count=0
for n in range(N):
    #すでに計算してある組みは考慮したくない
    for m in range(n,N):
        if n==m:
            continue
        #print(f"n{n}:m{m}")
        dis=calculate_dis(X[n],X[m],D)
        #print(f"X[{n}],X[{m}]:{dis}")
        if dis%1==0:
            count+=1
print(count)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# -*- coding:utf8 -*-
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)