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: Runtime Error

Solution code:
import math
N,D = map(int,input().split())
X = [list(map(float, input().split())) for i in range(N)]
counter = 0
for i, x0 in enumerate(X): 
    for x1 in X[i+1:]:
        if math.sqrt(sum([(a-b)**2 for a, b in zip(X0,X1)])).is_integer():
            counter+=1
print(counter)

Submission status: Runtime Error

Solution code:
n,d = map(int,input().split())
w = [list(map(int,input().split())) for a in range(n)]
c = 0
 
for i in range(n-1):
  for j in range(i+1,n+1):
    b = 0
    for m in range(d):
      b += (w[i][m]-w[j][m])**2
    if (b**0.5)==float(int(b**0.5)):
      c += 1
      
print(c)

Submission status: Runtime Error

Solution code:
n,d = map(int,input().split())
w = [list(map(int,input().split())) for a in range(n)]
c = 0
 
for i in range(n-1):
  for j in range(i+1,n):
    b = 0
    for m in range(d):
      b += (w[i][m]-w[j][m])**2
    if (b**0.5)　== float(int(b**0.5)):
      c += 1
      
print(c)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

for i in range(n-1):
  for j in range(i+1,n+1):
    b = 0
    for m in range(d):
      b += (x[i][m]-x[j][m])**2
    if (b**0.5)　== float(int(b**0.5)):
      c += 1
      
print(c)

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    A = list(map(int, input().split()))

    filled = [0]*(n+1)
    ans = []
    for i in range(n-1, -1, -1):
        if sum(filled[::i+1][1:]) % 2 != A[i]:
            filled[i+1] = 1
            ans.append(i+1)
    print(len(ans))
    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N,D = map(int,input().split())
#N,Dを入力
k = []
#座標のリストを作成
a = 0
#一時的に代入する値を作成
for i in range(N):
  k.append(map(int,input().split())
for i in range(N):
  for j in range(D):
#D回をN回繰り返す
    a += (k[i][j]-k[i+1][j])**2
  a = sqrt(a)
  if a%1 == 0:
  ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
tmp=input().split()
n=int(tmp[0])
d=int(tmp[1])
xn = [0]*d
num = 0

for i in range(n):
  xn[i] = input().split()
    
for i in range(n):
  for j in range(i+1, n):
    dist = 0
    for k in range(d):
      dist = dist + pow(int(xn[i][k])-int(xn[j][k]), 2)
#    print("test",dist)
#    print(int(pow(int(pow(dist,0.5)), 2)))
    if dist == int(pow(int(pow(dist,0.5)), 2)):
      num += 1
print(num)

Submission status: Runtime Error

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


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


result = 0

for i in range(n-1):
    total = 0
    for k in range(d-1):
        r = (x[i][k] - x[i+k][k]) ** 2
        total += r
    total = total ** 0.5
    if total.is_integer():
        result += 1
print(result)

Submission status: Runtime Error

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

l=[]
for _ in range(n):
  l1=[map(int,input().split())]
  l.append(l1)

import math

ans=[]
for a in range(n):
  for b in range(n):
    x=0
    for c in range(d):
      D=(l[a][c]-l[b][c])**2
      x+=D
    y=math.sqrt(x)
    ans.append(y.is_integer())
      
ans=(ans.count(True)-n)//2
print(ans)

Submission status: Runtime Error

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

l=[]
for _ in range(n):
  l1=[map(int,input().split())]
  l.append(l1)

import math

ans=[]
for a in range(n):
  for b in range(n):
    x=0
    for c in range(d):
      D=(l[a][c]-l[b][c])**2
      x+=D
    y=math.sqrt(x)
    ans.append(isinstance(y,int))
      
ans=(ans.count(True)-n)//2
print(ans)

Submission status: Runtime Error

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

l=[]
for _ in range(n):
  l1=[map(int,input().split())]
  l.append(l1)

import math

ans=[]
for a in range(n):
  for b in range(n):
    a=0
    for c in range(d):
      D=(l[a][c]-l[b][c])**2
      a+=D
    ans.append(isinstance(math.sqrt(a),int))
      
ans=(ans.count(True)-n)//2
print(ans)

Submission status: Runtime Error

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

l=[]
for _ in range(n):
  l1=[map(int,input().split())]
  l.append(l1)

import math

ans=[]
for a in range(n):
  for b in range(n):
    a=0
    for c in range(d):
      D=(l[a][c]-l[b][c])**2
      a+=D
    ans.append(isinstance(math.sqrt(a),int))
      
ans=sum(ans)-n
print(ans)

Submission status: Runtime Error

Solution code:
import sys
num = [int(i) for i in input().split()]
a = [[int(c) for c in l.strip()] for l in sys.stdin]
r = 0
ans = 0
for i in range(num[0]-1):
  for j in range(num[1]):
    d = (a[i][j]**2 + a[i+1][j]**2)
    r += d
  if int(r**0.5) == r**0.5:
    ans += 1
  r = 0

for j in range(num[1]):
  d = (a[num[0]-1][j]**2 + a[0][j]**2)
  r += d
if int(r**0.5) == r**0.5:
  ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
cnt = 0

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

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

Submission status: Runtime Error

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

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):
        if dist(x[i], x[i]).is_integer():
            ans += 1

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

