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())
point=[]
for _ in range(n):
    point.append(list(map(int,input().split())))
ans=0
for i in range(n-1):
    for l in range(1,n):
        if i==l:
            continue
        dis=0
        for f in range(d):
            dis+=(point[i][f]-point[l][f])**2
        dis=dis**0.5
        #print(dis)
        if dis.is_integer():
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
#ABC133 B

import math
N,D = map(int,input().split())
point = []
count = 0
for i in range(N):
    X = list(map(int,input().split()))
    point.append(X)
for i in range(1,N):
    for j in range(i+1,N+1):
        for k in range(D):
            S = 0
            square = []
            square.append(((point[i-1][k])-(point[j-1][k]))**2)
            S += math.sqrt(sum(square))
            if S % 1 ==0:
                count += 1
        

print(count)

Submission status: Wrong Answer

Solution code:
#ABC133 B

import math
N,D = map(int,input().split())
point = []
count = 0
for i in range(N):
    X = list(map(int,input().split()))
    point.append(X)
for i in range(1,N):
    for j in range(i+1,N+1):
        S = 0
        for k in range(D):
            square = []
            square.append(((point[i-1][k])-(point[j-1][k]))**2)
            S += math.sqrt(sum(square))
            if S % 1 ==0:
                count += 1
        

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,d = map(int,input().split())
import numpy as np
xlist = [list(map(int,input().split())) for i in range(n)]
xarray = np.array(xlist)
ans = 0
for i in range(n):
  for j in range(i+1,n):
    if np.linalg.norm(xarray[i]-xarray[j])%1!=0:
      ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import math

def colcu (bli,ali,D):
    num = 0
    for i in range(D):
        num += (bli[i] - ali[i]) ** 2
    return math.sqrt(num)

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

an = 0
for i in range(N-1):
 for t in range(i+1,N):
     if colcu(pli[i],pli[t],D).is_integer():
         an += 1
     print(colcu(pli[i],pli[t],D))
print(an)

Submission status: Wrong Answer

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

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

count = 0
d_2 = 0
d = 0

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

print("{}".format(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)]
print(x)
cnt = 0
sum_tmp = 0

for i in range(n):
    for j in range(i+1, n):
        for h in range(d):
            sum_tmp += (x[i][h] - x[j][h]) ** 2
            print("test i:",i , "h:", h ,x[i][h])
            print("test j:",j , "h:", h ,x[j][h])
        print(i,math.sqrt(sum_tmp))
        if math.sqrt(sum_tmp).is_integer():
            cnt += 1
        sum_tmp = 0

print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
from scipy.special import comb
n,d=map(int,input().split())
x=[]
total=0
for i in range(n):
    x.append(list(map(int,input().split())))
for i in range(n):
    for j in range(n):
        if i!=j:
            a=np.array(x[i])
            b=np.array(x[j])
            u=b-a
            print(np.linalg.norm(u))
            if np.linalg.norm(u)==int(np.linalg.norm(u)):
                total+=1
print(total/2)

Submission status: Wrong Answer

Solution code:
def main():
    n, d = map(int, input().split())
    ps = [[*map(int, input().split())] for _ in range(n)]
    square = [i**2 for i in range(1, 20)]
    cnt = 0
    for i in range(n-1):
        for j in range(i+1, n):
            if sum([(ps[i][k] - ps[j][k]) ** 2 for k in range(d)]) in square:
                cnt += 1
    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

cnt=0

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

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)]
cnt = 0
for i in range(n):
    for j in range(i+1, n):
        dis = 0
        for k in range(d):
            dis += (x[i][k]-x[j][k])**2
            if math.sqrt(dis) % 1 == 0:
                cnt += 1
print(cnt)

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)]
cnt = 0
for i in range(n):
    for j in range(i+1, n):
        for k in range(d):
            dis = 0
            dis += (x[i][k]-x[j][k])**2
            if math.sqrt(dis) % 1 == 0:
                cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
