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 numpy as np
import math
import itertools

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False
  
n, d = (int(i) for i in input().split()) 
x = []
count = 0

for k in range(n):
  x.append([int(i) for i in input().split()])
  
for px, py in itertools.combinations(range(n), 2):
  vec_a = np.array(x[px])
  vec_b = np.array(x[py])
  if is_integer_num(np.linalg.norm(vec_a - vec_b)):
    count += 1
    
print(count)

Submission status: Accepted

Solution code:
import math

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

#print(N,D,Points)

counter = 0

for i in range(N):
    for j in range(N-i-1):
        sum = 0
        for k in range(D):
            sum += (Points[i][k] - Points[j+i+1][k]) ** 2
        dist = math.sqrt(sum)
        if dist.is_integer():
            counter += 1

print(counter)

Submission status: Accepted

Solution code:
import numpy as np
n,d = map(int, input().split())
p = []
for i in range(n):
  p.append(list(map(int, input().split())))
p = np.array(p)
dist = []
for i in range(n-1):
  for j in range(n-i-1):
    dist.append(p[i]-p[i+j+1])
c = 0
for i in range(n*(n-1)//2):
  if np.linalg.norm(dist[i], ord=2) % 1 == 0:
    c +=1
print(c)

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):
        j += 1+i
        dis = 0

        for rep in range(d):
            dis += abs(x[i][rep] - x[j][rep])**2

        dis **= 0.5

        if dis == dis//1:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
