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:
N, D = map(int,input().split())
K = [list(map(int,input().split()))for x in range(N)]
ans = 0
for i in range(N-1):
  for j in range(i+1,N):
    goukei=0
    for a,b in zip(K[i],K[j]):
      goukei += (a-b)**2
    ans += (goukei**0.5).is_integer()
print(K)

Submission status: Wrong Answer

Solution code:
N,D = map(int,input().split())
X = [0]+[list(map(int,input().split()))for _ in range(N)]
List = []
ans = 0
for j in range(1,N):
    for i in range(j+1,N+1):
        v = 0
        for k in range(D):
            v+=(X[j][k]-X[i][k])**2
        for l in range(v):
            List.append(l**2)
        if v in List:
            ans+=1
            
print(ans)

Submission status: Wrong Answer

Solution code:
N,D = map(int,input().split())
X = [0]+[list(map(int,input().split()))for _ in range(N)]
List = []
i = 1
p = 0
ans = 0
while p <= 40*D:
    p = i**2
    List.append(p)
    i+=1
for j in range(1,N):
    for i in range(j+1,N+1):
        v = 0
        for k in range(D):
            v+=(X[j][k]-X[i][k])**2
        if v in List:
            ans+=1
        
print(ans)

Submission status: Wrong Answer

Solution code:
N,D = map(int,input().split())
X = [0]+[list(map(int,input().split()))for _ in range(N)]
List = []
i = 1
p = 0
ans = 0
while p < 40*D:
    p = i**2
    List.append(p)
    i+=1
for j in range(1,N):
    for i in range(j+1,N+1):
        v = 0
        for k in range(D):
            v+=(X[j][k]-X[i][k])**2
        if v in List:
            ans+=1
        
print(ans)

Submission status: Wrong Answer

Solution code:
N,D = map(int,input().split())
X = [0]+[list(map(int,input().split()))for _ in range(N)]
List = []
i = 0
p = 0
ans = 0
while p < 40*D:
    p = i**2
    List.append(p)
    i+=1
for j in range(1,N):
    for i in range(j+1,N+1):
        v = 0
        for k in range(D):
            v+=(X[j][k]-X[i][k])**2
        if v in List:
            ans+=1
        
print(ans)

Submission status: Wrong Answer

Solution code:
N,D = map(int,input().split())
X = [0]+[list(map(int,input().split()))for _ in range(N)]
List = []
i = 0
p = 0
ans = 0
while p < 40*D:
    p = i**2
    List.append(p)
    i+=1
for j in range(1,N+1):
    for i in range(j+1,N+1):
        v = 0
        for k in range(D):
            v+=(X[j][k]-X[i][k])**2
        if v in List:
            ans+=1
        
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n,d =map(int,input().split())
l=[]
ans=0
for i in range(n):
    l.append(list(map(int,input().split())))
for i in range(n):
    for j in range(i):
        z=0
        for k in range(d):
            z+=(l[i][k]-l[j][k])**2
        if float(np.sqrt(z)).is_integer:
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n,d=map(int,input().split())
w=[]
for i in range(n):
    l=[int(i) for i in input().split()]
    w.append(l)
ans=0
chk=set([int(i)**2 for i in range(0,41,1)])
for i in range(n-1):
    for j in range(i+1,n):
        cnt=0
        for k in range(d):
            cnt+=(w[i][k]-w[j][k])**2
        if cnt in chk:
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n, d = map(int, input().split())
x = []
cnt = 0
for i in range(n):
    a = list(map(int, input().split()))
    print(a)
    x.append(a)
for i in range(n):
    for j in range(i+1, n):
        val = 0
        for k in range(d):
            val += (x[i][k]-x[j][k]) ** 2
        dist = val ** 0.5
        if dist%1 == 0:
            if dist != 0:
                cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n, d = map(int, input().split())
x = []
cnt = 0
for i in range(n):
    a = list(map(int, input().split()))
    print(a)
    x.append(a)