r=input().split()
N=int(r[0])
D=int(r[1])
d=[[int(s) for s in input().split()] for i in range(N)]
ans=0
for i in range(N-1):
    for j in range(i+1,N):
        dis=0
        for k in range(D):
            dis+=(d[i][k]-d[j][k])**2
        ans_pre=dis**(int(1/2))
        if type(ans_pre)==int or ans_pre.is_integer()==True:
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    def calc(p, q):
        res = 0
        for i in range(D):
            res += (X[p][i] - X[q][i]) ** 2
        return res

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

    sq = [x ** 2 for x in range(100)]

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readlines
from math import sqrt

def isSquare(n):
    m = int(sqrt(n))
    for x in range(m-2, m+2):
        if x**2 == n:
            return True

def getDistance(xi, xj, dimention):
    d = 0
    for i in range(dimention):
        d += (xi[i] - xj[i])**2
    return d

def main():
    lines = input()

    n, d = list(map(int, lines[0].split()))
    x = []
    for i, xi in enumerate(lines[1:]):
        x.append(list(map(int, xi.split())))

    cnt = 0

    for i, xi in enumerate(x):
        for j, xj in enumerate(x[i+1:]):
            dist = getDistance(xi, xj, d)
            if isSquare(dist):
                print(dist)
                cnt += 1
    print(cnt)

main()

Submission status: Wrong Answer

Solution code:
n,d=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]
        
l=[]
m=[]
for i in range(n-1):
    m.clear()
    for j in range(d):
        a=(x[i][j]-x[i+1][j])**2
        m.append(a)
    l.append(sum(m))

m.clear()
for k in range(d):
    b=(x[-1][k]-x[0][k])**2
    m.append(b)
l.append(sum(m))

c=0

for i in l:
    g=i**(0.5)
    if g.is_integer()==True:
        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)]

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        norm = 0
        for k in range(d):
            diff = abs(x[i][k] - x[j][k])
            norm += diff ** 2

        flag = False
        for k in range(norm):
            if k ** 2 == norm:
                flag = True
        if flag:
            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)]
lis=list(i**2 for i in range(0,22))
ans=0
for i in range(n):
    for k in range(i+1,n):
        check=0
        for j in range(d):
            check+=(x[i][j]-x[k][j])**2
        if check in lis:
            ans+=1
print(ans)

Submission status: Wrong Answer

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

def distance(x,y):
  num=0
  for i in range(d):
    num=num+(x[i]-y[i])*(x[i]-y[i])
  return num

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

ans=0
for i in range(n-1):
  for j in range(i+1,n):
    k=distance(diff[i],diff[j])
    if k in check:
      ans+=1
  
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N, D = map(int, input().split(' '))
X_ls = []
cnt = 0
 
for i in range(N):
    X_ls.append(list(map(int, input().split(' '))))
 
for i in range(N - 1):
    for j in range(i+1, N):
        dist_squared, dist = 0, 0
        print(i,j)
        for y, z in zip(X_ls[i], X_ls[j]):
            dist_squared += (y - z) ** 2
        dist = math.sqrt(dist_squared)
        if dist - math.floor(dist) == 0:
            cnt += 1
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)]
l = []
s = []
for i in range(n):
    for j in range(i+1,n):
        t = 0
        for k in range(d):
            t += abs(x[i][k] - x[j][k]) ** 2
        l.append(t)
m = max(l)
i = 1
while i ** 2 <= l[-1]:
    s.append(i ** 2)
    i += 1
ans = 0
for i in range(len(s)):
    ans += l.count(s[i])
print(ans)

Submission status: Wrong Answer

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

for _ in range(n):
  x = list(map(int, input().split()))
  l.append(x)
    
for i in range(n-1):
  for j in range(1,n):
    k = 0
    for a,b in zip(l[i], l[j]):
      k += (a-b)**2
    if (k**0.5).is_integer():
      count += 1

print(count-1)

Submission status: Wrong Answer

Solution code:
def distance(a_lst, b_lst):
    n = len(a_lst)
    tmp_distance = 0

    for i in range(n):
        a = a_lst[i]
        b = b_lst[i]

        tmp_distance += (a - b) ** 2

    distance = (tmp_distance) ** (1/2)
    return distance


