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 numpy as np
n, d  = map(int, input().split())

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

def length_square(a, b):
  y = 0
  for i in range(n):
    y += (int(a[i]) - int(b[i])) ** 2
    return y

for i in range(n):
  for j in range(i + 1, n):
    #calculate distance between x[i] and x[j] (i < j)
    l_square = length_square(x[i], x[j])
    l = np.sqrt(l_square)
    #print(l)
    #decide whether l is int() or not
    if int(l) == l:
      ans += 1
    else:
      pass

print(ans)

Submission status: Wrong Answer

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

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

for i in range(n):
  for j in range(i + 1, n):
    #calculate distance between x[i] and x[j] (i < j)
    l_square = np.linalg.norm(np.array(x[i]) - np.array(x[j]))
    l = np.sqrt(l_square)
    #decide whether l is int() or not
    if int(l) == l:
      ans += 1
    else:
      pass

print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
sq = [i**2 for i in range(500)]
ans = 0
n,d = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
for (i,j) in combinations(a,2):
  dist2 = 0
  for x in range(d):
    dist2 += i[x]**2 + j[x]**2
  if dist2 in sq:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import math

N, D = map(int, input().strip().split())
X = [[int(n) for n in input().strip().split()] for _ in range(N)]
c = 0
for i in range(-1, N-1):
    s = 0
    for j in range(D):
        s += (X[i][j] - X[i+1][j])**2
    
    if len(str(math.sqrt(s))) < 10:
        c += 1

print(c if D > 1 else N * 2)

Submission status: Wrong Answer

Solution code:
from math import sqrt
n,d=map(int,input().split())
l=[list(map(float,input().split())) for i in range(n)]
nums=[i for i in range(n-1)]
fa=[i for i in range(d)]
cnt=0
ans=0
t=[]
for i in nums:
  for j in l[i+1:]:
    cnt=0
    for k in fa:
      cnt+=(l[i][k]-j[k])**2
    cnt=sqrt(cnt)
    print(cnt)
    t.append(cnt)
for v in t:
  if(v.is_integer()):
    ans+=1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

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

count = 0

for i in range(N):
    s = 0

    for j in range(i+1,N):
        for k in range(D):
            s += (list_ND[i][k] - list_ND[j][k])**2
    
    s = math.sqrt(s)

    if s.is_integer():
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import math
a,b=map(int,input().split())
c=[[int(i) for i in input().split()] for i in range(a)]


count=0
sum1=0
for i in range(b):
    sum1+=(c[0][i]-c[len(c)-1][i])**2
if math.sqrt(sum1)%1==0:
    count+=1
sum1=0
for i in range(a-1):
    for j in range(b):
        sum1+=(c[i][j]-c[i+1][j])**2
    
    if math.sqrt(sum1)%1.0==0:
        count+=1
    sum1=0
print (count)

Submission status: Wrong Answer

Solution code:
import math

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

b = 0
ans = 0
for i in range(n):
  for j in range(i+1,n):
    for k in range(d):
      b+= (abs(a[i][k] + a[j][k]))
      
    b= math.sqrt(b)
    
    if b%1==0:
      ans += 1
    b = 0
print(ans)

Submission status: Wrong Answer

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):
    for k in range(d):
      diff = sum([(s-t)**2 for s, t in zip(X[i], X[j])])
    if (diff**1/2).is_integer():c += 1
      
print(c)

Submission status: Wrong Answer

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):
    for k in range(d):
      diff = sum([(s-t)**2 for s, t in zip(X[i], X[j])])
    if (diff**1/2).is_integer():
      c += 1
      
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
print(5.0 == 5)

Submission status: Wrong Answer

Solution code:
import math
N,D=map(int,input().split()) #Nはポイントの数　Dは次元数（点を示す変数の数）
P=0
Q=0
X= [list(map(int, input().split())) for t in range(N)]
for i in range(0,N-1):
  for j in range(i+1,N):
    for k in range(0,D):
      P=P+(X[i][k]-X[j][k])**2
    if int(math.sqrt(P))==math.sqrt(P):
      Q=Q+1
      P=0
print(Q)

Submission status: Wrong Answer

