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:
#B
N, D = map(int, input().split())
List=[[int(j) for j in input().split()] for i in range(N)]
count =0
pp =0

for j in range(1,N):
    for i in range(j,N):
        pp= pp + 1
        combined1 = sum([(x-y)**2 for (x, y) in zip(List[j-1], List[i])])**0.5
        flg =combined1.is_integer()
        #print(List[i])
        if flg ==True:
            count =count+1

print(count)

Submission status: Accepted

Solution code:
import math

N,D = map(int, raw_input().split())
ans = 0
X = []

for i in range(0, N):
    x = map(int, raw_input().split())
    X.append(x)
    for j in range(0, i):
        d = 0
        for k in range(0, D):
            d += (X[i][k] - X[j][k]) ** 2
        dx = math.sqrt(d)
        if dx.is_integer():
            ans += 1

print(ans)

Submission status: Accepted

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

LIST=[[0]*D]*N
#print(LIST)
#print(LIST[0])

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

#print(LIST)
  
  
for i in range(N):
  for j in range(N):
    for k in range(D):
      DISTANCE=DISTANCE+(LIST[i][k]-LIST[j][k])**2
    DISTANCE=DISTANCE**0.5
    if DISTANCE%1==0 and DISTANCE!=0:
      COUNT=COUNT+1
      #print(COUNT,DISTANCE)
    DISTANCE=0
    
print(int(COUNT/2))

Submission status: Accepted

Solution code:
import numpy as np

N, D = map(int, raw_input().split(' '))

nizyo = np.array(range(1, 127))
nizyo = nizyo ** 2
X = []
for i in range(N):
    X.append(map(int, raw_input().split(' ')))

count = 0
for j in range(1, N):
    for k in range(j):

        if j > k:

            d = np.sum( (np.array(X[k]) - np.array(X[j])) **2)
            
            if d in nizyo:
                count += 1
            
print(count)

Submission status: Accepted

Solution code:
import sys
import math
import itertools

input = sys.stdin.readline


def main():
    n, d = [int(i) for i in input().split()]
    ps = [[int(i) for i in input().split()] for _ in range(n)]
    cnt = 0
    for i, x in itertools.combinations(range(n), 2):
        hige = math.sqrt(sum([(ps[i][j] - ps[x][j]) ** 2 for j in range(d)]))
        if hige % 1 == 0:
            cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

import numpy as np
np.seterr(all='ignore')

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

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

d = np.empty([mat.shape[0], mat.shape[0]])
d[:,:] = np.nan

for i in range(mat.shape[0]):
    for j in range(i+1, mat.shape[0]):
        d[i,j] = np.sqrt(((mat[i,:] - mat[j,:])**2).sum())

np.mod(d,1,d)
print('{}'.format(np.sum(d==0)))

Submission status: Accepted

Solution code:
import numpy as np
n,d = map(int,input().split())
l = np.array([list(map(int,input().split())) for _ in range(n)])
#print(l)
c = 0
ans = []
for i in range(len(l)-1):
  for j in range(i+1,len(l)):
    u = l[i] - l[j]
    #print(u)
    ans.append(np.linalg.norm(u))
#print(ans)
for k in ans:
  if k % 1 == 0:
    c += 1
print(c)

Submission status: Accepted

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



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

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


if __name__ == "__main__":
  main()

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
lenx=len(X)
leny=len(X[0])
for i in range(lenx):
   
    for j in range(i+1,lenx):
        suma=0
        for k in range(leny):
            suma+=(X[i][k]-X[j][k])**2
 
        if math.sqrt(suma)%1==0:
       
            cnt+=1
        
print(cnt)

Submission status: Accepted

Solution code:
n,d=map(int,input().split()) #2<=n<=10 souatari 10*9/2>kaisuu
x=[]
cnt=0
for _ in range(n):
  x+=[list(map(int,input().split()))]
dx=[]
for i in range(n):
  for j in range(n):
    if i == j:
      continue
    dx2=0
    for k in range(d):
      dx2 += (x[i][k]-x[j][k])**2
    dx +=[dx2**0.5]
for _ in dx:
	if _ == int(_):
  		cnt+=1 