for i in range(n):
    val = 0
    for j in range(d):
        if i != n-1:
            val += x[i+1][j]-x[i][j]
        else:
            val += x[i][j]-x[0][j]
    if abs(val) ** 0.5 % 1 == 0:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

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

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

count = []

for i in range(N):
  for k in range(N):
    #横軸の距離を測ってる的な？
    z = 0
    for j in range(D):
      z += ((lst[i][j] - lst[k][j])**2)
    if type(math.sqrt(z)) == int:
      if not math.sqrt(z) in count:
        count.append(math.sqrt(z))
      
print(len(count))

Submission status: Wrong Answer

Solution code:
N,D=map(int,input().split())
X=[0]*N
res=0
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 = 0
        for k in range(D):
            k+=(X[i][k]-X[j][k])**2
            k=k**0.5
        if k.is_integer():
            res+=1
print(res)

Submission status: Wrong Answer

Solution code:
import numpy as np
n,d = list(map(int,input().split()))
t = np.array([list(map(int,input().split())) for i in range(n)])
cnt = 0

for i in range(n):
	for h in range(n):
		x = (sum((t[i]-t[h])**2))**0.5
		if x % 1 == 0:
			cnt += 1
	np.delete(t,i,0)
			
print(int(cnt-n))

Submission status: Wrong Answer

Solution code:
n,d=map(int,input().split())
l1=[]
for a in range(n):
    l=list(map(int,input().split()))
    l1.append(l)
sum2=0
count=0
for i in range(n-1):
    for j in range(i+1,n):
        for k in range(d):
            sum2+=(l1[i][k]-l1[j][k])**2
        if (sum2**0.5)%1==0:
            count+=1
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, d = map(int, input().split())
lst = []
length = 0
cnt = 0
for i in range(n):
    a = map(int, input().split())
    lst.append(list(a))
for i in range(1, n):
    for j in range(i, n):
        for k in range(d):
            length += (lst[i][k]-lst[j-1][k])**2
            length = length ** 0.5
            if length%1 == 0:
                if length != 0:
                    cnt += 1
        length = 0
print(cnt)

Submission status: Wrong Answer

Solution code:
n, d = map(int, input().split())
lst = []
length = 0
cnt = 0
for i in range(n):
	a = map(int, input().split())
	lst.append(list(a))
for i in range(1, n):
	for j in range(i, n):
		for k in range(d):
			length += (lst[i][k]-lst[j-1][k])**2
			length = length ** 0.5
			print(length, length%1)
		if length%1 == 0:
			print("AAA")
			if length != 0:
				print(length)
				cnt += 1
		length = 0
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

N, D = map(int, input().split())
X = np.array([list(map(int, input().split())) for _ in range(N)])
ans = 0
Dist = 0