kaijou = 0
cnt = 0

for i in n:
  for j in n:
    for k in d:
      kaijou += (x[j,k]**2-x[i,k]**2)
    if math.sqrt(kaioju).is_integer() == True:
      cnt += 1

print(cnt-n)

Submission status: Runtime Error

Solution code:
N, D = map(int, input().splice())
full_list = []
for i in range(N):
  full_list.append(list(map(int, input().splice())))
 
result = 0
 
for i in range(N):
  for j in range(N-i-1):
    length = 0
    for s in range(D):
      length += abs(full_list[i][s]**2 - full_list[j][s]**2)
    result += 1 if math.sqrt(length).is_integer() == True else 0

print(result)

Submission status: Runtime Error

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

result = 0

for i in range(N):
  for j in range(N-i-1):
    length = sum(abs(full_list[i][s]**2 - full_list[j][s]**2 for s in range(D)))
    result += 1 if

Submission status: Runtime Error

Solution code:
import atexit
import io
import sys

_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER


@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

import math
R = lambda : map(int,input().split())
n,d = R()
xs = [list(R()) for _ in range(n)]

def dist(y,z):
    return math.sqrt(sum([(y[i]-z[i])**2 for i in range(d)]))


count = 0
for i in range(n):
    for j in range(i+1,n):
        d = dist(xs[i],xs[j])
        if int(d)==d:
            count+=1
print(count)

Submission status: Runtime Error

Solution code:
import math
R = lambda : map(int,input().split())
n,d = R()
xs = [list(R()) for _ in range(n)]

def dist(y,z):
    return math.sqrt(sum([(y[i]-z[i])**2 for i in range(d)]))


count = 0
for i in range(n):
    for j in range(i+1,n):
        d = dist(xs[i],xs[j])
        if int(d)==d:
            count+=1
print(count)

Submission status: Runtime Error

Solution code:
N,D=map(int,input().split())
for i in range(N):
  X[i]=list(map(int,input().split()))
count=0
for i in range(N):
  for j in range(i,N):
    dis=0
    for k in range(D):
      dis += pow(X[i][k],2) + pow(X[j][k],2) 
    dis = sqrt(dis)
    if dis==int(dis):
      count+=1
print(count)

Submission status: Runtime Error

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

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

cnt = 0
for i in itertools.combinations(x, 2):
    y = i[0]
    z = i[1]
    res = 0
    for j in range(d):
        res +=(y[j]-z[j])**2

    res = math.sqrt(res)
    if res.is_integer():
        cnt+=1

print (cnt)

Submission status: Runtime Error

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

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

cnt = 0
for i in itertools.combinations(x, 2):
    y = i[0]
    z = i[1]
    res = 0
    for j in range(d):
        res +=(y[j]-z[j])**2

    res = math.sqrt(res)
    if res.is_integer():
        cnt+=1

print (cnt)

Submission status: Runtime Error

Solution code:
n,d = list(map(int, input().split()))
x = [[0 for x in range(2)] for y in range(3)]

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

cnt = 0
for i in itertools.combinations(x, 2):
    y = i[0]
    z = i[1]
    res = 0
    for j in range(d):
        res +=(y[j]-z[j])**2

    res = math.sqrt(res)
    if res.is_integer():
        cnt+=1