print(cnt//2)

Submission status: Accepted

Solution code:
import numpy
N,D=map(int,input().split())
X=[list(map(int,input().split())) for i in range(N)]
A=0
for i in range(N):
    for j in range(N-i-1):
        Z=numpy.linalg.norm(numpy.array(X[i])-numpy.array(X[i+j+1]))
        if Z.is_integer()== True:
            A=A+1
print(A)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
from sys import stdin
import math
import itertools
import numpy as np

l = stdin.readline().rstrip().split()
l = [int(s) for s in l]

data = [stdin.readline().rstrip().split() for _ in range(l[0])]
for i in range(len(data)):
	data[i] = [int(s) for s in data[i]]

l = data
c = itertools.combinations(l, 2)
hoge = []
vvv = []
for v in itertools.combinations(l, 2):
    vvv.append(v)

for i in range(len(vvv)):
    vvv[i]
    calc = np.linalg.norm(np.array(vvv[i][0]) - np.array(vvv[i][1]))
    hoge.append(calc.is_integer())

print(hoge.count(True))

Submission status: Accepted

Solution code:
def distance(a, b):
	cont = 0
	for k in xrange(len(a)):
		cont += (a[k] - b[k]) * (a[k] - b[k])
	return cont ** 0.5
n, t = map(int, raw_input().split())

ar = []

for i in xrange(n):
	ar.append(map(int, raw_input().split()))
	
cont = 0
for k in xrange(n):
	for l in xrange(k + 1, n):
		if distance(ar[k], ar[l]) == int(distance(ar[k], ar[l])):
			cont += 1
			
print cont

Submission status: Accepted

Solution code:
import math
import itertools
N, D = map(int, input().split())
 
count = 0
all_list = []
for _ in range(N):
    p_list = list(map(int, input().split()))
    all_list.append(p_list)

comb_list = list(itertools.combinations(all_list, 2))
for f_list, l_list in comb_list:
    diff_list = [(i-j)**2 for i, j in zip(f_list, l_list)]
    dist = math.sqrt(sum(diff_list))
    if dist == int(dist):
        count += 1

print(count)

Submission status: Accepted

Solution code:
import numpy as np 


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

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

x = np.array(x)
count = 0
for i in range(N):
	for j in range(N-i-1):
		if(np.linalg.norm(x[i]-x[i+j+1]).is_integer()==True):
			count += 1

print(count)

Submission status: Accepted

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

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

i = 0
j = N - 1
while i < N - 1:
    a = points[i]
    b = points[j]
    total = 0
    for d in range(D):
        total += (a[d] - b[d]) ** 2
    res = math.sqrt(total)
    if res.is_integer(): ans += 1
    j -= 1
    if i == j:
        i += 1
        j = N - 1

print(ans)

Submission status: Accepted

Solution code:
import math
def check(n):
    if isinstance(n,int):
        return True
    if isinstance(n,float):
        return n.is_integer()
    return False

n,d=map(int,input().split())
info=[]
for i in range(n):
    info.append(list(map(int,input().split())))
#print(info)
count=0
dis=0
for i in range(n-1):#0～n-2
    for j in range(i+1,n): #i+1～n-1
        for k in range(d): #点iと点jの距離を調べる
            #print(str(i)+" "+str(j))
            dis+=abs(info[i][k]-info[j][k])**2
            #print(dis)
        #print(dis)
        dis2=math.sqrt(dis)
        #print(dis2)
        if check(dis2)==True:
            count+=1
        dis=0 #jが変わると初期化
    dis=0 #iが変わると初期化
    
print(count)

Submission status: Accepted

Solution code:
from math import sqrt
N,D = map(int,input().split())
X = [[int(i) for i in input().split()] for j in range(N)]
count = 0

for i in range(N-1):
  for j in range(i+1,N):
    tmp = sqrt(sum([(a-b)**2 for a,b in zip(X[i],X[j])]))
    if tmp == int(tmp):
      count += 1
      
print(count)

Submission status: Accepted

Solution code:
# coding: utf-8

import math as m

ls = input().split(" ")
n = int(ls[0])
d = int(ls[1])
Xs = []
ans = 0

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

for i in range(n - 1):
	for j in range(i + 1, n):
		if m.sqrt(sum([(a - b)**2 for a, b in zip(Xs[i], Xs[j])])).is_integer():
			ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import math
N, D = map(int, input().split())
 
n = [list(map(int, input().split())) for i in range(N)]
n = np.array(n)
ans = 0
for j in range(n.shape[0]):
  for i in range(n.shape[0]):
    length = np.linalg.norm(n[i]-n[j])
    aaa = math.modf(length)[0]
    if aaa < 0.00001:
      ans +=1
ans = ans - n.shape[0]
ans = int(ans/2)
print(ans)

Submission status: Accepted

Solution code:
import math
import numpy as np

def distance(y, z, d):
    y = np.array(y)
    z = np.array(z)
    delta2 = (y-z)**2
    return math.sqrt(sum(delta2))

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

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

Submission status: Accepted

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

def isqrt(n):
    x = n
    y = (x + 1) // 2
    while y < x:
        x = y
        y = (x + n // x) // 2
    return x

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math

# スペース区切りの整数の入力
n,d = map(int, input().split())
list_x = [[0 for i in range(d)] for j in range(n)]

ans = 0
tmp_targ = 0

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

# print(list_x)

for l in range(n-1):
    for m in range(l+1,n):
        tmp_targ = 0
        for i1 in range(d):
            tmp_targ += (list_x[l][i1] - list_x[m][i1]) ** 2
        # print("targ:{},sqrt:{}".format(tmp_targ,math.sqrt(tmp_targ)))
        if isinstance(math.sqrt(tmp_targ), int) or math.sqrt(tmp_targ).is_integer():
            ans += 1
# 出力
print(ans)

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())))
cnt = 0