def main():
    n, d = map(int, input().split())
    x_lst = [0] * n
    count = 0

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

    for i in range(n-1):
        a_lst = x_lst[i]

        for j in range(i+1, n):
            b_lst = x_lst[j]

            if distance(a_lst, b_lst) == int(distance(a_lst, b_lst)):
                count += 1

    print(count)

Submission status: Wrong Answer

Solution code:
MM = input().split()
N = int(MM[0])
D = int(MM[1])
list1 =[]
count = 0
for i in range(N):
  aa = input().split()
  list1.append(aa)
for i in range(N):
  for j in range(i+1,N):
    total = 0
    for k,l in zip(list1[i],list1[j]):
      total += (int(k) -int(l))**2
    for m in range(41):
      if total == m**2 and total !=0:
        count +=1
print(count)

Submission status: Wrong Answer

Solution code:
MM = input().split()
N = int(MM[0])
D = int(MM[1])
list1 =[]
count = 0
for i in range(N):
  aa = input().split()
  list1.append(aa)
for i in range(N):
  for j in range(i+1,N):
    total = 0
    for k,l in zip(list1[i],list1[j]):
      total += (int(k) -int(l))**2
    for m in range(40):
      if total == m**2 and total !=0:
        count +=1
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)]
ret = 0
for i in range(n-1):
    for j in range(i, n):
        meu = 0
        for y, z in zip(x[i], x[j]):
            meu += (y-z)**2
        if meu**0.5 == int(meu**0.5):
            ret += 1
print(ret)

Submission status: Wrong Answer

Solution code:
import math
n,m = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(n)]
cnt,tmp = 0,0
for i in range(n-1):
	for j in range(i+1,n):
		tmp = 0
		for M in range(m):
			tmp += (x[i][M] - x[j][M])**2
			#print(tmp)
			if math.sqrt(tmp).is_integer():
				cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
import itertools

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

xn = []
for i in range(n):
  x = [int(num) for num in input().split()]
  xn.append(x)

c_list = list(itertools.combinations([int(num) for num in range(n)], 2))  
  
answers = []
for c in c_list:
  sum = 0
  for j in range(d):
    sum += (xn[c[0]][j]-xn[c[1]][j])**2 
  
  answers.append(int(math.sqrt(sum)*10))  

count = 0
for a in answers:  
  if a%10 == 0:
    count += 1
 
print(count)

Submission status: Wrong Answer

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

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

def distance(a, b):
  dist = 0
  
  for a, b in zip(a, b):
    dist += (a - n) ** 2

  if dist == 0:
    return False
  return int(dist ** 0.5) ** 2 == dist

count = 0

for pa in points:
  for pb in points:
    if distance(pa, pb):
      count += 1

print(count // 2)

Submission status: Wrong Answer

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

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

for i in range(N):
  for j in range(i,N):
    for n in range(D):
      dist2 += (X[i][n] - X[j][n])**2
    a = dist2 **0.5
    if a == int(a) and a != 0:
      cnt += 1
      dist2 = 0
print(cnt)

Submission status: Wrong Answer

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

for i in range(n):
    for j in range(i + 1, n):
        diff_total = 0
        for k in range(d):
            diff = abs(distances[i][k] - distances[j][k])
            diff_total = diff * diff

        flag = False
        for k in range(diff_total + 1):
            if (k ** 2) == diff_total:
                flag = True
        if flag:
            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)]

sq = set()
for i in range(1, 100):
  sq.add(i**2)

def foo(x,y):
  t = 0
  for i, j in zip(X[x], X[y]):
    t += (i - j) * (i - j)
  if t in sq:
    return 1
  else:
    return 0
    
ans = 0

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

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

sq = set()
for i in range(1, 40):
  sq.add(i**2)

def foo(x,y):
  t = 0
  for i, j in zip(X[x], X[y]):
    t += (i - j) * (i - j)
  if t in sq:
    return 1
  else:
    return 0
    
ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n, _ = rm()
li = np.array([np.array(rl()) for _ in range(n)])
cnt = 0
for i in range(n):
  for j in range(i):
    a = sum((li[i] - li[j]) ** 2)
    if a - a//1 == 0:
      cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools

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

i = 1
tmp = 0
sq = []
while tmp <= 40**2*10:
    tmp += i**2
    sq.append(i**2)
    i += 1