print (cnt)

Submission status: Runtime Error

Solution code:
import math
import itertools

n,d = list(map(int, input().split()))
x = [[0 for x in range(2)] for y in range(3)]

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

cnt = 0
for i in itertools.combinations(x, 2):
    y = i[0]
    z = i[1]
    res = 0
    for j in range(d):
        res +=(y[j]-z[j])**2

    res = math.sqrt(res)
    if res.is_integer():
        cnt+=1

print (cnt)

Submission status: Runtime Error

Solution code:
n,d = list(map(int, input().split()))
x = [[0 for x in range(2)] for y in range(3)]

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

cnt = 0
for i in itertools.combinations(x, 2):
    y = i[0]
    z = i[1]
    res = 0
    for j in d:
        res +=(y[j]-z[j])**2

    res = math.sqrt(res)
    if res.is_integer():
        cnt+=1

print (cnt)

Submission status: Runtime Error

Solution code:
N, D = [int(i) for i in input().split()]
X = [[int(i) for i in input().split()] for _ in range(N)]
 
ans = 0
for i in range(N):
    for j in range(i+1, N):
        yz = [abs((y - z)**2) for y, z in zip(X[i], X[j])]
        v = math.sqrt(sum(yz))
        if v == int(v):
            ans += 1
            
print(ans)

Submission status: Runtime Error

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

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

cnt = 0

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

print(cnt)

Submission status: Runtime Error

Solution code:
#create environment
import numpy as np
import pandas as pd
num = 1
i = 1
k = 1
df = pd.DataFrame()
count_num = 0
f = lambda x: (x**2)

#input1 N, D (numeric)
N, D = map(int, input().split())
#input2
for l in range(1, N):
  a = map(int, input().split())
  if a is none:
    break
  df[l] = a

# make combination
df_new = df.T
#print(df_new)
for i in range(0, len(df_new.index)):
  for j in range(k, len(df_new.index)):
#    print_str = str(i) + '-' + str(j)
#    print(print_str)
    k = k + 1
    df_new_ij = df_new.loc[[i,j],:]
    obj_num = np.sqrt(df_new_ij.apply(f).cumsum().iloc[1,:].cumsum()[len(df['a'])-1])
    
    if obj_num == round(obj_num):
      count_num = count_num + 1

#print
print(count_num)

Submission status: Runtime Error

Solution code:
#create environment
import numpy as pd
num = 1
i = 1
k = 1
df = pd.DataFrame()
count_num = 0
f = lambda x: (x**2)

#input1 N D (numeric)
N, D = map(int, input().split())
#input2
for l in range(1, N):
  a = map(int, input().split())
  if a is none:
    break
  df[l] = a

# make combination
df_new = df.T
#print(df_new)
for i in range(0, len(df_new.index)):
  for j in range(k, len(df_new.index)):
#    print_str = str(i) + '-' + str(j)
#    print(print_str)
    k = k + 1
    df_new_ij = df_new.loc[[i,j],:]
    obj_num = np.sqrt(df_new_ij.apply(f).cumsum().iloc[1,:].cumsum()[len(df['a'])-1])
    
    if obj_num == round(obj_num):
      count_num = count_num + 1

#print
print(count_num)

Submission status: Runtime Error

Solution code:
#create environment
import numpy as pd
num = 1
i = 1
k = 1
df = pd.DataFrame()
count_num = 0
f = lambda x: (x**2)

#input1 N D (numeric)
N, D = map(int, input().split())
#input2
for l in range(1, N):
  a = map(int, input().split())
  if a is none:
    break
  df[l] = a

# make combination
df_new = df.T
#a_new = a.T
print(df_new)
for i in range(0, len(df_new.index)):
  for j in range(k, len(df_new.index)):
#    print_str = str(i) + '-' + str(j)
#    print(print_str)
    k = k + 1
    df_new_ij = df_new.loc[[i,j],:]
    obj_num = np.sqrt(df_new_ij.apply(f).cumsum().iloc[1,:].cumsum()[len(df['a'])-1])
    
    if obj_num == round(obj_num):
      count_num = count_num + 1