Solution code:
import math
N,D=map(int,input().split()) #Nはポイントの数　Dは次元数（点を示す変数の数）
P=0
Q=0
X= [list(map(int, input().split())) for t in range(N)]
for i in range(N-1):
  for j in range(i+1,N):
    for k in range(D):
      P=P+(X[i][k]-X[j][k])**2
    if int(math.sqrt(P))==math.sqrt(P):
      Q=Q+1
      P=0
print(Q)

Submission status: Wrong Answer

Solution code:
import math 
N,D = map(int,input().split())
X=[]
count=0
for i in range(N):
    x = list(map(int,input().split()))
    X.append(x)
for i in range(N-1):
    for j in range(i+1,N):
        s = 0
        for k in range(D):
            s += (X[i][k]-X[j][k])**2
            if math.sqrt(s).is_integer():
                count += 1
print(count)

Submission status: Wrong Answer

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

square_set = {i ** 2 for i in range(1, 60)}
ans = 0

for i in range(N):
    for j in range(i + 1, N):
        dist = 0
        for k in range(D):
            dist += (X[i][k] - X[j][k]) ** 2
        if dist in square_set:
            ans += 1
print(ans)

Submission status: Wrong Answer

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

square_set = {i ** 2 for i in range(1, 30)}
ans = 0

for i in range(N):
    for j in range(i + 1, N):
        dist = 0
        for k in range(D):
            dist += (X[i][k] - X[j][k]) ** 2
        if dist in square_set:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
nd = list(map(int, input().split()))
xnd = []
for _ in range(nd[0]):
    xnd.append(list(map(int, input().split())))
    
    
import math
count = 0
for i in range(nd[0] - 1):
    xSum = 0
    for i_2 in range(i+1, nd[0], 1):
        for j in range(nd[1]):
            xSum += (xnd[i][j] - xnd[i_2][j]) ** 2
        ans = math.sqrt(xSum)
        if ans == int(ans):
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
nd = list(map(int, input().split()))
xnd = []
for _ in range(nd[0]):
    xnd.append(list(map(int, input().split())))
    
    
import math
count = 0
for i in range(nd[0] - 1):
    xSum = 0
    for j in range(nd[1]):
        xSum += (xnd[i][j] - xnd[i+1][j]) ** 2
    ans = math.sqrt(xSum)
    if ans == int(ans):
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import math
N, D = map(int, input().split())
t = []
for i in range(N):
    t.append(list(map(int, input().split())))
count = 0
sum = 0
for i in range(0, N-1):
    for j in range(i + 1, N):
      for d in range(D):
        sum += pow(t[i][d] - t[j][d], 2)
        sqrt = math.sqrt(sum)
      print(sum)
      print(sqrt)
      if sqrt == int(sqrt):
        count += 1
      sum = 0
      sqrt = 0
print(count)

Submission status: Wrong Answer

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

ans=0
tmp=0

for i in range(n):
  for j in range(i+1, n):
    xi,xj = x[i],x[j]
    for k in range(d):
      tmp += (xi[k]-xj[k]) ** 2  
    if sqrt(tmp)%1==0:
      ans += 1

print(ans)

Submission status: Wrong Answer

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

ans=0
tmp = 0

for i in range(n):
  for j in range(i+1, n):
    xi,xj = x[i],x[j]
    for k in range(d):
      tmp += (xi[k]-xj[k]) ** 2
      if sqrt(tmp)%1==0:
        ans += 1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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)]
count = 0
dist=[0]*N
# print(X[2][1])
for i in range(N):
    for j in range(D):
        if i+1==N:
            dist[i] += (X[i][j] - X[0][j])** 2
        else:
            dist[i] += (X[i][j] - X[i + 1][j])** 2
    dist[i]=math.sqrt(dist[i])
for i in range(N):
    if dist[i].is_integer():
        count+=1
print(count)

Submission status: Wrong Answer

Solution code:
import math

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

def dist(R,L):
    P=0
    for z in range(D):
        P+=(R[z]-L[z])**2
    return math.sqrt(P)

count=0
for j in range(N-1):
    for k in range(j+1,N):
        print(dist(X[j],X[k]))
        print(math.floor(dist(X[j],X[k])))
        if dist(X[j],X[k])==math.floor(dist(X[j],X[k])):
            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)]
