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: Wrong Answer

Solution code:
import math
N=list(map(int,input().split()))
a=['X' for _ in range(int(N[0]))]
A=0
for i in range(int(N[0])):
    a[i]=list(map(int,input().split()))
    for t in range(int(i)):
        for s in range(int(N[1])):
            Y=[(a[i][s]-a[t][s])**2]
            Z=sum(Y)
            if (math.sqrt(Z))- int(math.sqrt(Z))==0:
                A+=1
print(A)

Submission status: Wrong Answer

Solution code:
import math
N=list(map(int,input().split()))
a=['X' for _ in range(int(N[0]))]
A=0
for i in range(int(N[0])):
    a[i]=list(map(int,input().split()))
    for t in range(int(i)):
        Y=[(a[i][s]-a[t][s])**2 for s in range(int(N[1]))]
        Z=sum(Y)
        if (math.sqrt(Z)) == int(math.sqrt(Z)):
            A+=1
            print(Z,math.sqrt(Z))
print(A)

Submission status: Wrong Answer

Solution code:
import math
N=list(map(int,input().split()))
a=['X' for _ in range(int(N[0]))]
A=0
for i in range(int(N[0])):
    a[i]=list(map(int,input().split()))
    for t in range(int(i)):
        Y=[(a[i][s]-a[t][s])**2 for s in range(int(N[1]))]
        Z=sum(Y)
        if (math.sqrt(Z)-int(math.sqrt(Z)))==0:
            A+=1
            print(Z,math.sqrt(Z))
print(A)

Submission status: Wrong Answer

Solution code:
count = 0
n,d = map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
for j in range(n):
    for k in range(n-1):
        aa = l[j]
        bb = l[k]
        sum = 0
        for di in range(d-1):
            sum = sum + (abs(aa[di]-bb[di]))**2
        t = sum**(1/2)
        if t>0 and t.is_integer():
            count +=1 
print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import numpy as np
from itertools import combinations


def answer(l):
    results = []
    for i, j in combinations(l, 2):
        v_a = np.array(i)
        v_b = np.array(j)
        results.append(np.linalg.norm(v_a - v_b))
    return sum(float.is_integer(i) for i in results)


rows = sys.stdin.read().splitlines()
print(rows)
args = [list(map(int, row.split())) for row in rows][1:]
print(answer(args))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
from itertools import combinations

def answer(l):
    results = []
    for i, j in combinations(l, 2):
        v_a = np.array(i)
        v_b = np.array(j)
        results.append(np.linalg.norm(v_a - v_b))
    return sum(float.is_integer(i) for i in results)

rows = sys.stdin.readline()
args = [list(map(int, row.split())) for row in rows][1:]
print(answer(args))

Submission status: Wrong Answer

Solution code:
import math
N, D = map(int, input().split())
a = []
for i in range(N):
  b = map(int, input().split())
  a += b
print(a)
res = 0
for i in range(N-1):
  j = i + 1
  while(j < N):
    x = []
    y = []
    for k in range(D):
      x.append(a[i * D + k])
      y.append(a[j * D + k])
    tmp = 0
    for k in range(D):
      tmp += (x[k] - y[k]) ** 2
    if tmp == int(tmp ** 0.5) * int(tmp ** 0.5):
      res += 1
    j += 1
print(res)

Submission status: Wrong Answer

Solution code:
import math
n, d= (int(c) for c in input().split())

x = []

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

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

Submission status: Wrong Answer

Solution code:
N,D = map(int,input().split())
A=[]
C=0
D=0
E=0
for i in range (1,N+1):
    A.append(i)
for i in range (0,N):
    A[i]=list(map(int,input().split()))
for i in range (0,N-1):
    for j in range(i,N-1):
        for k in range(0,D):
            B=(A[j][k]-A[j+1][k])**2
            C+=B
        D=C
        C=0
        if ((D)**(1/2))%1 ==  (D)**(1/2):
            E+=1
print(E)

Submission status: Wrong Answer

Solution code:
import math
dlst = []

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

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

count=0
distance = 0

