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

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

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

#cal
for i in range(len(x)):
	for j in range(i+1,len(x)):
		cnt = 0
		for k in range(d):
			cnt += (x[i][k]-x[j][k])**2
		cnt = math.sqrt(cnt)
		if cnt.is_integer():
			ans += 1

print(ans)

Submission status: Accepted

Solution code:
n,d = map(int,input().split())
x = [[int(e) for e in input().split()] for _ in range(n)]
count = 0
for i in range(n):
  for j in range(i+1,n):
    kyori = 0
    for k in range(d):
      kyori += (x[i][k]-x[j][k])**2
    for h in range(1,kyori+1):
      if (h*h==kyori):
        count += 1
        break
print(count)

Submission status: Accepted

Solution code:
import sys
import math
def input():
    return sys.stdin.readline()[:-1]

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

X = []

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

def nolm(x, y):
    s = len(x)
    total = 0
    for i in range(s):
        total += (x[i] - y[i]) ** 2
    return math.sqrt(total)

ans = 0

for n in range(N-1):
    for i in range(n+1, N):
        if nolm(X[n], X[i]).is_integer():
            ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
line = input()

N = int(line.split()[0])
D = int(line.split()[1])

matrix = []
for dim_cnt in range(N):
    line = input()
    vector = []
    for cnt in range(D):
        elm = int(line.split()[cnt])
        vector.append(elm)
    matrix.append(vector)

check_list = []
for i in range(N-1):
    for elm in range(N-i-1):
        j = i + elm + 1
        check_list.append((i, j))

int_cnt = 0
for check_point in check_list:
    i_vector = matrix[check_point[0]]
    j_vector = matrix[check_point[1]]
    sq_sum = 0
    for dim_cnt in range(D):
        sq_elm = (i_vector[dim_cnt] - j_vector[dim_cnt])**2
        sq_sum = sq_sum + sq_elm
    dist = sq_sum**0.5
    if dist.is_integer():
        int_cnt += 1
print(int_cnt)

Submission status: Accepted

Solution code:
n, d = map(int,input().split())
x = [list(map(int, input().split())) for _ in range(n)]
dist = lambda y, z : sum([(y_ - z_)**2 for y_,z_ in zip(y, z)]) ** 0.5
ret = 0
for i in range(n-1):
    for j in range(i+1, n):
        if i==j:
            continue
        distance = dist(x[i], x[j])
        if distance - int(distance)==0:
            ret += 1
print(ret)

Submission status: Accepted

Solution code:
import math


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


n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
cnt = 0
for i in range(n):
    for k in range(n):
        if i < k:
            dis = 0
            for j in range(d):
                dis += abs(x[i][j] - x[k][j])**2
            jud = math.sqrt(dis)
            if is_integer_num(jud):
                cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
x_l = [list(map(int,input().split())) for _ in range(n)]
cnt=0
dis=[]
for i in range(n-1):
    for j in range(i+1,n):
        for k in range(d):
            if k==0:dis = 0
            dis += (x_l[i][k] - x_l[j][k])**2
        if dis**0.5%1 == 0:
            cnt += 1

print(cnt)

Submission status: Accepted

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

def dist(y,z):
    tmp = 0
    for k in range(D):
        tmp += (y[k] - z[k])**2
    return (tmp**0.5).is_integer()

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

print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

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(N-i-1):
        s=0
        for I,J in zip(X[i],X[j+i+1]):
            s+=(I-J)**2
        if (int(s**.5))**2 == s:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
N, D = map(int, sys.stdin.readline().split())
L = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
#print(L)
cnt = 0
for i in range(N-1):
    for ie in range(i+1, N):
        tmp = 0
        for j in range(D):
            tmp +=(L[i][j] - L[ie][j])**2
        if math.sqrt(tmp) == int(math.sqrt(tmp)):
            cnt +=1
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np

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

X = []
X = np.vstack([input().split() for i in range(N)])

count = 0

for i in range(N - 1):
  for j in range(N - (i + 1)):
    r = 0
    for k in range(D):
      r += (int(X[i, k]) - int(X[i + (j + 1), k])) ** 2
  
    if np.sqrt(r).is_integer():
      count += 1
    