ans = 0
LL = 0
for i in range(N):
  for j in range(i+1,N):
    for k in range(D):
      LL += (X[i][k]-X[j][k])**2
    L = math.sqrt(LL)
    if LL == int(L)**2:
      ans += 1
      L = 0
      LL = 0
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#import pprint
n, d = map(int, input().split())
#x = list[int(input().split()) for i range(1, n+1)]
x = [list(map(int, input().split())) for _ in range(n)]
#pprint.pprint(x)

cnt = 0
a = 0
for i in range(n-1):
    for j in range(i+1, n):
        for k in range(d):
            a += (x[i][k]-x[j][k])**2
        if (a**0.5)%1 == 0:
            cnt += 1
            a = 0
        else:
            break
print(cnt)

Submission status: Wrong Answer

Solution code:
#import pprint
n, d = map(int, input().split())
#x = list[int(input().split()) for i range(1, n+1)]
x = [list(map(int, input().split())) for _ in range(n)]
#pprint.pprint(x)

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

Submission status: Wrong Answer

Solution code:
n,d=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]
count=0
su=0
for l in range(n-1):
    for i in range(l+1,n):
        for s in range(d):
            su+=(x[l][s]-x[i][s])**2
            
        if (su**0.5)%1==0:
            count+=1
            su=0
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)]
count=0
su=0
for l in range(n):
    for i in range(l+1,n):
        for s in range(d):
            su+=(x[l][s]-x[i][s])**2
            
        if (su**0.5)%1==0:
            count+=1
            su=0
print(count)

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)]
norm = 0
ans = 0
for i in range(n - 1):
  for j in range(1,n):
    if i >= j:
      continue
    #print(x[i][j])
    for k in range(d):
      #print(abs(x[i][k]-x[j][k])**2)
      norm += abs(x[i][k]-x[j][k])**2
      if k == (d - 1):
        p = math.sqrt(norm)
        #print(str(x[i][k])+"と"+str(x[j][k]))
        #print(p)
        if p.is_integer():
          ans += 1
          norm = 0
print(ans)

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)]
norm = 0
ans = 0
for i in range(n):
  for j in range(1,n):
    if i >= j:
      continue
    #print(x[i][j])
    for k in range(d):
      #print(abs(x[i][k]-x[j][k])**2)
      norm += abs(x[i][k]-x[j][k])**2
      if k == (d - 1):
        p = math.sqrt(norm)
        #print(str(x[i][k])+"と"+str(x[j][k]))
        #print(p)
        if p.is_integer():
          ans += 1
          norm = 0
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)]
n=0
for i in range(N):
  for j in range(i):
    DD=0
    for k in range(D):
      DD+=(L[i][k]-L[j][k])**2
    if any(n**2==DD for n in range(1,80)):
      n+=1
print(n)

Submission status: Wrong Answer

Solution code:
N,D=map(int,input().split())
L=[list(map(int,input().split())) for i in range(N)]
n=0
for i in range(N):
  for j in range(i):
    for k in range(D):
      DD=0
      DD+=(L[i][k]-L[j][k])**2
    if any(n**2==DD for n in range(1,80)):
      n+=1
print(n)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def solve():
    n,d = map(int, input().split())
    if d == 1:
        return sum(range(n))
    L = [[int(x) for x in input().split()] for _ in range(n)]
    for i in range(n):
        y = L[i]
        count = 0
        for z in L[i+1:]:
            total = 0
            for a,b in zip(y,z):
                total += (a-b)**2
            if total**0.5 == int(total**0.5):
                count += 1
        return count
    
if __name__ == '__main__':
    print(solve())

Submission status: Wrong Answer

Solution code:
def solve():
    n,d = map(int, input().split())
    L = [[int(x) for x in input().split()] for _ in range(n)]
    if d==1:
        return sum(range(n))
    for i in range(n):
        y = L[i]
        count = 0
        for z in L[:i]+L[i+1:]:
            total = 0
            for a,b in zip(y,z):
                total += (a-b)**2
            if total**0.5 == int(total**0.5):
                count += 1
        return count
    
if __name__ == '__main__':
    print(solve())

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N,D = map(int,readline().split())
X = np.array(read().split(),np.int64).reshape(-1,D)

dist_mat = ((X[:,None,:] - X[None,:,:])**2).sum(axis=2)