#print
print(count_num)

Submission status: Runtime Error

Solution code:
#create environment
import numpy as pd
num = 1
i = 1
k = 1
df = pd.DataFrame()
count_num = 0
f = lambda x: (x**2)

#input1 N D (numeric)
N, D = map(int, input().split())
#input2
for l in range(0, N):
  a = map(int, input().split())
  if a is none:
    break
  df[l] = a

# make combination
df_new = df.T
#a_new = a.T
print(df_new)
for i in range(0, len(df_new.index)):
  for j in range(k, len(df_new.index)):
#    print_str = str(i) + '-' + str(j)
#    print(print_str)
    k = k + 1
    df_new_ij = df_new.loc[[i,j],:]
    obj_num = np.sqrt(df_new_ij.apply(f).cumsum().iloc[1,:].cumsum()[len(df['a'])-1])
    
    if obj_num == round(obj_num):
      count_num = count_num + 1

#print
print(count_num)

Submission status: Runtime Error

Solution code:
#create environment
import numpy as pd
num = 1
i = 1
k = 1
df = pd.DataFrame()
count_num = 0
f = lambda x: (x**2)

#input1 N D (numeric)
N, D = map(int, input().split())
#input2
for l in (1, N):
  a = map(int, input().split())
  if a is none:
    break
  df[l] = a

# make combination
df_new = df.T
#a_new = a.T
print(df_new)
for i in range(0, len(df_new.index)):
  for j in range(k, len(df_new.index)):
#    print_str = str(i) + '-' + str(j)
#    print(print_str)
    k = k + 1
    df_new_ij = df_new.loc[[i,j],:]
    obj_num = np.sqrt(df_new_ij.apply(f).cumsum().iloc[1,:].cumsum()[len(df['a'])-1])
    
    if obj_num == round(obj_num):
      count_num = count_num + 1

#print
print(count_num)

Submission status: Runtime Error

Solution code:
#create environment
import numpy as pd
num = 1
i = 1
k = 1
df = pd.DataFrame()
count_num = 0
f = lambda x: (x**2)

#input1 N D (numeric)
N, D = map(int, input().split())
#input2
for l in (1, N):
  a = map(int, input().split())
  if a is none:
    break
  df[l] = a

#for num > 2:
#  a = map(int, input().split())
#  if a is none:
#    break
#  df[i] = a
#  i = i + 1

# make combination
df_new = df.T
#a_new = a.T
print(df_new)
for i in range(0, len(df_new.index)):
  for j in range(k, len(df_new.index)):
    print_str = str(i) + '-' + str(j)
    print(print_str)
    k = k + 1
    df_new_ij = df_new.loc[[i,j],:]
    obj_num = np.sqrt(df_new_ij.apply(f).cumsum().iloc[1,:].cumsum()[len(df['a'])-1])
    
    if obj_num == round(obj_num):
      count_num = count_num + 1

print(count_num)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

n = 0
for i in range(N):
  for j in range(i+1, N):
    dist = linalg.norm(X[i]-X[j])
    if dist.is_integer():
      n += 1

print(n)

Submission status: Runtime Error

Solution code:
temp=input().split()
N=int(temp[0])
D=int(temp[1])

points=[]
for i in range(N):
  temp=input().split()
  points.append([int(temp[x]) for x in range(D)])
  
counter=0
for i in range(N):
  for j in range(i+1, N):
    l=pow(sum([pow(points[i, x]-points[j, x], 2) for x in range(D)]), 1/2)
    if l.is_integer():
      counter+=1
      
print(counter)

Submission status: Runtime Error

Solution code:
temp=input().split()
N=int(temp[0])
D=int(temp[1])

points=[]
for i in range(N):
  temp=input().split()
  points.add([int(temp[x]) for x in range(D)])
  
counter=0
for i in range(N):
  for j in range(i+1, N):
    l=pow(sum([pow(points[i, x]-points[j, x], 2) for x in range(D)]), 1/2)
    if l.is_integer():
      counter+=1
      
print(counter)

Submission status: Runtime Error

Solution code:
temp=input().split()
N=int(temp[0])
D=int(temp[1])

points=[]
for i in range(N):
  temp=input().split()
  points.add([int(temp[x]) for x in range(D)])
  