cnt = 0
l = [int(i) for i in range(n)]
for v in itertools.combinations(l, 2):
    i, j = v[0], v[1]
    sub = x[i] - x[j]
    dist = sum(sub**2)
    if dist in sq:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n,d = i2()
x = []
for i in range(n):
	a = intl()
	x.append(a)

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

Submission status: Wrong Answer

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

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

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

S=set()
k=0
L=M*M*D
while k*k<=L:
    S.add(k*k)
    k+=1
    
K=0
for i in range(N):
    for j in range(i+1,N):
        K+=(f(X[i],X[j]) in S)
print(K)

Submission status: Wrong Answer

Solution code:
def dist(p1,p2):
  r=0
  for a,b in zip(p1,p2):
    r+=(a-b)**2
  return r

def isSqrt(n):
  i=1
  while i*i<n:
    i+=1
  return i==n
    
N,D = map(int,input().split())
P=[list(map(int,input().split())) for _ in range(N)]
ans=0
for i in range(N):
  for j in range(i):
    d = dist(P[i],P[j])
    if isSqrt(d):
      ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
def dist(p1,p2):
  r=0
  for a,b in zip(p1,p2):
    r+=(a-b)**2
  return r

def isSqrt(n):
  i=1
  while i*i<n:
    i+=1
  return i==n
    
N,D = map(int,input().split())
P=[list(map(int,input().split())) for _ in range(N)]
ans=0
for i in range(N):
  for j in range(i):
    d = dist(P[i],P[j])
    if d==int(d):
      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)]

ans = 0

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

ans = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
n,d=[int(x) for x in input().rstrip().split()]
 
l=[]
for i in range(n):
  X=[int(x) for x in input().rstrip().split()]
  l.append(X)
 
ans=0
for i in range(n):
  ni=l[i]
  for j in range(i+1,n):
    nj=l[j]
    now=0
    for s in range(d):
      now+=(ni[s]-nj[s])**2
    now=now**0.5

Submission status: Wrong Answer

Solution code:
N,D=[int(x) for x in input().rstrip().split()]
 
l=[]
for i in range(N):
  X=[int(x) for x in input().rstrip().split()]
  l.append(X)
 
ans=0
for i in range(N):
  ni=l[i]
  for j in range(i+1,N):
    nj=l[j]
    now=0
    for s in range(D):
      now+=(ni[s]-nj[s])**2
    now=now**0.5

Submission status: Wrong Answer

Solution code:

url = "https://atcoder.jp//contests/abc133/tasks/abc133_b"
import itertools
def main():
    n,d = list(map(int, input().split()))
    lis = []
    for i in range(n):
        t = list(map(int, input().split()))
        lis.append(t)
    count = 0
    for i in range(len(lis)):
        for j in range(i+1, len(lis)):
            if i == j:
                continue
            if float.is_integer(ret(lis[i], lis[i+1])):
                count += 1
    print(count)


import math
def ret(a,b):
    retval = 0
    idx = 0
    while True:
        if idx == len(a):
            break
        retval += abs(a[idx]-b[idx])**2
        idx += 1
    return math.sqrt(retval)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

url = "https://atcoder.jp//contests/abc133/tasks/abc133_b"

def main():
    n,d = list(map(int, input().split()))
    lis = []
    for i in range(n):
        t = list(map(int, input().split()))
        lis.append(t)
    count = 0
    for i in range(len(lis)-1):
        if float.is_integer(ret(lis[i], lis[i+1])):
            count += 1
    print(count)


import math
def ret(a,b):
    retval = 0
    idx = 0
    while True:
        if idx == len(a):
            break
        retval += abs(a[idx]-b[idx])**2
        idx += 1
    return math.sqrt(retval)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

N, D = map(int, input().split())
X = []
cnt = 0
for i in range(N):
    X.append(list(map(int, input().split())))
for i in range(1, N):
    for j in range(i):
        d = 0
        for k in range(D):
            d += (X[i][k] - X[j][k])**2
        for l in range(d):
            if l**2 == d:
                cnt += 1
                break
print(cnt)

Submission status: Wrong Answer