for i in range(N-1):
    for m in range(i+1,N):
        distance = 0
        for j in range(D):
            distance += (dlst[i][j] - dlst[m][j])**2
        judge=math.sqrt(distance)
        if judge.is_integer==True:
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import math
n, d= (int(c) for c in input().split())

x = []

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

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

Submission status: Wrong Answer

Solution code:
import math
N,D=map(int,input().split())
X=[list(map(int,input().split())) for _ in range(N)]
Y=X[1:]
Y.append(X[0])
def d(x,y):
    kyori=0
    for a,b in zip(x,y):
        kyori+=abs(a-b)**2
    return kyori
ans=0
for x,y in zip(X,Y):
    if math.sqrt(d(x,y)).is_integer():
        ans+=1
print(ans)

Submission status: Wrong Answer

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

for i in range(n):
  b=list(map(int,input().split()))
  a.append(b)
for i in range(n-1):
  for j in range(i+1,n):
    cnt=1
    dist=0
    for k in range(d):
      dist+=(a[i][k]-a[j][k])**2
      if cnt**2==dist:
        ans+=1
      cnt+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n,d=map(int,input().split())
a=[]
ans=0
cnt=1

for i in range(n):
  b=list(map(int,input().split()))
  a.append(b)
for i in range(n-1):
  for j in range(i+1,n):
    dist=0
    for k in range(d):
      dist+=(a[i][k]-a[j][k])**2
    while cnt**2>dist:
      if cnt**2==dist:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import math
dlst = []

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

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

lst=[1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025, 3136, 3249, 3364, 3481, 3600, 3721, 3844, 3969]
count=0
distance = 0
checklst=[]

for i in range(N):
    for m in range(i+1,N):
        distance = 0
        for j in range(D):
            distance += (dlst[i][j] - dlst[m][j])**2
        judge=math.sqrt(distance)
        if judge.is_integer==True:
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
dlst = []

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

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

lst=[1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025, 3136, 3249, 3364, 3481, 3600, 3721, 3844, 3969]
count=0
distance = 0
checklst=[]

for i in range(N):
    for m in range(i+1,N):
        distance = 0
        for j in range(D):
            distance += (dlst[i][j] - dlst[m][j])**2
        if distance in lst:
            count += 1
                
print(count)

Submission status: Wrong Answer

Solution code:
import math
N,D=map(int,input().split())
X=[list(map(int,input().split())) for _ in range(N)]
Y=X[1:]
Y.append(X[0])
ans=0
for n,(x,y) in enumerate(zip(X,Y)):
    kyori=0
    for a,b in zip(x,y):
        kyori+=abs(a-b)**2
    if math.sqrt(kyori).is_integer():
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N, D = map(int, input().split())
a = []
for i in range(N):
  b = map(int, input().split())
  a += b
print(a)
res = 0
for i in range(N-1):
  j = i + 1
  while(j < N):
    x = []
    y = []
    for k in range(D):
      x.append(a[i * D + k])
      y.append(a[j * D + k])
    tmp = 0
    for k in range(D):
      tmp += (x[k] - y[k]) ** 2
    s_tmp = math.sqrt(tmp)
    if(s_tmp.is_integer()):
      res += 1
    j += 1
print(res)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np

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

result=0
for v in itertools.combinations(e, 2):
    calc = sum(np.sqrt(abs((np.array(v[0]) - np.array(v[1])))^2))
    if isinstance(calc, int)==False:
        res=0
    else:
        res=1
    result=result+res
# 出力
print("{}".format(result))

Submission status: Wrong Answer

Solution code:
import numpy as np


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

for i in range(n-1):
    for j in range(n-i,n,1):
        a=np.array(X[i])
        b=np.array(X[i+1])
        u=b-a
        u=np.linalg.norm(u)
        if(int(u)==u):
            cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
N, D = map(int, input().split())
X = [[0]*D]*N
dis_double = 0
count = 0
for j in range(N): 
    X[j]= [int(i) for i in input().split()]
 
for l in range(N):
    for m in range(N):
        dis_double = 0
        for n in range(D):
            dis_double = dis_double + (abs(X[N-l-1][D-n-1]-X[N-m-1][D-n-1])*abs(X[N-l-1][D-n-1]-X[N-m-1][D-n-1]))
        if math.sqrt(dis_double).is_integer() & (not (dis_double==0)):
            count = count + 1