print(count)

Submission status: Accepted

Solution code:
import itertools

n, d = map(int, input().split())
xs = [list(map(int, input().split())) for _ in range(n)]
sq_num = set([i**2 for i in range(128)])

cnt = 0
for x1, x2 in itertools.combinations(xs, 2):
    distance_sq = sum(map(lambda xx: (xx[0]-xx[1])**2, zip(x1, x2)))
    if distance_sq in sq_num:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from math import sqrt

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

l = []
result = 0

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

for i in range(N):
  for j in range(i + 1, N):
    dist = sqrt(sum( [(l[i][d] - l[j][d]) ** 2 for d in range(D)] ))
    if(dist % 1 == 0):
      result += 1
  
print(result)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(N):
    for j in range(i+1, N):
        dist = 0
        for d in range(D):
            dist += (X[i][d]-X[j][d])*(X[i][d]-X[j][d])
        for r in range(1, 200):
            if dist == r*r:
                ans += 1
                break

print(ans)

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n, d = list(map(int, input().rstrip('\n').split()))
    x = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    cnt = 0
    for i1, v1 in enumerate(x):
        for i2, v2 in enumerate(x):
            if i1 < i2:
                t = 0
                for i in range(d):
                    t += (abs(v1[i] - v2[i]) ** 2)
                if t ** 0.5 == int(t ** 0.5):
                    cnt += 1
    print(cnt)


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
n,d = map(int, input().split())
xd = [(list(int(_) for _ in input().split())) for i in range(n)]
ans =0
for i in range(n):
  x1 = xd[i]
  for j in range(i+1,n):
    x2 = xd[j]
    dis =0
    for x,y in zip(x1,x2):
      dis += (y-x) **2
    k = dis **0.5

    if int(k)**2 ==dis:
      ans +=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# AtCoder
from math import sqrt
N, D = map(int, input().split())
lst = [list(map(int, input().split())) for i in range(N)]
ans = 0

for i in range(N):
    for j in range(i + 1, N):
        dis = 0
        for k in range(D):
            dis += (lst[i][k] - lst[j][k]) ** 2
        r = sqrt(dis)
        if r == int(r):
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math
N,D=map(int,input().split())
ans=0
place=[[0]*D for _ in range(N)]
for i in range(N):
  place[i]=list(map(int,input().split()))
for i in range(N-1):
  for j in range(i+1,N):
    d_squared=0
    for k in range(D):
      d_squared+=(place[i][k]-place[j][k])**2
    if math.sqrt(d_squared)-int(math.sqrt(d_squared))<1/(10**10):
      ans+=1
print(ans)

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
X=[]
count=0
for i in range(N):
  x=list(map(int,input().split()))
  X.append(x)
for i in range(N-1):
  for j in range(i+1,N):
    Y=0
    for k in range(D):
      Y+=(X[i][k]-X[j][k])**2
    for l in range(1,int(Y)+1):
      if l**2==Y:
        count+=1
      elif l**2>Y:
        break
print(count)

Submission status: Accepted

Solution code:
from itertools import combinations
import math

L = list(map(int, input().split()))
N = L[0]
D = L[1]

X = []

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

count = 0

for x in combinations(X,2):
	tmp = 0
	for j in range(D):
		tmp += (x[0][j]-x[1][j]) ** 2
		dist = math.sqrt(tmp)
	if dist % 1 == 0:
			count += 1
			
print(count)

Submission status: Accepted

Solution code:
import numpy as np
import itertools

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

ans = 0

for u, v in itertools.combinations(X,2):
  d = ((u - v) * (u - v)).sum()
  d2 = int(d ** 0.5)
  
  if d2 ** 2 == d:
    ans += 1
    
print(ans)

Submission status: Accepted

Solution code:
import math


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

for i in range(n):
    for j in range(i + 1, n):
        sum = 0
        for k in range(d):
            sum += pow(x[i][k] - x[j][k], 2)
        if math.sqrt(sum).is_integer():
            c += 1

print(c)

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
items = []
for i in range(N):
    items.append(tuple(map(int, input().split())))
ans = 0
from itertools import combinations