Solution code:
N, D = map(int, input().split())
X = []
count = 0
for n in range(N):
  temp = list(map(int, input().split()))
  X.append(temp)
for i in range(N):
  for j in range(i + 1, N):
    sums = 0
    for d in range(D):
      sums += (X[i][d] - X[j][d]) ** 2
    for n in range(sums):
      if n * n == sums or sums == 1:
        count += 1
    print("{} {}".format(sums, count))
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)]
ans=0
dist=0.0
for i in range(N):
    for j in range(i+1,N):
        dist=0.0
        for k in range(D):
            dist+=(X[i][k]-X[j][k])**2
        print(dist.is_integer())
        if dist.is_integer() is True:
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
    import math
    N, D = map(int, input().split())
    A = []
    count = 0
    ans = []
    for i in range(N):
        a = list(map(int, input().split()))
        A.append(a)
    for j in range(N):
        for g in range(N):
            if j != g:
                for k in range(D):
                    ans.append(((A[j])[k]-(A[g])[k])**2)
                if math.sqrt(sum(ans))%1 == 0:
                    count += 1
    print(count//2)
resolve()

Submission status: Wrong Answer

Solution code:
n,d = map(int,input().split())
x = [[] for _ in range(n)]
for i in range(n):
	x[i] = list(map(int,input().split()))
#8000
ansk = 0
l = set([i**2 for i in range(100)])
for i in range(n):
	for j in range(i+1, n):
		ans = 0
		for k in range(d):
			ans += (x[i][k]-x[j][k])**2
		if ans in l:
			ansk += 1
print(ansk)

Submission status: Wrong Answer

Solution code:
sq_nums = {i * i for i in range(1, 101)}
N, D = map(int, input().split())
coords = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N):
    for j in range(i, N):
        if sum((y - z) ** 2 for y, z in zip(coords[i], coords[j])) in sq_nums:
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import combinations


sq_nums = {i * i for i in range(101)}

N, D = map(int, input().split())
coords = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for Y, Z in combinations(coords, 2):
    if sum((y - z) ** 2 for y, z in zip(Y, Z)) in sq_nums:
        ans += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
n,d = map(int,input().split())
try:
  a = [list(map(int,input().split())) for j in range(0,n)]
except EOFError:
  pass
c = 0
r = 0
for i in range(0,n):
  for j in range(i+1,n):
    for k in range(0,d):
      c+=(a[i][k]-a[j][k])**2
  if math.sqrt(c)==int(math.sqrt(c)):
    r += 1
print(r)

Submission status: Wrong Answer

Solution code:
import math
n,d = map(int,input().split())
try:
  a = [list(map(int,input().split())) for j in range(0,n)]
except EOFError:
  pass
c = 0
r = 0
for i in range(0,n-1):
  for j in range(i+1,n):
    for k in range(0,d):
      c+=(a[i][k]-a[j][k])**2
  if math.sqrt(c)==int(math.sqrt(c)):
    r += 1
print(r)

Submission status: Wrong Answer

Solution code:
n,d = map(int,input().split())
try:
  a = [list(map(int,input().split())) for j in range(0,n)]
except EOFError:
  pass
c = 0
r = 0
for i in range(0,n-1):
  for j in range(i+1,n):
    for k in range(0,d):
      c+=(a[i][k]-a[j][k])**2
      ans = c**(1/2)
  if isinstance(ans,int) == True:
    r += 1
print(r)

Submission status: Wrong Answer

Solution code:
n,d = map(int,input().split())
try:
  a = [list(map(int,input().split())) for j in range(0,n)]
except EOFError:
  pass
c = 0
r = 0
for i in range(0,n):
  for j in range(i+1,n):
    for k in range(0,d):
      c+=(a[i][k]-a[j][k])**2
ans = c**(1/2)
if isinstance(ans,int) == True:
  r += 1
print(r)

Submission status: Wrong Answer

Solution code:
n,d = map(int,input().split())
try:
  a = [list(map(int,input().split())) for j in range(0,n)]
except EOFError:
  pass
c = 0
r = 0
for i in range(0,n-1):
  for j in range(i+1,n):
    for k in range(0,d):
      c+=(a[i][k]-a[j][k])**2