counter=0
for i in range(N):
  for j in range(i+1, N):
    l=pow(sum([pow(points[i, x]-points[j, x], 2) for x in range(D)]), 1/2)
    if l==int(l):
      counter+=1
      
print(counter)

Submission status: Runtime Error

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

# N, D = [3, 4]
# X = [
# [-3, 7, 8, 2],
# [-12, 1, 10, 2],
# [-2, 8, 9, 3]
# ]

from math import sqrt

ans = 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 sqrt(d) % 1 == 0:
            ans += 1
print(ans)

Submission status: Runtime Error

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

# N, D = [3, 4]
# X = [
# [-3, 7, 8, 2],
# [-12, 1, 10, 2],
# [-2, 8, 9, 3]
# ]

from math import sqrt
# import numpy

ans = 0
for i in range(N):
    for j in range(i):
        d = [(x[0] - x[1]) ** 2 for x in zip(X[i], X[j])]
        if sqrt(sum(d)) % 1 == 0:
            ans += 1
print(ans)

Submission status: Runtime Error

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

# N, D = [3, 4]
# X = [
# [-3, 7, 8, 2],
# [-12, 1, 10, 2],
# [-2, 8, 9, 3]
# ]

import math
import numpy

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

Submission status: Runtime Error

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

import math

ans = 0
for i in range(5):
    for j in range(i):
        # print(i,j)
        d = X[i] - X[j]
        if math.sqrt(d.dot(d)).is_integer():
            ans += 1
print(ans)

Submission status: Runtime Error

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

c=0
for i in range(n-1):
  for j in range(i+1,n):
    c+=(sum((a-b)**2 for a,b in zip(x[i],x[j]))**0.5).is_integer

print(c)

Submission status: Runtime Error

Solution code:
N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
if D==1:
  print( N*(N-1)/2)
#次元から取りうる距離の最大整数値を取得
max_num = [None,None,56,69,80,89,97,105,113,120,126][D] 
#再帰　2分探索
def binarysearch(heihouwa,minnum,maxnum):
  #中央値を計算
  num = (maxnum+minnum)//2
  #中央値と最小値が一致した場合：探索結果　存在しない（再帰終了）
  if num == minnum:
    return False
  #中央値二乗と対象の数値が一致した場合：探索結果　存在する（再帰終了）
  elif heihouwa == num**2:
    return True
  #対象の数値＞中央値の2乗ならば、中央値を最小値として再帰
  elif heihouwa > num**2:
    return binarysearch(heihouwa, num, maxnum)
  #対象の数値＜中央値の2乗ならば、中央値を最大値として再帰
  else:
    return binarysearch(heihouwa, minnum, num)
count = 0
#組み合わせループ
for i in range(N-1):
  for j in range(N-i-1):
    j+=i+1
    #2点間の距離二乗
    heihouwa = sum( [ (X[i][k]-X[j][k])**2 for k in range(D) ] )
    #整数の二乗かどうかを2分探索
    count += binarysearch(heihouwa,1,max_num)
print(count)

Submission status: Runtime Error

Solution code:
N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
#1次元の場合
if D==1:
    print(N*(N-1)/2)
#次元から取りうる距離の最大整数値を取得
max_num = [None,None,
           56,
           69,
           80,
           89,
           97,
           105,
           113,
           120,
           126][D]
#再帰　2分探索
def binarysearch(heihouwa,minnum,maxnum):
    #中央値を計算
    num = (maxnum+minnum)//2
    #中央値と最小値が一致した場合：探索結果　存在しない（再帰終了）
    if num == minnum:
        return False
    #中央値二乗と対象の数値が一致した場合：探索結果　存在する（再帰終了）
    elif heihouwa == num**2:
        return True
    #対象の数値＞中央値の2乗ならば、中央値を最小値として再帰
    elif heihouwa > num**2:
        return binarysearch(heihouwa, num, maxnum)
    #対象の数値＜中央値の2乗ならば、中央値を最大値として再帰
    else:
        return binarysearch(heihouwa, minnum, num)