for i in range(n):
    for j in range(n):

        if i != j:
            countwa = 0
            for k in range(d):
                countwa += abs(a[i][k] - a[j][k]) ** 2
            if float(math.sqrt(countwa)).is_integer():
                cnt += 1
print(cnt//2)

Submission status: Accepted

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

counter = 0
for i in range(N):
    for j in range(N-i-1):
        dsquare = 0
        for k in range(D):
            dsquare += (X[i][k] - X[i+j+1][k])**2
        n = 1
        while (n**2 <= dsquare):
            if (dsquare == n**2):
                counter += 1
                break
            else:
                n += 1
print(counter)

Submission status: Accepted

Solution code:
import math
n , d = map(int,input().split())
p = []
ans = 0
for i in range (n):
    z = list(map(int,input().split()))
    p.append(z)
for j in range(n):
    for k in range (j+1,n):
        dis2 = 0
        for l in range (d) :
            dis2 += (p[j][l] - p[k][l]) ** 2
        dis = math.sqrt(dis2)
        if int(dis)== dis :
            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)]
a=0
for i in range(n):
	for j in range(i+1,n):
		a += math.modf(math.sqrt(sum([abs(x[i][k] - x[j][k])**2 for k in range(d)])))[0] < 1e-9
print(a)

Submission status: Accepted

Solution code:
import math

def inputs():
    return [int(s) for s in input().split(" ")]

#----------#
elem = inputs()
N = elem[0]
D = elem[1]

points = []
for i in range(N):
    points.append(inputs())

anscount = 0
for i_pt in points:
    for j_pt in points:
        if i_pt == j_pt:
            break
        sumup = 0
        for k in range(D):
            sumup += abs(i_pt[k] - j_pt[k]) ** 2
        if(math.sqrt(sumup) % 1 == 0):
            anscount +=1

print(anscount)

Submission status: Accepted

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

count = 0
for i in range(len(x) - 1):
  for j in range(i + 1, len(x)):
    u = x[i] - x[j]
    if np.linalg.norm(u).is_integer():
      count += 1
print(count)

Submission status: Accepted

Solution code:
import math

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

X = []
for _ 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):
        d = 0
        for k in range(D):
            d += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k])
        for z in range(130):
            if d == z**2:
                ans += 1
                break

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()

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

x=[]
for i in range(n):
    row = input().split()
    for i in range(len(row)):
        row[i]=int(row[i])
    x.append(row)
#print(x[0][1])
count = 0
for i in range(n-1):
    a=np.array(x[i])
    for j in range(i,n):
        if(i==j):
            continue
        b=np.array(x[j])
        l = np.linalg.norm(a-b)
        #print(l)
        if(is_integer(l)):
            count += 1

print(count)

Submission status: Accepted

Solution code:
import numpy as np

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