ans = c**(1/2)
if isinstance(ans,int) == True:
  r += 1
print(r)

Submission status: Wrong Answer

Solution code:
N, D = map(int, input().split())
zahyo = [0]*N
for i in range(N):
  zahyo[i] = list(map(int, input().split()))
count = 0
for i in range(N):
  for j in range(i+1, N):
    V = 0
    for k in range(D):
      V += float((zahyo[i][k]-zahyo[j][k])**2)
    if V.is_integer():
      count += 1
print(count)

Submission status: Wrong Answer

Solution code:
N, D = map(int, input().split())
zahyo = [0]*N
for i in range(N):
  zahyo[i] = list(map(int, input().split()))
count = 0
for i in range(N):
  for j in range(i+1, N):
    V = 0
    for k in range(D):
      V += (zahyo[i][k]-zahyo[j][k])**2
    if isinstance(V, int):
      count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import sys,math
input = sys.stdin.readline

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

for i in range(N):
  for j in range(N):
    num = 0
    if i < j:
      for k in range(D):
        num += pow(abs(X[i][k] - X[j][k]) ,2)
  if math.floor(math.sqrt(num)) ** 2 == num:
    cnt += 1

print(cnt)

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

for j in range (N-1):
  for k in range(j+1, N):
    t = 0
    for l in range(D):
      t += (X[j][l]-X[k][l])**2
      
    if (t**1/2)%1 ==0:
      cnt += 1
      
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
def good_distance(n, d, xli):

    ans = 0

    for i in range(n):
        count = 0
        for w in range(d):
            if i == n-1:
                count += (xli[i][w]-xli[0][w])**2
            else:
                count += (xli[i][w]-xli[i+1][w])**2

        if int(math.sqrt(count))**2 == count:
            ans += 1

    return ans

def main():
    n, d = map(int, input().split())
    xli = [list(map(int, input().split()))for i in range(n)]
    print(good_distance(n, d, xli))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys,math
input = sys.stdin.readline

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

print(X)

for i in range(1,N):
  for j in range(1,D):
      #num += pow(abs(X[i-1][j-1] - X[i][j]) ,2)
      print(X[i-1][j-1],X[i][j])
  #if int(math.sqrt(num)):
    #print(math.sqrt(num))
    #cnt += 1

#print(cnt)

Submission status: Wrong Answer

Solution code:
import sys,math
input = sys.stdin.readline

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

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

print(cnt)

Submission status: Wrong Answer

Solution code:
n, d = map(int, input().split())
L = [list(map(int, input().split())) for i in range(n)]
for i in range(n-1):
    for j in range(i+1, n):
        ans = 0
        int_ = 0
        for k in range(d):
            int_ += (L[i][k]-L[j][k])**2
        if int(int_**0.5)==int_**0.5:
            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)]
for i in range(n-1):
    for j in range(i+1, n):
        ans = 0
        int_ = 0
        for k in range(d):
            int_ += (L[i][k]-L[j][k])**2
        if int(int_**0.5):
            ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from math import sqrt

n,d = map(int,input().split())
li  = [list(map(int,input().split())) for i in range(n)]
tmp = 0
ans = 0

for i in range(n):
  for j in range(d):
    if i==n-1:
      tmp += pow(abs(li[i][j]-li[0][j]),2)
    else:
      tmp += pow(abs(li[i][j]-li[i+1][j]),2)
  if sqrt(tmp)%1==0:
    ans += 1
  tmp =  0

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)]
count = 0

import numpy as np
for i in range(n-1):
    for j in range(1,n):
        a = np.array(x[i])
        b = np.array(x[j])
        ab = sum(np.power((a-b),2))**0.5
        if ab%1 == 0:
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
# ABC133B

import numpy as np

n, d = map(int, input().split())
x = [0] * n
for i in range(n):
    x[i] = list(map(int, input().split()))
x = np.array(x)
count = 0
for i in range(n-1):
    for j in range(i+1, n):
        d = np.sqrt(sum((x[i, :] - x[j, :]) ** 2))
        print(i, j, "** d =", d)
        if d == int(d):
            count += 1
print(count)