count = 0
#組み合わせループ
for i in range(N-1):
    for j in range(N-i-1):
        j+=i+1
 
        #2点間の距離二乗
        heihouwa = sum( [ (X[i][k]-X[j][k])**2 for k in range(D) ] )
 
        #整数の二乗かどうかを2分探索
        count += binarysearch(heihouwa,1,max_num)
print(count)

Submission status: Runtime Error

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

#1次元の場合
if D==1:
    return N*(N-1)/2

#次元から取りうる距離の最大整数値を取得
max_num = [None,None,
           56,
           69,
           80,
           89,
           97,
           105,
           113,
           120,
           126][D]

#再帰　2分探索
def binarysearch(heihouwa,minnum,maxnum):
    #中央値を計算
    num = (maxnum+minnum)//2

    #中央値と最小値が一致した場合：探索結果　存在しない（再帰終了）
    if num == minnum:
        return False

    #中央値二乗と対象の数値が一致した場合：探索結果　存在する（再帰終了）
    elif heihouwa == num**2:
        return True

    #対象の数値＞中央値の2乗ならば、中央値を最小値として再帰
    elif heihouwa > num**2:
        return binarysearch(heihouwa, num, maxnum)

    #対象の数値＜中央値の2乗ならば、中央値を最大値として再帰
    else:
        return binarysearch(heihouwa, minnum, num)

count = 0

#組み合わせループ
for i in range(N-1):
    for j in range(N-i-1):
        j+=i+1

        #2点間の距離二乗
        heihouwa = sum( [ (X[i][k]-X[j][k])**2 for k in range(D) ] )

        #整数の二乗かどうかを2分探索
        count += binarysearch(heihouwa,1,max_num)

print(count)

Submission status: Runtime Error

Solution code:
N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
if D==1:
  return N*(N-1)/2

#次元から取りうる距離の最大整数値を取得
max_num = [None,None,56,69,80,89,97,105,113,120,126][D]

#再帰　2分探索
def binarysearch(heihouwa,minnum,maxnum):
  #中央値を計算
  num = (maxnum+minnum)//2
  #中央値と最小値が一致した場合：探索結果　存在しない（再帰終了）
  if num == minnum:
    return False
  #中央値二乗と対象の数値が一致した場合：探索結果　存在する（再帰終了）
  elif heihouwa == num**2:
    return True
  #対象の数値＞中央値の2乗ならば、中央値を最小値として再帰
  elif heihouwa > num**2:
    return binarysearch(heihouwa, num, maxnum)
  #対象の数値＜中央値の2乗ならば、中央値を最大値として再帰
  else:
    return binarysearch(heihouwa, minnum, num)
count = 0
#組み合わせループ
for i in range(N-1):
  for j in range(N-i-1):
    j+=i+1
    #2点間の距離二乗
    heihouwa = sum( [ (X[i][k]-X[j][k])**2 for k in range(D) ] )
    #整数の二乗かどうかを2分探索
    count += binarysearch(heihouwa,1,max_num)
print(count)

Submission status: Runtime Error

Solution code:
N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
if D==1:
  return N*(N-1)/2
 
#次元から取りうる距離の最大整数値を取得
max_num = [None,None,
           56,
           69,
           80,
           89,
           97,
           105,
           113,
           120,
           126][D]
 
#再帰　2分探索
def binarysearch(heihouwa,minnum,maxnum):
  #中央値を計算
  num = (maxnum+minnum)//2
 
  #中央値と最小値が一致した場合：探索結果　存在しない（再帰終了）
  if num == minnum:
    return False
 
  #中央値二乗と対象の数値が一致した場合：探索結果　存在する（再帰終了）
  elif heihouwa == num**2:
    return True
 
  #対象の数値＞中央値の2乗ならば、中央値を最小値として再帰
  elif heihouwa > num**2:
    return binarysearch(heihouwa, num, maxnum)
 
  #対象の数値＜中央値の2乗ならば、中央値を最大値として再帰
  else:
    return binarysearch(heihouwa, minnum, num)

count = 0
 
#組み合わせループ
for i in range(N-1):
  for j in range(N-i-1):
    j+=i+1
 
    #2点間の距離二乗
    heihouwa = sum( [ (X[i][k]-X[j][k])**2 for k in range(D) ] )
 
    #整数の二乗かどうかを2分探索
    count += binarysearch(heihouwa,1,max_num)