square = np.arange(1,100)**2

answer = np.in1d(dist_mat,square).sum()//2
print(answer)

Submission status: Wrong Answer

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

count=1
for i in range(n):
  for j in range(i+1,n):
    t=0
    for k in range(b):
      t += (x[i][k]-x[j][k])**2
    t = t**(1/2)
    if t.is_integer():
      count += 1
print(count)

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


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

                break

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
print("zzzzzzzzzzzzzzzzzzzzzzzz")
#xij=x[i-1][j-1]
for i in range(n-1):
    for j in range(i+1,n):
        d2=0
        for l in range(d):
            d2+=(x[i][l]-x[j][l])**2
        d2=int(d2)
        print(d2)
        for k in range(1,d2//2+2):
            if d2==k**2:
                ans+=1
                #print("{} {} {}".format("ok",d2,k**2))
                break
            else:
                #print("{} {} {}".format("not ok",d2,k**2))
                pass
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,d = map(int,input().split())
s = [input().split() for m in range(n)]
print(s)
b = 0
for m in range(n):
    for l in range(m+1,n):
        ans = 0
        for j in range(d):
            ans += (int(s[m][j])-int(s[l][j]))**2
            if ans**0.5 == int(ans**0.5):
                b += 1
print(b)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N ,D = map(int, input().split())
X = []
tmp = []
ans = []
fans = 0
for _ in range(N):
    X.append(list(map(int, input().split())))
for i in range(N):
    if D == 1:
        tmp.append((X[i-1][0])**2**0.5)
    else:
        for j in range(D):
            tmp.append((X[i-1][j]-X[i][j])**2)
    if D != 1:
        ans.append(sum(tmp)**0.5)
        tmp = []
for A in ans:
    if A.is_integer():
        fans += 1
print(fans)

Submission status: Wrong Answer

Solution code:
n,d=map(int,input().split())
x=[[int(a) for a in input().split(" ")] for _ in range(n)]
cnt=0
dis=0
for i in range(n-1):
  for j in range(i+1,n):
    for k in range(d):
      dis+=(x[i][k]-x[j][k])**2
    if (dis**0.5).is_integer():
        cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
n,d=map(int,input().split())
x=[[int(a) for a in input().split(" ")] for _ in range(n)]
cnt=0
dis=0
for i in range(n-1):
  for j in range(i+1,n):
    for k in range(d):
      dis+=(x[i][k]-x[j][k])**2
      if (dis**0.5).is_integer:
        cnt+=1
print(cnt)

Submission status: Wrong Answer

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

ans = 0
for i in range(N):
    for j in range(i+1, N):
        dist = 0
        for d in range(D):
            dist += (X[i][d]-X[j][d])*(X[i][d]-X[j][d])
        for r in range(2, 200):
            if dist == r*r:
                ans += 1
                break

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,D=map(int,input().split())
c=0
X=[[0]*D]*N
for l in range(N):
    X[l]=list(map(int,input().split()))
for i in range(N-1):
    l=0
    for j in range(i+1,N):
        for k in range(D):
            l+=(X[i][k]-X[j][k])**2
        if pow(l,0.5).is_integer() == True:
            c+=1
print(c)

Submission status: Wrong Answer

Solution code:
N,D=map(int,input().split())
c=0
X=[[0]*D]*N
for l in range(N):
    X[l]=list(map(int,input().split()))
for i in range(N):
    l=0
    for j in range(i+1,N):
        for k in range(D):
            l+=(X[i][k]-X[j][k])**2
        if pow(l,0.5).is_integer() == True:
            c+=1
print(c)

Submission status: Wrong Answer

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

s = 0
c = 0
for n in range(-1,N-1):
    for d in range(D):
        s = s + abs(li[n][d] - li[n+1][d]) ** 2
    s_float = float(s**(1/2))
    if s_float.is_integer():
        c += 1
    s = 0
print(c)

Submission status: Wrong Answer

Solution code:
def dis(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 = [[int(x) for x in input().split()] for i in range(n)]
ans =0
for  i in range(n-1):
    for j in range(i +1, n):
        if dis(X[i], X[j]).is_integer:
            ans +=1
            
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        dist = sum(map(lambda v1, v2: (v1 - v2) ** 2, x[i], x[j]))
        print(dist)
        if math.sqrt(dist) == int(math.sqrt(dist)):
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from math import sqrt

N,D = [int(i) for i in input().split()]
XY_l = [[int(i) for i  in input().split()] for _ in range(N)]
ans = 0

for i in range(N):
  for j in range(N):
    if i <= j :
      continue
    S = 0
    for d in range(D):
      S = ((XY_l[i][d]) - (XY_l[j][d]))**2
    if sqrt(S).is_integer():
      ans+=1

print(ans)

Submission status: Wrong Answer

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

for i in range(n-1):
    dist = 0
    for j in range(d):
        dist += (x[i][j]-x[i+1][j])**2
    dist = mt.sqrt(dist)
    if dist.is_integer()==True:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')


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

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

Submission status: Wrong Answer

Solution code:
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')


N,D=map(int,input().split())
X=[list(map(int,input().split())) for _ in range(N)]
a=0
cnt=0
print(X)

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n, d = map(int, input().split())
x = np.array([[int(i) for i in input().split(" ")] for j in range(n)])
t = x[:-1,:]-x[1:,:]
t = np.sqrt(np.sum(t*t, axis=1))
print(np.sum(t%1==0))

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)] 
dist2 = 0
count = 0
for i in range(n-1):
    for j in range(i+1,n):
        for k in range(d):
            dist2 += (x[i][k]-x[j][k])**2
        dist = dist2**0.5 
        if dist.is_integer():
            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)] 