for i in range(N - 1):
    for j in range(i + 1, N):
        Dist = np.sum((X[i] - X[j]) ** 2)
        print(Dist)
        for k in range(1, Dist // 2 + 2):
            if k ** 2 == Dist:
                ans += 1
print(ans)

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

Submission status: Wrong Answer

Solution code:
import math
n,d=map(int,input().split())
x=[[int(i) for i in input().split()] for i in range(n)] 
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        check = 0
        for k in range(d):
            check += (x[i][k]-x[j][k])**2
        if type(check) is int:
            ans+=1
print(ans)

Submission status: Wrong Answer

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

x = np.array(input().split(" ") , dtype="int32")
ans = 0
for i in range(N-1):
    x = np.append(x, np.array(input().split(" ") , dtype="int32"))
print(x)
x = x.reshape(N , D)
print(x)
for i in range(N):
    for n in range(i+1 , N):
        dist = np.linalg.norm(x[i] - x[n])
        if math.ceil(dist)==math.floor(dist):
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
l,r = map(int,input().split())

r = min(r, l+4038)

min = 99999999
for i in range(l,r):
  for j in range(i+1,r+1):
    value = (i*j)%2019
    if min > value:
      min = value
print(min)

Submission status: Wrong Answer

Solution code:
N,D = map(int,input().split())
X=[]
for i in range(N):
    X.append(list(map(int, input().split())))
    
ans=0
dist=0
for i in range(N):
    for j in range(N):
        if i < j:
            for k in range(D):
                dist += (X[i][k] - X[j][k])**2
            dist = dist ** (1/2)
            if round(dist,0) == dist:
                ans += 1
            
print(ans)

Submission status: Wrong Answer

Solution code:
N, D = map(int, input().split())
X =[]
for i in range(N):
  X.append(list(map(int, input().split())))
ans=0
dist=0
for i in range(N):
  for j in range(N):
    if i < j:
      for k in range(D):
        dist += abs(X[i][k] - X[j][k])**2
      dist = dist**(1/2)
      if round(dist,0) == dist:
        ans += 1
      
print(ans)

Submission status: Wrong Answer

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

squares=[i**2 for i in range(100)]
ans=0
for i in range(n):
    for j in range(i+1,n):
        dist = sum((x[i][m]-x[j][m])**2 for m in range(d)) 
        if dist in squares: ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

for i in range(n):
    for j in range(i + 1, n):
        l = 1
        for k in range(d):
            sum += (x[i][k] - x[j][k]) ** 2
        while (l ** 2 <= sum):
            if l ** 2 == sum:
                cnt += 1
            l += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
import math

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

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

print(cnt)

Submission status: Wrong Answer

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

for i in range(n):
    for j in range(i + 1, n):
        for k in range(d):
            sum += (x[i][k] - x[j][k]) ** 2
        distance = sum ** 0.5
        if distance.is_integer():
            cnt += 1

print(cnt)

Submission status: Wrong Answer

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

for i in range(n):
    for j in range(i + 1, n):
        for k in range(d):
            sum += (x[i][k] - x[j][k]) ** 2
        distance = sum ** 0.5
        if int(distance) - distance == 0:
            cnt += 1

print(cnt)

Submission status: Wrong Answer

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

for i in range(n):
  for j in range(i+1,n):
    for k in range(d):
      dist+=(x[i][k]-x[j][k])**2
    dist=dist**0.5
    if dist.is_integer():
      count+=1
print(count)

Submission status: Wrong Answer

Solution code:
import math

def distance(l1,l2):
    d2 = 0
    for i in range(len(l1)):
        l = l1[i] - l2[i]
        d2 += l ** 2
    return d2

def issqrt(num):
    cand = math.sqrt(num)
    if (cand + 1) ** 2 == num:
        return True
    if cand ** 2 == num:
        return True
    if (cand - 1) ** 2 == num:
        return True
    return False


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

count = 0
for i in range( N - 1):
    for j in range( i+1, N):
        d = distance( cord[i],cord[j])
        #print( "({} {}) => {} {}".format(i,j,d,math.sqrt(d)))
        if issqrt( d ):
            count += 1

print( count )

Submission status: Wrong Answer

Solution code:
num=input()
K,X=[int(s) for s in num.split(" ")]

max=X+(K-1)
min=X-(K-1)

list=[]
for i in range(min,max+1,1):
    list.append(i)

ans=" ".join(map(str,list))

print(ans)

Submission status: Wrong Answer

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

Solution code:
import numpy as np

N, D = list(map(int, input().split()))
full_list = []
for i in range(N):
  full_list.append(list(map(int, input().split())))
 
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 np.sqrt(length).is_integer() == True else 0
 
print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

OK = 0
for j in range(N-1):
  print(j)
  num = 0
  for k in range(D):
    num =num+ (A[j][k]-A[j+1][k])**2
    print(num)
  print(num**(1/2).is_integer())
  if num**(1/2).is_integer() == True:
    OK += 1
    print(type(num**(1/2)))
  else:
    None
print(OK)

Submission status: Wrong Answer

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

print(b)

Submission status: Wrong Answer

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

print(b)

Submission status: Wrong Answer

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

print(b)

Submission status: Wrong Answer

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

print(b)

Submission status: Wrong Answer

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

print(b)

Submission status: Wrong Answer

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

X_matrix=[]
for i in range(N):
  X = list(map(int, input().split()))
  X_matrix.append(X)
count=0  
print(X_matrix)
for i in range(N-1):
  for j in range(i+1, N):
    dd=0
    for k in range(D):
      dd+=(X_matrix[i][k] - X_matrix[j][k])**2
    d=np.sqrt(dd)
    if d.is_integer():
      count+=1
print(count)

Submission status: Wrong Answer

Solution code:
#create environment
import math
x = []
ans = 0
#input1 N, D (numeric)
N, D = map(int, input().split())
#input2
for i in range(N):
  a = list(map(int, input().split()))
  x += [a]
#make combination
for i in range(N):
  for j in range(i+1, N):
    for k in range(D):
      square = 0
      obj_num = 0
      square += (x[i][k] - x[j][k])**2
    obj_num = math.sqrt(square)
    if obj_num == round(obj_num):
      ans += 1    
#print
print(ans)

Submission status: Wrong Answer

Solution code:
#create environment
import math
x = []
ans = 0
square = 0
obj_num = 0
#input1 N, D (numeric)
N, D = map(int, input().split())
#input2
for l in range(N):
  a = list(map(int, input().split()))
  x += [a]
#make combination
for i in range(N):
  for j in range(i+1, N):
    for k in range(D):
      square += (x[i][k] - x[j][k])**2
    obj_num = math.sqrt(square)
    #if obj_num == round(obj_num):
    if obj_num % 1 == 0 and obj_num>=1:
      ans += 1    
#print
print(ans)

Submission status: Wrong Answer

Solution code:
#create environment
import math
x = []
ans = 0
square = 0
#input1 N, D (numeric)
N, D = map(int, input().split())
#input2
for l in range(N):
  a = list(map(int, input().split()))
  x += [a]
#make combination
for i in range(N):
  for j in range(i+1, N):
    for k in range(D):
      square = square + (x[i][k] - x[j][k])**2
    obj_num = math.sqrt(square)
    if obj_num == round(obj_num):
      ans = ans + 1    
#print
print(ans)

Submission status: Wrong Answer

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

for i in range(n):
    c = 0
    for j in range(d):
        if i == n-1:
            c += (int(x[i][j])-int(x[0][j]))**2
        else:
            c += (int(x[i][j])-int(x[i+1][j]))**2
    
    #if (c**0.5).is_integer() == True:
    if c**0.5%1==0:
        An += 1
 
print(An)

Submission status: Wrong Answer

Solution code:
from math import sqrt


def diff_square(x1, x2):
    return (x1 - x2) ** 2


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

count = 0
for i in range(N):
    for j in range(i, N):
        if i != j:
            distance = sqrt(sum(map(diff_square, X[i], X[j])))
            if distance.is_integer():
                print(i, j)
                count += 1

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())
c = [list(map(int,input().split())) for j in range(a)]
ans = 0
for l in range(a-1):
    for k in range(l+1,a):
        d = [(x-y)**2 for (x, y) in zip(c[l], c[k])]
        g = sum(d)
        if (g**0.5).is_integer:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())