print(count)

Submission status: Runtime Error

Solution code:
N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
if D==1:
  return N*(N-1)/2

#次元から取りうる距離の最大整数値を取得
max_num = [None,None,
           56,
           69,
           80,
           89,
           97,
           105,
           113,
           120,
           126][D]

#再帰　2分探索
def binarysearch(heihouwa,minnum,maxnum):
  #中央値を計算
  num = (maxnum+minnum)//2

  #中央値と最小値が一致した場合：探索結果　存在しない（再帰終了）
  if num == minnum:
    return False

  #中央値二乗と対象の数値が一致した場合：探索結果　存在する（再帰終了）
  elif heihouwa == num**2:
    return True

  #対象の数値＞中央値の2乗ならば、中央値を最小値として再帰
  elif heihouwa > num**2:
    return binarysearch(heihouwa, num, maxnum)

  #対象の数値＜中央値の2乗ならば、中央値を最大値として再帰
  else:
    return binarysearch(heihouwa, minnum, num)

count = 0

#組み合わせループ
for i in range(N-1):
  for j in range(N-i-1):
    j+=i+1

    #2点間の距離二乗
    heihouwa = sum( [ (X[i][k]-X[j][k])**2 for k in range(D) ] )

    #整数の二乗かどうかを2分探索
    count += binarysearch(heihouwa,1,max_num)

return count

Submission status: Runtime Error

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

for i in range(N-1):
    c = X[i]
    for j in range(i+1,N):
        d = X[j]
        e = c-d
        f = np.square(e)
        g = sum(f)
        h = np.sqrt(g)
        l = int(h**.5)
        if abs(l*l-h) <1e-6:
            cnt +=1
print(cnt)

Submission status: Runtime Error

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

for i in range(N-1):
    c = X[i]
    for j in range(a+1,N):
        d = X[j]
        e = c-d
        f = np.square(e)
        g = sum(f)
        h = np.sqrt(g)
        l = int(h**.5)
        if abs(l*l-h) <1e-6:
            cnt +=1
print(cnt)

Submission status: Runtime Error

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

for i in range(N-1):
    c = X[a]
    for j in range(a+1,N):
        d = X[b]
        e = c-d
        f = np.square(e)
        g = sum(f)
        h = sqrt(g)
        l = int(h**.5)
        if abs(l*l-h) <1e-6:
            cnt +=1
print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np

S      = input()
S      = S.split()
N      = int(S[0])
D      = int(S[1])
matrix = np.zeros([N, D])
count  = 0


for i in range(0, N, 1):
    X_vector = input()
    X_vector = X_vector.split()
    for j in range(0, D, 1):
        matrix[i][j] = int(X_vector[j])

for i in range(0, N, 1):
    a_vector = matrix[i]
    for j in range(i+1, N, 1):
        b_vector = matrix[j]
        length = np.linalg.norm(b_vector-a_vector)
        if length.is_integer()):
            count = count + 1
print(count)

Submission status: Runtime Error

Solution code:
import numpy as np

S      = input()
S      = S.split()
N      = int(S[0])
D      = int(S[1])
matrix = np.zeros([N, D])
count  = 0


for i in range(0, N, 1):
    X_vector = input()
    X_vector = X_vector.split()
    for j in range(0, D, 1):
        matrix[i][j] = int(X_vector[j])

for i in range(0, N, 1):
    a_vector = matrix[i]
    for j in range(i+1, N, 1):
        b_vector = matrix[j]
        length = np.linalg.norm(b_vector-a_vector)
        if isinstance(length, int):
            count++
print(count)

Submission status: Runtime Error

Solution code:
import numpy as np

S      = input()
S      = S.split()
N      = int(S[0])
D      = int(S[1])
matrix = np.zeros([N, D])
count  = 0


for i in range(0, N, 1):
    X_vector = input()
    X_vector = X_vector.split()
    for j in range(0, D, 1):
        matrix[i][j] = int(X_vector[j])

for i in range(0, N, 1):
    a_vector = matrix[i]
    for j in range(i+1, N, 1):
        b_vector = matrix[j]
        length = np.linalg.norm(b_vector-a_vector)
        if float(length) / float(length) == 0.0:
            count++

print(count)