for x in combinations([i for i in range(N)] , 2):
    tmp = 0
    for k in range(D):
        tmp += (items[x[0]][k] - items[x[1]][k]) ** 2
    if pow(tmp, 0.5) % 1 == 0:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
items = []
for i in range(N):
    items.append(tuple(map(int, input().split())))
ans = 0
for i in range(N):
    for j in range(i+1, N):
        if i == j:
            continue
        tmp = 0
        for k in range(D):
            tmp += (items[i][k] - items[j][k]) ** 2
        if pow(tmp, 0.5).is_integer():
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
items = []
for i in range(N):
    items.append(tuple(map(int, input().split())))
ans = 0
for i in range(N):
    for j in range(i+1, N):
        if i == j:
            continue
        tmp = 0
        for k in range(D):
            tmp += (items[i][k] - items[j][k]) ** 2
        if pow(tmp, 0.5) % 1 == 0:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
def main():
    n, d, *x = map(int, open(0).read().split())

    cnt = 0
    for j in range(n):
        for i in range(j):
            y = x[i*d:(i+1)*d]
            z = x[j*d:(j+1)*d]
            dist_double = 0
            for cur_y, cur_z in zip(y, z):
                dist_double += (cur_y - cur_z) ** 2
            dist = int(dist_double ** 0.5 + 0.99)
            if dist ** 2 == dist_double:
                cnt += 1

    ans = cnt
    print(ans)
    return()

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n, d, *x = map(int, open(0).read().split())

    cnt = 0
    for j in range(n):
        for i in range(j):
            y = x[i*d:(i+1)*d]
            z = x[j*d:(j+1)*d]
            dist_double = 0
            for cur_y, cur_z in zip(y, z):
                dist_double += (cur_y - cur_z) ** 2
            dist = int(dist_double ** 0.5 + 0.5)
            if dist ** 2 == dist_double:
                cnt += 1

    ans = cnt
    print(ans)
    return()

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n, d, *x = map(int, open(0).read().split())

    cnt = 0
    for i in range(n-1):
        for j in range(i+1, n):
            y = x[i*d:(i+1)*d]
            z = x[j*d:(j+1)*d]
            dist_double = 0
            for cur_y, cur_z in zip(y, z):
                dist_double += (cur_y - cur_z) ** 2
            dist = int(dist_double ** 0.5 + 0.5)
            if dist ** 2 == dist_double:
                cnt += 1

    ans = cnt
    print(ans)
    return()

if __name__ == '__main__':
    main()

Submission status: Accepted

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

int_length_count = 0
for i in range(N):
    ref_ppint = points[i]
    for j in range(i+1,N):
        tar_point = points[j]
        distans_of_coordinate = [x - y for (x,y) in zip(ref_ppint, tar_point)]
        squared_distans_of_coordinate =list(map(lambda x: x ** 2, distans_of_coordinate))
        if (sum(squared_distans_of_coordinate) ** .5).is_integer():
            int_length_count += 1
print(int_length_count)

Submission status: Accepted

Solution code:
import math

def main():
    n, d, *x = map(int, open(0).read().split())

    cnt = 0
    for i in range(n-1):
        for j in range(i+1, n):
            y = x[i*d:(i+1)*d]
            z = x[j*d:(j+1)*d]
            dist = 0
            for cur_y, cur_z in zip(y, z):
                dist += (cur_y - cur_z) ** 2
            dist = math.sqrt(dist)
            if dist == int(dist):
                cnt += 1

    ans = cnt
    print(ans)
    return()

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np

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

Submission status: Accepted

Solution code:
n,d = map(int, input().split())
xd = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n):
  x1 = xd[i]
  for j in range(i+1,n):
    x2 = xd[j]
    dist = 0
    for x,y in zip(x1,x2):
      dist += (y-x) ** 2
    k = dist ** 0.5
    
    if int(k) ** 2 == dist:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math

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

r = 0
for i in range(n):
  for j in range(i + 1,n):
    a = 0
    if i != j:
      for k in range(d):
        a += (x[i][k] - x[j][k]) ** 2
      a = math.sqrt(a)
      #print("{} {} {}".format(i,j,a))
      if a % 1 == 0:
        r += 1