c = [list(map(int,input().split())) for j in range(a)]
ans = 0
for l in range(a-1):
    for k in range(l+1,a):
        d = [(x-y)**2 for (x, y) in zip(c[l], c[k])]
    g = sum(d)
    if (g**0.5).is_integer:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n,d = map(int,input().split())
a = []
b = 0
c = 0

for i in range(n):
    x = list(map(int,input().split()))
    a.append(x)
    
for i in range(n):
    for j in range(i+1,n):
        for k in range(d):
            c += (a[i][k]-a[j][k])**2

        if int(math.sqrt(c))**2 == c:
            b += 1
print(b)

Submission status: Wrong Answer

Solution code:
import numpy as np

def distance(p1, p2):
    sum = 0
    for y, z in zip(p1, p2):
        sum += (z - y) ** 2
    return np.sqrt(sum)

N, D = [int(x) for x in input().split(" ")]
X = []
for i in range(N):
    X.append([int(x) for x in input().split(" ")])
X = np.array(X)
eps = 0.0001

count = 0
for i in range(N):
    p1 = X[i, :]
    for j in range(i + 1, N):
        p2 = X[j, :]
        if (distance(p1, p2) - round(distance(p1, p2))) ** 2 < eps:
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

def distance(p1, p2):
    sum = 0
    for y, z in zip(p1, p2):
        sum += (z - y) ** 2
    return np.sqrt(sum)