print(count/2)

Submission status: Wrong Answer

Solution code:
import math

n,d = map(int, input().split())
big_list = []
for i in range(1, n+1):
  big_list.append(list(map(int, input().split())))
count = 0

for i in range(1, n+1):
  for j in range(1, n):
    pa=big_list[(i+j)%n]
    pb=big_list[(i+1+j)%n]
    dim = 0
    for k in range(d):
      dim += (pa[k]-pb[k])**2
    ans = math.sqrt(dim)
    if ans%int(ans) == 0:
      count += 1
print((count+1)//2)

Submission status: Wrong Answer

Solution code:
import math

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

integer_count = 0

point_1 = list(map(int, input().split()))
point_2 = list(map(int, input().split()))

for _ in range(N-2):
    distance = 0
    for i in range(D):
        distance += (point_1[i] - point_2[i]) ** 2

    if math.sqrt(distance).is_integer():
        integer_count += 1

    point_1 = point_2.copy()
    point_2 = list(map(int, input().split()))

print(integer_count)

Submission status: Wrong Answer

Solution code:
d,n=input().split()
d=int(d)
n=int(n)
li=[[] for i in range(d)]
for i in range(d):
  a=input()
  li[i]+=a.split(" ")
  li[i]=[int(n) for n in li[i]]
 
import numpy as np
count=0
for i in range(d):
  for j in range(d):
    j=j+i
    if j==d-1:
      break
    vec_a = np.array(li[i])
    vec_b = np.array(li[j])
    result=np.linalg.norm(vec_a - vec_b)
    if result.is_integer():
      count+=1
print(count)

Submission status: Wrong Answer

Solution code:
import math
#Nこの点　D次元
N, D = map(int, input().split())
points = []
count = 0
for i in range(N):
    points.append(list(map(int, input().split())))

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

#一次元を考える
if D == 1:
    print(combinations_count(N, 2))

else:
    #number0のとりうるあたいは0からN-1
    for number0 in range(0,N):
        ans = 0
        if number0 != N-1: 
            for number1 in range(0,D):
                #print("先",number0,number1,"後",number0+1,number1)
                ans = ans + pow(abs(points[number0][number1]) - abs(points[number0+1][number1]),2)
        else:
            for number1 in range(0,D):
                #print("先",number0,number1,"後",0,number1)
                ans = ans + pow(abs(points[number0][number1]) - abs(points[0][number1]),2)

        #print("ans",math.sqrt(ans).is_integer())
        if math.sqrt(ans).is_integer() == True:
            count = count + 1

    print(count)

Submission status: Wrong Answer

Solution code:
N,D = map(int, input().split())
X = [[int(i) for i in input().split()] for i in range(N)]
S = set()
ans = 0
for i in range(N):
    for j in range(N):
        for k in range(D):
            S = S | {(X[i][k] - X[j][k])**2}
        sumS = sum(S)**(0.50)
        S = set()
        if i == j:
            ans += 0
        else:
            if sumS.is_integer() == True:
                ans +=1
print(ans//2)

Submission status: Wrong Answer

Solution code:
import numpy as np
ND =  list(map(int,input().split()))
Lis = []
for i in range(ND[0]):
    a =list(map(int,input().split()))
    Lis.append(a)
Lisnp = np.array(Lis)
Count = 0
for k in range(ND[0]):
    for g in range(k):
        u = Lisnp[k] - Lisnp[i]
        norm = np.linalg.norm(u)
        if norm.is_integer():
            Count += 1
print(Count)

Submission status: Wrong Answer

Solution code:
import numpy as np
nd = list(map(int,input().split()))
l = [input().split() for i in range(nd[0])]
ll = [[]for x in range(nd[0])]
c=0
for i in l:
  ll[c] = [int(n) for n in i]
  c+=1
count = 0
for i in range(nd[0]):
  for i2 in range(i+1,nd[0]):
    t=0
    for j in range(nd[1]):
      t = t + (ll[i][j]-ll[i2][j])**2
    t = np.sqrt(t)
    if isinstance(t,int):
      count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np

n, d = map(int, input().split())
ls = [[int(i) for i in input().split()] for _ in range(n)]
ls = np.array(ls)
ans = 0
total = 0
for i in range(d):
  total += (ls[-1][i] - ls[0][i]) ** 2
total **= 0.5
if total.is_integer():
  ans +=1


for i in range(n-1):
    total = 0
    for j in range(d):
        total += (ls[i][j] - ls[i+1][j]) **2
    total **= 0.5
    if total.is_integer():
        ans +=1
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

array = [[0 for i in range(10)] for j in range(10)]

for i in range(N):
    x = list(map(int, input().split()))
    for j in range(0, D):
        array[i][j] = x[j];
sum_dis = 0
for i in range(0,N-1):
    for j in range(i+1,N):
        dis = 0
        for k in range(D):
            dis += (array[i][k] - array[j][k])**2
        dis = math.sqrt(dis)
        if(type(dis) == int): sum_dis += 1
print(sum_dis)

Submission status: Wrong Answer

Solution code:
import math

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

array = [[0 for i in range(10)] for j in range(10)]
print(array)
for i in range(N):
    x = list(map(int, input().split()))
    for j in range(0, D):
        array[i][j] = x[j];
sum_dis = 0
for i in range(0,N-1):
    for j in range(i+1,N):
        dis = 0
        for k in range(D):
            dis += (array[i][k] - array[j][k])**2
        dis = math.sqrt(dis)
        if(type(dis) == int): sum_dis += 1
print(sum_dis)

Submission status: Wrong Answer

Solution code:
import math
#Nこの点　D次元
N, D = map(int, input().split())
points = []
count = 0
for i in range(N):
    points.append(list(map(int, input().split())))

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

#一次元を考える
if D == 1:
    print(combinations_count(N, 2))

else:
    #number0のとりうるあたいは0からN-1
    for number0 in range(0,N):
        ans = 0
        if number0 != N-1: 
            for number1 in range(0,D):
                #print("先",number0,number1,"後",number0+1,number1)
                ans = ans + pow(points[number0][number1] - points[number0+1][number1],2)
        else:
            for number1 in range(0,D):
                #print("先",number0,number1,"後",0,number1)
                ans = ans + pow(points[number0][number1] - points[0][number1],2)

        #print("ans",math.sqrt(ans).is_integer())
        if math.sqrt(ans).is_integer() == True:
            count = count + 1

    print(count)

Submission status: Wrong Answer

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

cnt = 0
R = []
for i in range(N):
    for j in range(i+1,N):
        r = 0
        for d in range(D):
            r += (X[i][d] - X[j][d]) ** 2
        for n in range(1,100):
            if r == n ** 2:
                cnt += 1
        R.append(r)

print(cnt)

Submission status: Wrong Answer

Solution code:
import math
N, D = map(int, input().split())
X = [[0]*D]*N
dis_double = 0
count = 0
for j in range(N): 
    X[j]= [int(i) for i in input().split()]
 
for l in range(N):
    dis_double=0
    for m in range(D):
        dis_double = dis_double + (abs(X[N-l-1][D-m-1]-X[N-l-2][D-m-1])*abs(X[N-l-1][D-m-1]-X[N-l-2][D-m-1]))
    if math.sqrt(dis_double).is_integer():
        count = count + 1
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
nd = list(map(int,input().split()))
l = [input().split() for i in range(nd[0])]
ll = [[]for x in range(nd[0])]
c=0
for i in l:
  ll[c] = [int(n) for n in i]
  c+=1
count = 0
for i in range(nd[0]):
  for i2 in range(nd[0]):
    t=0
    for j in range(nd[1]):
      t = t + (ll[i][j]-ll[i2][j])**2
    t = np.sqrt(t)
    if isinstance(t,int):
      count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import math

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

array = [[0]*10]*10

for i in range(N):
    x = list(map(int, input().split()))
    for j in range(D):
        array[i][j] = x[j];
sum_dis = 0
for i in range(0,N-1):
    for j in range(i+1,N):
        dis = 0
        for k in range(D):
            dis += (array[i][k] - array[j][k])**2
        dis = math.sqrt(dis)
        if(type(dis) == int): sum_dis += 1
print(sum_dis)

Submission status: Wrong Answer

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

x_lists = []
for i in range(n):
    x_list = list(input().split())
    x_lists.append(x_list)

cnt = 0
for i in range(n-1):
    dis = 0.0
    for j in range(d):
        y = ((int(x_lists[i][j]) - int(x_lists[i+1][j]))**2)
        dis = dis + (y)

    dis = dis ** 0.5
    if dis.is_integer() == True:
        cnt = cnt+1

dis = 0.0
for j in range(d):
    y = ((int(x_lists[n-1][j]) - int(x_lists[0][j]))**2)
    dis = dis + (y)
dis = dis ** 0.5
if dis.is_integer() == True:
    cnt = cnt+1

if d == 1:
    cnt = cnt*2
print(cnt)

Submission status: Wrong Answer

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

A=[[int(a) for a in input().split()]for a in range(N)]

def int_test(a,n):
    if a.is_integer():
        n+=1

n=0


for i in range(0,N):

    if i != N:
        for j in range(i+1,N):
            sq=0.0
            for k in range(0,D):
                sq=sq+(A[i][k]-A[j][k])**2

            sq2=math.sqrt(sq)
            print(i,j,k,sq2)
            if sq2.is_integer():
                n+=1
        #else:
    #        for k in range(1,D+1):
        #        sq=sq+(A[N][k]-A[N][k])**2
        #        sq2=math.sqrt(sq)
    #            int_test(sq2,n)
print(n)

Submission status: Wrong Answer

Solution code:
import math

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

array = [[0]*11]*11

for i in range(N):
    x = list(map(int, input().split()))
    for j in range(D):
        array[i][j] += x[j];
sum_dis = 0
for i in range(0,N-1):
    for j in range(i+1,N):
        dis = 0
        for k in range(D):
            dis += (array[i][k] - array[j][k])**2
        dis = math.sqrt(dis)
        if(type(dis) == int): sum_dis += 1
print(sum_dis)

Submission status: Wrong Answer

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

vc = []

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

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

cc = 0
for k, i in enumerate(vc):
    if len(vc) < 2:
        break
    print(k)
    for v in vc[k+1:]:
        summ = 0
        for (x, y) in zip(i, v):
            summ += abs(x - y) ** 2


        if isqrt(summ) == math.sqrt(summ):
            print("OK")
            cc += 1


print(cc)

Submission status: Wrong Answer

Solution code:
import math

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

array = [[0]*11]*11

for i in range(N):
    x = list(map(int, input().split()))
    for j in range(D):
        array[i][j] += x[j];
sum_dis = 0
for i in range(0,N-1):
    for j in range(i+1,N):
        dis = 0
        for k in range(D):
            dis += (array[i][k] - array[i][k])**2
        dis = math.sqrt(dis)
        if(type(dis) == int): sum_dis += 1
print(sum_dis)

Submission status: Wrong Answer

Solution code:
import math

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

array = [[0]*11]*11

for i in range(N):
    x = list(map(int, input().split()))
    for j in range(D):
        array[i][j] += x[j];
    
for i in range(0,N-1):
    for j in range(i+1,N):
        dis = 0
        sum_dis = 0
        for k in range(D):
            dis += (array[i][k] - array[i][k])**2
        dis = math.sqrt(dis)
        if(type(dis) == int): sum_dis += 1
print(sum_dis)

Submission status: Wrong Answer

Solution code:
N, D = map(int, input().split())
X = []
ans = 0
for _ in range(N):
    x = [int(s) for s in input().split()]
    X.append(x)
for i in range(N - 1):
    for j in range(i + 1, N):
        dist = 0
        for d in range(D):
            dist += (X[i][d] - X[j][d]) ** 2
        for n in range(500):
            if n * n == dist:
                ans += 1
                print(n, dist)
                break
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

array = [[0]*11]*11

for i in range(N):
    x = list(map(int, input().split()))
    for j in range(D):
        array[i][j] += x[j];
    
dis = 0
sum_dis = 0
for i in range(N-1):
    for j in range(i+1,N):
        for k in range(D):
            dis += (array[i][k] - array[i][k])**2
        dis = math.sqrt(dis)
        if(type(dis) == int): sum_dis += 1
print(sum_dis)

Submission status: Wrong Answer

Solution code:
d,n=input().split()
d=int(d)
n=int(n)
li=[[] for i in range(d)]
for i in range(d):
  a=input()
  li[i]+=a.split(" ")
  li[i]=[int(n) for n in li[i]]
 
import numpy as np
count=0
for i in range(d):
  if i == d-1:
    j=0
  else:
    j=i+1
  vec_a = np.array(li[i])
  vec_b = np.array(li[j])
  result=np.linalg.norm(vec_a - vec_b)
  if result.is_integer():
    count+=1
  if d==1:
    count=count*2
print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import math


def solve(N: int, D: int, X: "List[List[int]]"):
    res = 0

    for i in range(N):
        index = (i + 1) % N

        former = X[i]
        latter = X[index]

        sq = 0

        for d in range(D):
            sq += (abs(former[d] - latter[d])**2)

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

    if D == 1:
        print(res * 2)
    else:
        print(res)

    return


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

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math #math.sqrt(x)

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

ans = 0
for i in range(n):
    for q in range(n):
        sumv = 0
        if i == q:
            continue
        for j in range(d):
            sumv += (x[i][j] - x[q][j]) ** 2

        if math.sqrt(sumv).is_integer() == True:
            ans += 1

print(ans/2)

Submission status: Wrong Answer

Solution code:
N,D = map(int,input().split())
X = [list(input().split()) for _ in range(N)]
import math
a = 0
b = 0
c = 0
for i in range(N-1):
    for j in range(i+1,N):
        for k in range(D):
            a += (int(X[i][k])-int(X[j][k]))*(int(X[i][k])-int(X[j][k]))
        b = math.sqrt(a)
        if b.is_integer():
            c += 1
print(c)

Submission status: Wrong Answer

Solution code:
import math
N,D= (int(i) for i in input().split())
e = [[int(i) for i in input().split()] for i in range(N)]
counter=0
num=0
if D!=1:
    for i in e:
        e.pop(counter)

        for j in e:
            x=0
            for k in range(D):
                x+=(abs(i[k]-j[k]))**2
            x=math.sqrt(x)

            if(x.is_integer()):
                num+=1



        counter+=1
else:

    num+=1
    for i in e:
        e.remove(i)
        for j in e:
            x=(abs(i[0]-j[0]))**2
            x=math.sqrt(x)
            if(x.is_integer()):
                num+=1
            x=0

print(num)

Submission status: Wrong Answer

Solution code:
import math #math.sqrt(x)

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

ans = 0
for i in range(n):
    for q in range(n):
        sumv = 0
        if i == q:
            continue
        for j in range(d):
            if i == n - 1:
                sumv += (x[i][j] - x[1][j]) ** 2
            else:
                sumv += (x[i][j] - x[q][j]) ** 2

    if math.sqrt(sumv).is_integer() == True:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import math
b, c = map(int, input().split())
count  = 0
sum_a = 0
ans = 0
dim = []
for i in range(b):
  a = list(map(int,input().split()))
  dim.append(a)
               

while count < b :
  for i in range(c):
    if count+1 == b:
      sum_a +=  (dim[count][i] - dim[0][i])**2
    else:
      sum_a +=  (dim[count][i] - dim[count + 1][i])**2
  
  
  n = math.sqrt(sum_a)
  
  if n.is_integer():
    ans +=1
  
  sum_a = 0
  count +=1
  
print(ans)

Submission status: Wrong Answer

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

x_lists = []
for i in range(n):
    x_list = list(input().split())
    x_lists.append(x_list)

cnt = 0
for i in range(n-1):
    dis = 0.0
    for j in range(d):
        y = ((int(x_lists[i][j]) - int(x_lists[i+1][j]))**2)
        dis = dis + (y)

    dis = dis ** 0.5
    if dis.is_integer() == True:
        cnt = cnt+1

dis = 0.0
for j in range(d):
    y = ((int(x_lists[n-1][j]) - int(x_lists[0][j]))**2)
    dis = dis + (y)
dis = dis ** 0.5
if dis.is_integer() == True:
    cnt = cnt+1

print(cnt)

Submission status: Wrong Answer

Solution code:
import math
N,D= (int(i) for i in input().split())
e = [[int(i) for i in input().split()] for i in range(N)]
counter=0
num=0
if D!=1:
    for i in e:
        e.pop(counter)

        for j in e:
            x=0
            for k in range(D):
                x+=(abs(i[k]-j[k]))**2
                x=math.sqrt(x)

                if(x.is_integer()):
                    num+=1



        counter+=1
else:
    
    for i in e:
        e.remove(i)
        for j in e:
            x=(abs(i[0]-j[0]))**2
            x=math.sqrt(x)
            if(x.is_integer()):
                num+=1
            x=0
    num+=1
print(num)

Submission status: Wrong Answer

Solution code:
import math

n,d = map(int, input().split())
big_list = []
for i in range(1, n+1):
  big_list.append(list(map(int, input().split())))
count = 0

for i in range(1, n+1):
  for j in range(1, n):
    pa=big_list[(i+j)%n]
    pb=big_list[(i+1+j)%n]
    dim = 0
    for k in range(d):
      dim += (pa[k]-pb[k])**2
    ans = math.sqrt(dim)
    if ans%int(ans) == 0:
      count += 1
print(count//2)

Submission status: Wrong Answer

Solution code:
d,n=input().split()
d=int(d)
n=int(n)
li=[[] for i in range(d)]
for i in range(d):
  a=input()
  li[i]+=a.split(" ")
  li[i]=[int(n) for n in li[i]]
 
import numpy as np
count=0
for i in range(d):
  if i == d-1:
    j=0
  else:
    j=i+1
  vec_a = np.array(li[i])
  vec_b = np.array(li[j])
  result=np.linalg.norm(vec_a - vec_b)
  if result.is_integer():
    count+=1
print(count)

Submission status: Wrong Answer

Solution code:
import math as mt

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

xlis = [[0 for _ in range(D)] for _ in range(N)]

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

cnt = 0

for i in range(N):
    for s in range(N):
        res = 0
        if i == s:
            continue
        for l in range(D):
           res += ((xlis[i][l] - xlis[s][l]) ** 2)

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


print(cnt/2)

Submission status: Wrong Answer

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

for i in range(N):
    for j in range(i, N):
        if i != j:
            tmp = 0.0
            for k in range(D):
                tmp += abs(X[i][k] - X[j][k]) ** 2
            tmp = math.sqrt(tmp)
            print(tmp)
            if tmp.is_integer():
                result += 1

print(result)

Submission status: Wrong Answer

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

for i in range(N):
    for j in range(i, N):
        if i != j:
            tmp = 0.0
            for k in range(D):
                tmp += abs(X[i][k] - X[j][k]) ** 2
            tmp = math.sqrt(tmp)
            print(tmp)
            if tmp.is_integer():
                result += 1

print(result)

Submission status: Wrong Answer

Solution code:
N, D = map(int, input().split())
x = [None for k in range(N)]
for k in range(N):
  a = list(map(int, input().split()))
  x[k] = a
ans = 0
for n in range(N):
  for p in range(n-1):
    wa = 0
    for d in range(D):
      wa += (x[n][d] - x[p][d])**2
    t = wa ** 0.5
    if type(t) is int:
      ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import math

def dist(X1,X2):
  d=[abs(X1[i]-X2[i]) for i in range(len(X1))]
  d=[x**2 for x in d]
  d=sum(d)
  d=math.sqrt(d)
  return d
 
count=int(0)
N,D=map(int,input().split())
X=list(range(N))
for i in range(N):
  X[i]=list(map(int,input().split()))
for i in range(N):
  for j in range(i+1,N):
    d=dist(X[i],X[j])
    print(d)
    if d.is_integer():
      count=count+1
print(count)