print(r)

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):
        kyori = 0
        for k in range(d):
            kyori += (x[i][k] - x[j][k]) ** 2
        kyori **= 0.5
        if kyori == int(kyori):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
#input : D次元空間上のN個の点、及び座標
#output : ２点間の距離が整数値となるような点の組の数

N_D = list(map(int,input().split()))
X = []
n = 0

for i in range(N_D[0]):
    X.append(list(map(int,input().split())))

for i in range(N_D[0]-1):
    j = i + 1
    while j <= N_D[0]-1:
        distance = 0
        sum = 0
        for k in range(N_D[1]):
            sum += (X[i][k] - X[j][k])**2
        distance = sum ** (1/2)
        j += 1
        if int(distance) == distance:
            n += 1

print(n)

Submission status: Accepted

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

s = 0
c = 0
for n1 in range(-1,N-1):
    for n2 in range(n1+1,N-1):
        for d in range(D):
            s = s + abs(li[n1][d] - li[n2][d]) ** 2
        s_float = float(s**(1/2))
        if s_float.is_integer():
            c += 1
        s = 0
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
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):
        dist = sum(map(lambda v1, v2: (v1 - v2) ** 2, x[i], x[j]))
        if math.sqrt(dist) == int(math.sqrt(dist)):
            ans += 1

print(ans)

Submission status: Accepted

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

count = 0
a = 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 math.sqrt(a) == int(math.sqrt(a)):
            count += 1
        a = 0

print(count)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import math
n, d = map(int, input().split())
x = [[] for i in range(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):
        norm2 = 0
        for k in range(d):
            norm2 += (x[i][k]-x[j][k])**2
        norm = math.sqrt(norm2)
        if int(norm)**2 == norm2:
            count += 1
print(count)

Submission status: Accepted

Solution code:
import math
from sys import stdin, exit

def calc_dist(y, z, D):
    dist = 0
    for i in range(D):
        dist += pow(y[i]-z[i], 2)
    return pow(dist, 0.5)

N, D = [int(_) for _ in stdin.readline().rstrip().split()]
X = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]

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

Submission status: Accepted

Solution code:
import sys
import numpy as np 
dist = 0
pairs_num = 0
dist_ary = []
i = 0
j = 1
n, d = map(int, input().split())
n_point = [input().split() for i in range(n)]
while i < n:
    while j < n:
        dist = 0
        for y,z in zip(n_point[i],n_point[j]):
            dist += (int(y)-int(z))**2
        dist_ary.append(dist)
        j+=1
    i+=1
    j = i+1
for i in range(len(dist_ary)):
    if np.sqrt(dist_ary[i]).is_integer():
        pairs_num +=1
print(pairs_num)

Submission status: Accepted

Solution code:
import numpy as np
n, d = map(int, input().split())
mat = np.zeros((n, d), "int64")
for index in range(n):
    pos = list(map(int, input().split()))
    for val_index in range(len(pos)):
        mat[index, val_index] = pos[val_index]

count = 0
for i_index in range(n-1):
    i_pos = mat[i_index]
    for j_index in range(i_index+1, n):
        j_pos = mat[j_index]
        sa = j_pos - i_pos
        sa_jijou = sa * sa
        dist_square = np.sum(sa_jijou)
        m = int(dist_square ** 0.5)
        if abs(m * m - dist_square) < 1e-6:
            count += 1
print(count)

Submission status: Accepted

Solution code:
import math
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):
        d = 0
        for x, y in zip(X[i], X[j]):
            d += (x-y)**2
        d = math.sqrt(d)
        if d - int(d) == 0:
            count += 1
        d = 0

print(count)

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
x = [[int(j) for j in input().split()] for i in range(n)]
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        acum = 0.0
        for k in range(d):
            acum += (x[j][k] - x[i][k]) ** 2
        if (acum ** 0.5).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(map(int, input().split())) for _ in range(N)]
combs = combinations(X, 2)

cnt = 0

for comb in combs:
    in_sqrt = 0
    for i in range(D):
        in_sqrt += (comb[0][i] - comb[1][i]) ** 2
    dist = sqrt(in_sqrt)
    if dist.is_integer():
        cnt += 1
print(cnt)

Submission status: Accepted

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

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