Submission status: Accepted

Solution code:
import numpy as np
N, D = (int(i) for i in input().split())
X = [[int(i) for i in input().split()] for i in range(N)]
a = np.zeros(D)
b = 0
count = 0
for l in range(N):
  for k in range(N):
    for i in range(D):
      a[i] = (X[l][i]-X[k][i])**2
      b = np.sqrt(sum(a))
    if b != 0 and b - int(b) == 0:
      count += 1
print(count//2)

Submission status: Accepted

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

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

count = 0
for i in range(N):
    t = N - i - 1
    
    for j in range(t):
        vec = np.sqrt(np.power(x[t] - x[j], 2).sum())
        count = count + 1 if vec % 1.0 == 0.0 else count

print(count)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

N,D = map(int,input().split())
lst = [list(map(int,input().split())) for i in range(N)]
count = 0
for j in range(N-1):
    for i in range(j+1,N):
        a = 0
        for d in range(D):
           #print(lst[j][d],lst[i][d])
            a+= (abs(lst[j][d] - lst[i][d]))**2
        if (a**0.5 % 1 == 0):
            count+=1
        
print(count)

Submission status: Accepted

Solution code:
import numpy as np

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

def norm(y,z,D):
    nrm = 0.0
    for i in range(D):
        nrm = nrm + (y[i] - z[i])*(y[i] - z[i])
    return np.sqrt(nrm)

count = 0
for i in range(N):
    for j in range(i+1,N):
        dis = norm(x[i],x[j],D)
        if dis.is_integer():
            count = count + 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

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

"""
itertools.product(range(a+1), range(b+1), range(c+1))
"""

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

    count = 0
    for (a, b) in itertools.combinations(x, 2):
        if is_integer_num(sum((pair[0] - pair[1]) ** 2 for pair in zip(a, b)) ** .5):
            count += 1
    print(count)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Xss = []
for _ in range(N):
	Xs = list(map(int,input().split()))
	Xss.append(Xs)
	
#print(Xss)

count = 0
for i in range(N):
	for j in range(N):
		if i >= j:
			continue
		
		tmp = 0
		for d in range(D):
			#print(Xss[i][d],Xss[j][d])
			tmp += ((Xss[i][d]-Xss[j][d])**2)
			
		tmp = tmp**(1/2)
		
		#print(tmp)
		if float.is_integer(tmp):
			count += 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)]
count = 0
for i in range(N-1):
    for j in range(i+1,N):
        list_c = [(x2-x1)**2 for (x2,x1) in zip(x[j],x[i])]
        a=sum(list_c)**0.5
        if a.is_integer() == True:
            count += 1
print(count)

Submission status: Accepted

Solution code:
n,d = [int(_) for _ in input().split()]
x = [[int(_) for _ in input().split()] for __ 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 += (x[i][k] - x[j][k])**2
        for k in range(1,200):
            if dist == k**2:
                ans += 1
                break
        dist = 0
print(ans)

Submission status: Accepted

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

x = [0 for i in range(n)]

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

chk = 0
cnt = 0


for i in range(n-1):
    for k in range(i+1,n):
        for j in range(d):
            #print(x[i][j],x[i+1][j])
            chk += (abs(x[i][j]-x[k][j]))**2
        chk = chk**0.5
        #print(i,k,chk)
        if chk.is_integer():
            cnt+=1
        chk = 0

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)]

c = 0

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

Submission status: Accepted

Solution code:
import math
def calc(aL, bL):
  des2 = 0
  for (a, b) in zip(aL, bL):
#    print("des {} {}".format(a, b))
    des2 += abs(a-b) * abs(a-b)
  return math.sqrt(des2)

n, d = map(int, input().split())
aList = list()
for _ in range(n):
  if d != 1:
    aList.append(list(map(int, input().split())))
  else:
    aList.append(int(input()))
  
count = 0
for aIdx in range(0, len(aList)):
  for bIdx in range(aIdx+1, len(aList)):
#    print("Idx {} {}".format(aIdx, bIdx))
    if aIdx == bIdx:
      continue
    if d != 1:
      des = calc(aList[aIdx], aList[bIdx])
    else:
      des = math.sqrt(abs(aList[aIdx] - aList[bIdx])*(abs(aList[aIdx] - aList[bIdx])))
    if des % 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())))

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