def main():
    n, d = map(int, input().split(' '))
    l = [list(map(int, input().split(' '))) for _ in range(n)]
    a = [distance(d, l[i], l[j]) for i in range(n) for j in range(i+1, n)]
    ans = [1 if i == i//1 else 0 for i in a]
    print(sum(ans))


def distance(d, x, y):
    x_y = [x[i] - y[i] for i in range(d)]
    return sum([i ** 2 for i in x_y]) ** 0.5


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
N, D = map(int, input().split())
P = []
for _ 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 d in range(D):
            distance += (P[i][d]-P[j][d]) ** 2
        distance = math.sqrt(distance)
        if distance.is_integer():
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N,D=map(int, input().split())
dis = []
for i in range(N):
  dis.append([int(x) for x in input().split()])
array = np.asarray(dis)

ans = 0
for i in range(N):
  for j in range(i+1,N):
    distance = np.sqrt(sum((array[j]-array[i])**2))
    if distance%1==0:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import itertools

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

err=0
for i, j in list(itertools.combinations(X, 2)):
  if np.linalg.norm(np.array(i)-np.array(j)).is_integer():
    err+=1
    
print(err)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from itertools import combinations

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

def p(a, b):
    d2 = sum((ai - bi) ** 2 for ai, bi in zip(a, b))
    return int(d2 ** 0.5) ** 2 == d2

ans = 0
for a, b in combinations(xs, 2):
    if p(a, b):
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n,d=map(int,input().split())
lis=[[] for j in range(n)]
for i in range(n):
  lis[i]=list(map(int,input().split()))
ans=0
for a in range(n):
  for b in range(n-a-1):
    sum=0
    for c in range(d):
      sum+=(lis[a][c]-lis[a+b+1][c])**2
    if(np.sqrt(sum)%1==0):
      ans+=1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

n, d = map(int, input().split())
xs = [np.array(list(map(int, input().split()))) for _ in range(n)]
count = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        d = np.linalg.norm(xs[i] - xs[j])
        if d == int(d):
            count += 1
print(count)

Submission status: Accepted

Solution code:
import math

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

cnt=0
for i in range(n):
	for j in range(i+1,n):
		val = 0
		for y,z in zip(x_lst[i],x_lst[j]):
			val += (y-z)**2
		
		a = math.sqrt(val)
		if a == int(a):
			cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
n,d  =map(int,input().split())
lm = []
for _ in range(n):
    lm.append(list(map(int,input().split())))
s = 0
for i in range(n):
    for j in range(n):
        t = 0
        if i == j:
            continue
        else:
            for x in range(d):
                t += (lm[i][x] - lm[j][x])**2
            t = pow(t,0.5)
            if t.is_integer() == True:
                s += 1
print(s//2)

Submission status: Accepted

Solution code:
import itertools
N,D=map(int,input().split())
list1=[]
ans=0
for i in range(N):
  list1+=[list(map(int,input().split()))]
list2=list(itertools.combinations(list1,2))
for k in range(len(list2)):
  LEN=0
  for t in range(D):
    LEN+=(list2[k][0][t]-list2[k][1][t])**2
  if (LEN**0.5//1)**2==LEN:
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
import math

n, d = [int(i) for i in input().split()]
xs = []
for i in range(n):
    xs.append([int(j) for j in input().split()])

count = 0
for i in range(n-1):
    for j in range(i+1, n):
        A = xs[i]
        B = xs[j]
        sum_ = 0
        for a, b in zip(A, B):
            sum_ += (a - b)**2
        decimal, integer = math.modf(math.sqrt(sum_))
        if decimal == 0:
            count += 1

print(count)

Submission status: Accepted

Solution code:
from math import sqrt


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

list = []


for i in range(N):
  for k in range(i+1,N):
    list.append([i,k])
    
d_list = []

for plot in list:
  y = X[plot[0]]
  z = X[plot[1]]
 
  d = sqrt(sum([(yi-zi)**2 for yi, zi in zip(y,z)]))
  if d.is_integer():
    d_list.append(d)
    
    
print(len(d_list))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def calc_distance(p,q):
    sum = 0
    for i in range(d):
        sum = sum + (p[i] - q[i]) ** 2
    return math.sqrt(sum)


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

count = 0

for i in range(n):
    for j in range(n):
        if i < j:
            dist = calc_distance(matrix[i],matrix[j])
            if dist.is_integer() == True:
                count = count + 1

print(count)

Submission status: Accepted

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

import numpy as np
xs = [np.array(list(map(int, input().split()))) for i in range(n)]

def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()

counter = 0
for i in range(len(xs)):
    for j in range(i + 1, len(xs)):
        if is_integer(np.linalg.norm(xs[i] - xs[j])):
            counter += 1

print(counter)

Submission status: Accepted

Solution code:
import numpy as np
N, D = map(int, input().split())
x = []
for _ in range(N):
    x.append(list(map(int, input().split())))
x = np.array(x)
c = 0
for i in range(N-1):
    y = x[i+1:]
    y = np.sqrt(np.sum((y - x[i])*(y-x[i]), axis=1))
    c += len(np.where(y==y.astype('i'))[0])
print(c)

Submission status: Accepted

Solution code:
import math
def dist(a,b,d):
  distance=0
  for i in range(d):
    distance+=(a[i]-b[i])**2
  return distance
n,d=map(int,input().split())
x=[]
c=0
for i in range(n):
  x.append(list(map(int,input().split())))
for i in range(1,n):
  for j in range(i):
    k=dist(x[i],x[j],d)
    if k==(int(math.sqrt(k)))**2:
      c+=1
print(c)

Submission status: Accepted

Solution code:
import math as m


def calc(N, D, X):
    d_max = m.floor(40 * m.sqrt(D))
    sqrts = [x * x for x in range(1, d_max)]
    count = 0
    for i in range(N):
        for j in range(i):
            d = 0
            for k in range(D):
                d += (X[i][k] - X[j][k]) ** 2
            if (d in sqrts):
                count += 1
    print(count)


s = input().split(' ')
N = int(s[0])
D = int(s[1])
X = [
    [int(s) for s in input().split(' ')]
    for _ in range(N)
]
calc(N, D, X)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

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

ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        p = 0
        for d in range(D):
            p += (X[i][d] - X[j][d])**2

        z = math.sqrt(p)
        if z.is_integer():
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
import math

def distance(X, Y):
    ans = 0
    for x, y in zip(X,Y):
        ans = ans + (x - y)**2

    return math.sqrt(ans)

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
import bisect
from operator import itemgetter
import math
import copy
import collections
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,D = IL()
x = [IL() for i in range(N)]

cnt = 0
for i in itertools.combinations(x,2):
  num = 0
  for j in range(D):
    num += (i[0][j] - i[1][j])**2
  numa = math.sqrt(num)
  if int(numa) == math.ceil(numa):
    cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
S=input()

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

X=[]
for i in range(N):
    X.append(np.array(input().split(),dtype=np.int32))

import math

def calc_dist(x_i,x_j):
    s=0
    for i in range(len(x_i)):
        s+=pow((x_i[i]-x_j[i]),2)
    return math.sqrt(s)

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

print(count)

Submission status: Accepted

Solution code:
import itertools,math
n,d = [int(u) for u in input().split(" ")]
ps = [[int(u) for u in input().split(" ")] for row in range(n)]

r = 0
for i,j in itertools.combinations(range(n),2):
  a = ps[i]
  b = ps[j]
  l = sum([(x-y)*(x-y) for x,y in zip(a,b)])
  l2 = math.floor(math.sqrt(l))
  if l2*l2 == l:
    r+=1
print(r)

Submission status: Accepted

Solution code:
import math

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

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

for i in range(N-1):
    for j in range(i+1,N):
        ans = 0
        for k in range(D):

            ans += (X[i][k] - X[j][k])**2
    
        ans = math.sqrt(ans)
        if(ans%1 == 0):
            ans_p += 1

print(ans_p)

Submission status: Accepted

Solution code:
import itertools
import math
n,d = map(int,input().split())
x_list = [list(map(int,input().split())) for _ in range(n)]
x_c = itertools.combinations(x_list,2)
count = 0
for x in x_c:
    x1 = x[0]
    x2 = x[1]
    tmp = 0
    for i in range(d):
        tmp += (x1[i]-x2[i])**2
    tmp = math.sqrt(tmp)
    if tmp.is_integer():
        count += 1
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)]

cnt = 0
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        s = 0
        for d in range(D):
            s += (X[i][d] - X[j][d]) ** 2
        s = sqrt(s)
        if s.is_integer():
            cnt += 1
print(cnt // 2)

Submission status: Accepted

Solution code:
import bisect

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

def distance2(p1, p2):
    ddt = 0
    for i in range(D):
        r = (p1[i] - p2[i])
        ddt += (r * r)

    return ddt

class SquareRoot(object):
    def __init__(self, n):
        self.n = n
    def __getitem__(self, index):
        return index * index
    def __len__(self):
        return self.n

def try_square_root(n2):
    n = bisect.bisect_left(SquareRoot(n2), n2)
    return n if n*n == n2 else None

result = []
lss = len(Xss)
r = 0
for i in range(lss):
  for j in range(i + 1, lss):
      p1 = Xss[i]
      p2 = Xss[j]
      d = distance2(p1, p2)
      if try_square_root(d) is not None:
          r += 1
print(r)

Submission status: Accepted

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

count = 0
dots = []
for _ in range(n):
    line = input().split(" ")
    dots.append([int(m) for m in line])

for i in range(n-1):
    for j in range(i+1, n):
        val = [(dots[i][k] - dots[j][k])**2 for k in range(d)]
        
        if math.sqrt(sum(val)).is_integer():
            count += 1
            
print(count)

Submission status: Accepted

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

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

ans = 0
tmp = 0

for i in range(n-1):
    for j in range(i+1, n):
        for k in range(d):
            tmp += (Xlist[i][k] - Xlist[j][k]) ** 2
        a = int(tmp ** 0.5) ** 2
        if a == tmp:
            ans += 1
        tmp = 0

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
import math
input = [int(x) for x in stdin.readline().rstrip().split()]

N=input[0]
D=input[1]
point_list=[]
for n in range(N):
    point_list.append([int(x) for x in stdin.readline().rstrip().split()])

output=0

for i in range(N):
    for j in range(N):
        if i<j:
            difflist=[x - y for (x, y) in zip(point_list[i], point_list[j])]
            diff2=[x**2 for x in difflist]
            dist=math.sqrt(sum(diff2))
            if dist==int(dist):
                output+=1
print(output)

Submission status: Accepted

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

X = [0] * N
for n in range(N):
    X[n] = [int(_) for _ in input().split()]

count = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        distance = sum([(X[i][d] - X[j][d]) ** 2 for d in range(D)])
        tmp = math.sqrt(distance)
        if distance % tmp == 0:
            count += 1
print(count)

Submission status: Accepted

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

all_pattern = list(itertools.combinations(points,2))
result = 0

for i in all_pattern:
    a = i[0]
    b = i[1]
    tmp = 0
    for j,e in enumerate(a):
        tmp += (e - b[j])**2
    if math.sqrt(tmp).is_integer():
        result += 1

print(result)

Submission status: Accepted

Solution code:
import math
from itertools import combinations
N, D = map(int, input().split())
X = [list(map(int , input().split())) for i in range(N)]
P = list(combinations(range(1,N+1), 2))
#print(X)
count = 0
for p in P :
    x = X[p[0] - 1]
    y = X[p[1] - 1]
    #print(x,y)
    ans = 0
    for d in range(D) :
        ans += (x[d] - y[d]) * (x[d] - y[d])
    ans = math.sqrt(ans)
    #print(ans)
    if ans.is_integer() :
        count += 1
print(count)

Submission status: Accepted

Solution code:
import math
N,D = map(int,input().split())
cnt = 0
data = []
for i in range(N):
  list_youso = list(map(int,input().split()))
  data.append(list_youso)
for i in range(N):
  for k in range(i+1,N):
    distance = 0
    for j in range(D):
      distance += abs(data[i][j]-data[k][j])**2
    if int(math.sqrt(distance))*int(math.sqrt(distance)) == distance:
      cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
import numpy as np
from scipy.spatial import distance

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

l = [0]*N

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

dist_M = distance.cdist(l, l, metric='euclidean')

count = 0

for i in range(N):
    for j in range(i+1,N):
        if dist_M[i][j] %1 == 0 :
            count += 1

print(count)

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

print(ans)

Submission status: Accepted

Solution code:
import math

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

count=0
for i in range(n-1):
  for j in range(i+1,n):
    num=0
    for k in range(d):
      num+=(li[i][k]-li[j][k])**2
    num=math.sqrt(num)
    if num%1==0:
      count+=1
print(count)

Submission status: Accepted

Solution code:
from itertools import combinations
from math import sqrt

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

count = 0
for c in combinations(xs, 2):
    a = c[0]
    b = c[1]
    y = sqrt(sum([(b[i] - a[i]) ** 2 for i in range(len(a))]))
    if y.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):
  h = list(map(int,input().split()))
  x.append(h)
def l(i,j):
  s = 0
  for k in range(d):
    s += (x[i][k]-x[j][k])**2
  return math.sqrt(s)
S = 0
for i in range(0,n-1):
  for j in range(i+1,n):
    k = l(i,j)
    if k.is_integer() == True:
      S += 1
print(S)

Submission status: Accepted

Solution code:
import math


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
n, d = [int(i) for i in input().split()]
A = []
for i in range(n):
    A.append([int(i) for i in input().split()])
def distance_truth(x,y):
    dist = 0
    for i in range(d):
        dist += (x[i]-y[i])**2
    tmp = math.sqrt(dist)
    return int(tmp) == tmp
ans = 0
for i in range(n):
    for j in range(i+1, n):
        if distance_truth(A[i],A[j]):
            ans += 1
print(ans)

Submission status: Accepted

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

X=[]

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

#print(X)

dis=0
n=0
ans=0

for Y in X[:-1]:
    n+=1
    for Z in X[n:]:
        for i in range(d):
            dis+=(Y[i]-Z[i])**2
        if round(math.sqrt(dis))**2 == dis:
            ans +=1
        
        #print(dis,ans)
        dis=0
        
print(ans)

Submission status: Accepted

Solution code:
N, D = map(int,input().split()) # 複数の数字を変数に格納
List = [list(map(int,input().split())) for i in range(N)] # [[1,2],[3,4],[5,6]]

import math

count = 0

for i in range(N):
    for j in range(i+1,N):
        tmp = 0
        for k in range(D):
            tmp += (List[i][k] - List[j][k])**2
        tmp = math.sqrt(tmp)
        if tmp.is_integer() == True:
            count += 1

print(count)

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

N, D = LI()
X = [[] for i in range(N)]
for i in range(N):
    X[i] = LI()

cnt = 0
for i in range(N):
    for j in range(i+1,N):
        l = 0
        for d in range(D):
            l += (X[i][d] - X[j][d]) ** 2
        if math.sqrt(l) % 1 == 0:
            cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

n, d = (int(i) for i in input().split())
X = [[int(ii) for ii in input().split()] for i in range(n)]
X = np.array(X)

count = 0
for i in range(X.shape[0]):
    for ii in range(X.shape[0]):
        if i == ii:
            continue
        if float.is_integer(np.linalg.norm(X[i] - X[ii])):
            count += 1

print(count // 2)

Submission status: Accepted

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

count = 0

point_list_copy = copy.deepcopy(point_list)

for point in point_list:
    point_list_copy.pop(0)
    for point_copy in point_list_copy:
        distance = 0
        for i in range(d):
            distance += (point[i] - point_copy[i])**2
        dist = distance ** (1/2)
        if dist == int(dist):
            count += 1

print (count)

Submission status: Accepted

Solution code:
import math

x = input()
x = x.split()
n = int(x[0])
d = int(x[1])


ans = 0
points = []

for i in range(n):
  x = input()
  x = x.split()
  points.append(x)

for i in range(len(points)):
  for j in range(i+1,len(points)):
    dis = 0
    for k in range(d):
      sa = int(points[i][k])-int(points[j][k])
      dis += sa*sa
    
    disf = math.sqrt(dis)
    if disf.is_integer() == True:
      ans += 1

      
print(ans)

Submission status: Accepted

Solution code:
N,D = map(int,input().split())
para=[[i for i in map(int,input().split())] for j in range(N)]
def dist(a,b):
    ans = 0
    for i in range(D):
        ans += (a[i] - b[i])**2
    k = 0 
    while k**2 <= ans :
        if k**2 == ans :
            return True
        else :
            k += 1
    return False
p = 0 
for i in range(N):
    for j in range(N-i-1):
        if dist(para[i],para[i+j+1]) :
            p += 1
print(p)

Submission status: Accepted

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

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

cnt=0

for i in range(n):
    for j in range(i+1,n):
        res=0
        for xa,xb in zip(x[i],x[j]):
            res+=abs(xa-xb)**2

        tmp=int(res**0.5)
        if int(tmp**2)==res:
            cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
n,d = map(int, input().split())
X = []
for _ in range(n):
    _x = list(map(int, input().split()))
    X.append(_x)

from itertools import combinations
import numpy as np

ans = 0
for (x1, x2) in combinations(X, 2):
    a = 0
    for i in range(d):
        a += (x1[i]-x2[i])**2 
    a = np.sqrt(a)
    if a.is_integer():
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
from math import sqrt
N, D = map(int,input().split())
points = []
for _ in range(N):
    points.append(np.array(list(map(int,input().split()))))
#print(points)

# def calc_dist(p1,p2):
#     dist = np.linalg.norm(p1-p2)
#     print(dist)
# calc_dist(points[0],points[1])
cnt = 0
for p1 in range(N):
    for p2 in range(p1+1,N):
        dist = np.linalg.norm(points[p1] - points[p2])
        #print(dist)
        if dist.is_integer():
            #print(dist)
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
n, d = map(int, input().split())
a = np.zeros((n, d))
ans = 0
for i in range(n):
  a[i] = np.array([int(j) for j in input().split()])
for i in range(n-1):
  for j in range(i+1, n):
    if float.is_integer(np.linalg.norm(a[i]-a[j])):
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math

N, D = map(int, input().split())
x=[['' for i in range(D)] for j 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(0,i):
    sum=0
    for k in range(D):
      sum+=pow(x[i][k]-x[j][k],2)
    #print(math.sqrt(sum).is_integer(),str(math.sqrt(sum)))
    if math.sqrt(sum).is_integer():
      count+=1
print(count)

Submission status: Accepted

Solution code:
import numpy as np

s = input()
l = s.split()

n = int(l[0])
d = int(l[1])

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

X = np.array(X)

cnt = 0
for i, xi in enumerate(X):
    for j, xj in enumerate(X[i+1:]):
        if np.linalg.norm(xi-xj, ord=2) % 1.0 == 0:
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
from copy import deepcopy
from math import sqrt

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

vectors = []
for i in range(N):
    string = input()
    split = string.split()
    vec = []
    for j in range(D):
        vec.append(int(split[j]))
    vectors.append(deepcopy(vec))

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

Submission status: Accepted

Solution code:
import numpy as np

N, D = map(int, input().split())
x = [list(map(int, input().split())) for i in range(N)] 
def main(x2, x3):
  y2 = np.array(x2)
  y3 = np.array(x3)
  l = np.linalg.norm(y3-y2)
  return l

count = 0

for i in range(N):
  for j in range(i+1, N):
    if main(x[i], x[j]).is_integer() == True:
      count += 1

print(count)

Submission status: Accepted

Solution code:
import math
a,b = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(a)]
num = 0
ans = 0
for i in range(a-1):
    for j in range(i+1,a):
        num = 0
        for k in range(b):
            num += (lis[i][k] - lis[j][k]) ** 2
        if math.ceil(math.sqrt(num)) == math.floor(math.sqrt(num)):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import itertools as it
N, D = map(int, input().split())
def dis(ls1, ls2):
    distance = 0
    for i in range(D):
        distance += ( ls1[i] - ls2[i] ) ** 2
    return np.sqrt(distance)

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

count = 0
ran = [i for i in range(N)]
for x in it.combinations(ran, 2):
    d = dis(ls[x[0]], ls[x[1]])
    if d.is_integer():
        count += 1
print(count)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from math import sqrt

ND = input().split(' ')
N = int(ND[0])
D = int(ND[1])
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):
        sum = 0
        for d in range(D):
            sum += (X[i][d] - X[j][d]) * (X[i][d] - X[j][d])
        s = int(sqrt(sum))
        if s * s == sum:
            result += 1

print(result)

Submission status: Accepted

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