dist2 = 0
count = 0
for i in range(n): 
    for j in range(i+1,n):
        for k in range(d):
            dist2 += (x[i][k]-x[j][k])**2
        dist = dist2**0.5 
        if dist.is_integer():
            count += 1 
print(count)

Submission status: Wrong Answer

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

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

#二重ループで各点の距離を計算
print(list_N)
score = 0
for i in range(len(list_N)):
    for j in range(i+1, len(list_N)):
        val = 0

        for a, b in zip(list_N[i], list_N[j]):
            val += (a-b)**2

        val = val**0.5
        
        if val.is_integer():
            score += 1

print(score)

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)]
distanceA = 0
count = 0
for i in range(N):
    for j in range(N):
        if i < j:
            for d in range(D):
                    distanceA += ((x[i][d])-(x[j][d]))**2
            distanceB = math.sqrt(distanceA)
            if distanceB.is_integer():
                count += 1
        else:
            continue
print(count)

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)]
distanceA = 0
count = 0
print(x)
for i in range(N):
    for j in range(N):
        if i < j:
            for d in range(D):
                    distanceA += ((x[i][d])-(x[j][d]))**2
            distanceB = math.sqrt(distanceA)
            print(distanceA)
            if distanceB.is_integer():
                count += 1
        else:
            continue
print(count)

Submission status: Wrong Answer

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

cnt = 0

def distance(x, y):
  ans = 0
  for dd in range(d):
    ans += abs(x[dd] - y[dd]) ** 2
  return math.sqrt(ans)


for i in range(n):
  for j in range(i+1, n):
    if distance(points[i], points[j]):
      cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
import copy
import math

n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
y = copy.deepcopy(x)
cnt = 0
inside = 0
for nx, i in enumerate(x[:]):
  # print(i)
  for ny, j in enumerate(y[:]):
    # print(j)
    inside = 0
    if nx != ny:
      for item in range(d):
        inside += (i[item] - j[item]) ** 2
        # print('inside = %d' % inside)
      root = math.sqrt(inside)
      if root.is_integer():
        cnt += 1
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,D = map(int, input().split())
X  = []
for n in range(N):
    x = list(map(int, input().split()))
    X.append(x)
    
import numpy as np
def distance(a,b):
    dis = 0
    for i in range(D):
        dis += (a[i]-b[i])**2
    return np.sqrt(dis)

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

Submission status: Wrong Answer

Solution code:
import math

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

ans=0

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

print(ans)

Submission status: Wrong Answer

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

cnt = 0
distance = 0

for i in range(N):
    for j in range(i+1, N):
        distance = 0
        for k in range(D):
            distance += (X[i][k] - X[j][k]) ** 2
        for m in range(distance):
            if m ** 2 == distance:
                cnt += 1
                break
                
print(cnt)