Submission status: Accepted

Solution code:
def f(a):

	return a**0.5==int(a**0.5)#print(f(4))

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

def g(a,b):

	ret=0

	for i in range(0,d):

		ret+=(a[i]-b[i])**2

	return ret

	

	

ans=0

a=[]

for i in range(0,n):

	a.append(list(map(int,input().split())))

	for j in range(0,i):

		if f(g(a[i],a[j])):

			ans+=1

print(ans)

Submission status: Accepted

Solution code:
import math

a,b = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(a)]
co = 0
for i in range(0,a-1):
    for j in range(i+1,a):
        t = 0
        for k in range(b):
            t += pow(abs(l[i][k]-l[j][k]),2)
        if(math.sqrt(t).is_integer()):
            co = co+1

print(co)

Submission status: Accepted

Solution code:
def f(D, Y, Z):
    temp = 0
    for i in range(D):
        temp+= (Y[i]-Z[i])**2
    return temp**(1/2)

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

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

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        if f(D, axis[i], axis[j]).is_integer():
            cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
import sys
import math
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
ra = lambda: list(map(int, sys.stdin.readline().split()))

n, d = ra()
x = []
for i in range(n):
    l = ra()
    x.append(l)

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

print(ans)

Submission status: Accepted

Solution code:
import math as mt
n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
count, a = 0, 0
for i in range(n):
    for j in range(i + 1, n):
        for m in range(d):
            a += abs(x[i][m] - x[j][m]) ** 2
        if mt.sqrt(a).is_integer():
            count += 1
        a = 0
print(count)

Submission status: Accepted

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

x = [ [] for x in range(n) ]

count = 0

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

for i in range(n):
  for j in range(n)[i+1:]:
    s = 0
    for k in range(d):
      s += (x[i][k] - x[j][k])**2
    r=int(s**0.5)
    if s == r**2 :
      count += 1
print(count)

Submission status: Accepted

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

count = 0
distance = 0

for i in range(N-1):
    for j in range(i+1,N):
      distance = 0
      for k in range(D):
        distance += pow(X[i][k] - X[j][k],2)
      distance = math.sqrt(distance)
      f = distance - int(distance)
      if f == 0.0:
        count += 1
            
print(count)

Submission status: Accepted

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


def calc(i,j):
    dist2d = [x**2 for x in range(500)]
    ci = field[i]
    cj = field[j]
    dist2 = [(di-dj)**2 for di,dj in zip(ci,cj)] 

    
    if sum(dist2) in dist2d:
        return True
    else:
        return False

ans = 0
for i in range(N):
    for j in range(i+1,N):
        ans += calc(i,j)

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math

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

count = 0

for i in range(N):
    for j in range(N):
        d = math.sqrt(sum(map(lambda x,y : abs(x-y) * abs(x-y) , X[i],X[j])))
        if d - int(d) == 0 and d != 0.0:
            count += 1
count = count /2

print(int(count))

Submission status: Accepted

Solution code:
import math

N,D = map(int, input().split())
idx = [list(map(int, input().split())) for i in range(N)]
count = 0
Sum = 0

for i in range(N-1):
    for j in range(i+1,N):
        for k in range(D):
            Sum = Sum + (idx[i][k]-idx[j][k])**2 
        distance = math.sqrt(Sum)
            
        if distance == round(distance):
            count += 1
        Sum = 0

print(count)

Submission status: Accepted

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

def calc_distant(p,q):
	sco = 0
	for i in range(d):
		sco += (p[i]-q[i])**2
	return sco

num=[]
for i in range(n-1):
	for j in range(i+1,n):
		num.append(calc_distant(lst[i],lst[j]))

def joukon(m):
	if float.is_integer(m**(0.5)):
		return 1
	else:
		return 0

lust = []
for i in num:
	lust.append(joukon(i))
print(sum(lust))

Submission status: Accepted

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

count = 0
sum_max  = (40**2) * d
int_list = [ i**2 for i in range(int(math.sqrt(sum_max))) ]

for i in range(n):
    for j in range(i+1,n):
        sum = 0
        for k in range(d):
            sum += (vecs[i][k] - vecs[j][k]) ** 2
        if sum in int_list:
            count += 1

print(count)

Submission status: Accepted