count = 0
for i in range(n):
    for j in range(i+1, n):
        cal = 0
        for y, z in zip(point[i], point[j]):
            cal += (y - z) ** 2
        # print(math.sqrt(cal))
        if math.sqrt(cal).is_integer():
            count += 1


print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

lines = stdin.readlines()
N, D = map(int, lines[0].split())
X = [[int(j) for j in lines[i].split()] for i in range(1, N + 1)]
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        acum = 0.0
        for k in range(D):
            acum += (X[j][k] - X[i][k]) ** 2
        if float.is_integer(acum ** 0.5):
            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)]
result = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        result += (sum((a - b) ** 2 for a, b in zip(X[i], X[j])) ** 0.5).is_integer()
print(result)

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(N)]
s = 0
for i in range(N - 1) :
    for j in range(i + 1, N) :
        l = 0.0
        for d in range(D) :
            l += (x[i][d] - x[j][d]) ** 2
        length = l ** (1/2)
        if length.is_integer() :
            s += 1
print(s)

Submission status: Accepted

Solution code:
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):
        sum=0.0
        for dd in range(d):
            sum+=(x[i][dd]-x[j][dd])**2
        sum=sum**(1/2)
        if sum.is_integer():
            cnt+=1
print(cnt)

Submission status: Accepted

Solution code:

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


ans=0
for j in range(a):
    for k in range(j+1,a):
        count=0
        sum=0
        for l in range(b):
            e=abs(c[j][l]-c[k][l])
            f=e**2
            count +=1
            if count <=b:
                sum +=f
                
        for n in range(sum+1):
            if n**2 == sum:
                ans +=1
                
print(ans)

Submission status: Accepted

Solution code:
def dis(a,b):
  ans = 0
  sum = 0
  
  for i in range(d):
   # print("a is",a[i])
   # print("b is",b[i])
    sum += (a[i] - b[i]) ** 2
   
  ans = sum ** 0.5
  return ans

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

for i in range(0, n-1):
  for j in range(i+1, n):
 #   print(x[i])
 #   print(x[j])
    if dis(x[i], x[j]).is_integer():
      count += 1
    
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
N,D = map(int,input().split())
X = []

#! /usr/bin/python2.7
#平方数判定
def try_square_root_naive(n):
    m = int(n**.5)
    return m if abs(m*m - n) < 1e-6 else None
 
  
for i in range(N):
  x = list(map(int,input().split()))
  X.append(x)

count = 0  
for i in range(N):
  for j in range(N):
    if(i < j):
      dist = 0
      for k in range(D):
        dist += (X[i][k] - X[j][k])*(X[i][k] - X[j][k])
      if(try_square_root_naive(dist) != None):
        count += 1
 
print(count)

Submission status: Accepted

Solution code:
import math

N, D = map(int, input().split())
X = []
for i in range(N):
    X.append(list(map(int, input().split())))
c = 0
while len(X) > 1:
    x = X.pop()
    a = 0
    for i in range(len(X)):
        for j in range(len(x)):
            a += (x[j]-X[i][j])**2
        if math.sqrt(a).is_integer():
            c += 1
        a = 0
print(c)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np


def solve(N: int, D: int, X: "List[List[int]]"):
    x_array = np.array(X)

    count = 0
    for i, x in enumerate(x_array):
        if not i == N:

            for x_target in x_array[i + 1 :]:

                distance = np.sqrt(np.power(x - x_target, 2).sum())
                if distance == int(distance):
                    count += 1
                else:
                    pass

        else:
            pss

    print(count)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    X = [
        [int(next(tokens)) for _ in range(D)] for _ in range(N)
    ]  # type: "List[List[int]]"
    solve(N, D, X)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from math import sqrt

N,D = [int(i) for i in input().split()]
XY_l = [[int(i) for i  in input().split()] for _ in range(N)]
ans = 0

for i in range(N):
  for j in range(N):
    if i <= j :
      continue
    S = float()
    for d in range(D):
      S += ((XY_l[i][d]) - (XY_l[j][d]))**2
    if sqrt(S).is_integer():
      ans+=1

print(ans)

Submission status: Accepted

Solution code:
import math

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

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

print(c)