N, D = [int(x) for x in input().split(" ")]
X = []
for i in range(N):
    X.append([int(x) for x in input().split(" ")])
X = np.array(X)
eps = 0.001

count = 0
for i in range(N):
    p1 = X[i, :]
    for j in range(i + 1, N):
        p2 = X[j, :]
        if (distance(p1, p2) - round(distance(p1, p2))) ** 2 < eps:
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:
def judge(x):
    for i in range(50):
        if x==i**2:
            return True
    return False

def f(x,y):
    res = 0
    for i in range(len(x)):
        res += (x[i]-y[i])**2
    return res

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

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

ans = 0
for i in range(n):
    for j in range(i+1,n):
        if judge(f(a[i],a[j])):
            ans += 1
print(ans)

Submission status: Wrong Answer

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


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

for i in range(n):
    c = 0
    for j in range(d):
        if i == n-1:
            c += (int(x[i][j])-int(x[0][j]))**2
        else:
            c += (int(x[i][j])-int(x[i+1][j]))**2
    if (c**0.5).is_integer() == True:
        An += 1

print(An)

Submission status: Wrong Answer

Solution code:
n,d = map(int, input().split())
array = [list(map(int, input().split())) for i in range(n)]
sqarray = [i**2 for i in range(70)]
count = 0

for i in range(n-1):
    for j in range(i+1, n):
        dis = sum([(array[i][k] - array[j][k])**2 for k in range(d)])
        if dis in sqarray:
            count += 1
            
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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)
else:
  #次元から取りうる距離の最大整数値を取得
  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: Wrong Answer

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)
else:
  #次元から取りうる距離の最大整数値を取得
  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: Wrong Answer

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

Submission status: Wrong Answer

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

ans=0
for i in range(n):
    for k in range(i+1,n):
        t=0
        for j in range(d):
            t=t+(l[i][j]-l[k][j])**(2)
        t=t**(1/2)
        if t==int(t):
            ans=ans+1          
print(ans)

Submission status: Wrong Answer

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


def nijou(a,n):
    korelist = 0
    for i in range(0, n-1):
        for j in range(i+1, n ):
            c = [x - y for (x, y) in zip(a[i], a[j])]
            kore = 0
            for u in c:
                kore += u**2
            kore1 = kore ** (1/2)
            
            if kore1 - int(kore1) == 0:
                korelist += 1
    return korelist

nijou(a,n)

Submission status: Wrong Answer

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

print(a)
def nijou(a,n):
    korelist = 0
    for i in range(0, n-1):
        for j in range(i+1, n ):
            c = [x - y for (x, y) in zip(a[i], a[j])]
            kore = 0
            for u in c:
                kore += u**2
            kore1 = kore ** (1/2)
            print(kore1)
            if kore1 - int(kore1) == 0:
                korelist += 1
    return korelist

nijou(a,n)

Submission status: Wrong Answer

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

dis=[]
for a in p:
    for b in p:
        n = 0
        for i in range(D):
            n = n + (a[i]-b[i])**2
        if not n==0:
            dis.append(n)
print(len([d for d in dis if int(math.sqrt(d))**2==d])/2)

Submission status: Wrong Answer

Solution code:
import math

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

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

Submission status: Wrong Answer

Solution code:
import math

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

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

Submission status: Wrong Answer

Solution code:
import math as m
n, d=map(int, input().split())
a=[]
p=[]
q=[]
for _ in range(n):
	a.append(list(map(int, input().split())))
for i in range(n):
	x, k=0, i+1
	while k<n:
		for j in range(d):
			x+=(a[i][j]-a[k][j])**2
		x=m.sqrt(x)
		p.append(x)
		q.append(int(x))
		k+=1
x=0
for i in range(len(p)):
	if p[i]==q[i]:
		x+=1
print(x)