Solution code:
def distance(a, b, d):
    res = 0
    for i in range(d):
        res += (a[i] - b[i]) ** 2
    res **= 0.5
    return res

n, d = [int(i) for i in input().split()]
dot = []
for i in range(n):
    dot.append([int(i) for i in input().split()])
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        di = distance(dot[i], dot[j], d)
        if abs(int(di) - di) < 0.0001:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N, D = list(map(int, input().split(' ')))
v = []
for n in range(N):
    v.append(list(map(int, input().split(' '))))
vec = np.array(v)
c = 0
for i in range(N):
    for j in range(i+1, N):
        if np.linalg.norm(vec[i]-vec[j]) % 1 == 0:
            c += 1
print(c)

Submission status: Accepted

Solution code:
n,d = map(int, input().split())
import numpy as np
import itertools
x = np.array([np.array(list(map(int, input().split()))) for _ in range(n)])
count = 0
for i,j in itertools.combinations(x,2):
  k = np.sqrt(np.sum(np.square(i-j)))
  if k==int(k):
    count += 1
    
print(count)

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):
    
    for k in range(i+1,N):
        sum = 0
#        print("i: {}  k: {}".format(i, k))
        for j in range(D):
#            print("list: {}  list: {}".format(List[i][j], List[k][j]))
            sum += (List[i][j] - List[k][j]) ** 2
#            print(sum)
        result = math.sqrt(sum)
#        print(result)
        if result.is_integer() == True:
            count += 1

print(count)

Submission status: Accepted

Solution code:
import numpy as np
A = []
B = 0
N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
for i in range(N):
  X[i] = np.array(X[i])
for i in range(N):
  for j in range(N):
    if np.linalg.norm(X[i]-X[j]) // 1 == np.linalg.norm(X[i]-X[j]):
      B = B + 1
print((B-N)//2)

Submission status: Accepted

Solution code:
# coding: utf-8
import math

def distance(X1, X2):
    square_sum = 0
    for x1, x2 in zip(X1, X2):
        square_sum = square_sum + (x1 - x2) ** 2
    return math.sqrt(square_sum)


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

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

Submission status: Accepted

Solution code:
import sys, math

a = [int(i) for i in input().split()]
N = a[0]
D = a[1]
X = []
for i in range(N):
  tmp = [int(i) for i in input().split()]
  X.append(tmp)

if D == 1:
  print(int(N*(N-1)/2))
  sys.exit(0)

count = 0
for n in range(0,N-1):
  for nn in range(n+1,N):
    result = 0
    for d in range(D):
      tmp = (X[n][d]-X[nn][d])**2
      result+=tmp
    result = math.sqrt(result)
    
    if result.is_integer():
      count+=1;
print(int(count))

Submission status: Accepted

Solution code:
import itertools

n,d=map(int, input().split()) 
x=[list(map(int, input().split()))  for i in range(n)]
v=[]
a=0
count=0
for i in itertools.combinations(x,r=2):
    for j in range(d):
        a+=(i[0][j]-i[1][j])**2
    v.append(a)
    a=0
c=round(n*(n-1)/2)
for i in range(c):
    if (v[i]**(1/2)).is_integer():
        count+=1
print(count)

Submission status: Accepted

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

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

final_ans=0

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

for i in range(0,N-1,1):
    for j in range(i+1,N,1):
        res = 0
        for k in range(0,D,1):
            res = res + (X[i][k] - X[j][k]) ** 2
        res = res ** 0.5
        if is_integer_num(res):
            final_ans = final_ans+1
print(final_ans)

Submission status: Accepted

Solution code:
import numpy as np


def main():
	n, d = [int(x) for x in input().split()]
	l = []
	for val in range(n):
		l.append([int(x) for x in input().split()])
	a = np.array(l)
	
	l = []
	for i, v1 in enumerate(a):
		for v2 in a[i:]:
			D = np.linalg.norm(v1 - v2)
			l.append(D)
	res = map(lambda x: float.is_integer(x), l)
	print(len([f for f in list(res) if f == True]) - n)

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
import math as ma

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

  return ma.sqrt(r)

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

ret = 0
for i in range(N):
  for j in range(i+1, N):
    d = dist(X[i], X[j], D)
    if (d == int(d)):
      ret = ret + 1

print(ret)