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: Accepted

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

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

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

print(sum)

Submission status: Accepted

Solution code:
from itertools import combinations
from math import sqrt

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

cnt = 0
for x, y in combinations(ps, 2):
  if sqrt(sum((x[i]-y[i])**2 for i in range(d))).is_integer():
    cnt += 1
    
print(cnt)

Submission status: Accepted

Solution code:
n = [ int(i) for i in input().split()]
m = [[ int(i) for i in input().split()] for i in range(n[0])]

count=0

for i in range (n[0]-1):
  for j in range (i+1, n[0]):
    r = 0
    
    for l in range (n[1]):
      r += (m[i][l]-m[j][l])**2
      
    if r**0.5 == int( r**0.5):
      count += 1
      
print (count)

Submission status: Accepted

Solution code:
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()))

count = 0

for i in range(N-1):
    for j in range(i+1, N):
        distance = np.linalg.norm(np.array(X[i]) - np.array(X[j]))
        if distance == int(distance):
            count += 1

print(count)

Submission status: Accepted

Solution code:
from collections import defaultdict
import itertools
import math

d = defaultdict(int)

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

c = 0
for i,j in itertools.permutations(range(N),2):
    if i >= j :
        continue
    d = sum(
        map(lambda x:(X[i][x]-X[j][x])**2,range(D))
    )
    if d == math.floor(math.sqrt(d))**2:
        c += 1

print(c)

Submission status: Accepted

Solution code:
from math import sqrt
n, d = map(int, input().split())
dots = []
for i in range(n):
    dot = list(map(int, input().split()))
    dots.append(dot)
cnt = 0
for i in range(n-1):
    for j in range(i+1, n):
        distance = 0
        for dm in range(d):
            distance += pow(dots[i][dm] - dots[j][dm],2)
        dis = sqrt(distance)
        if int(dis) - dis == 0:
            cnt += 1
print(cnt)

Submission status: Accepted

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

ans = 0
zahyou = []
for i in range(n):
    zahyou.append(list(map(int, input().split())))
for i in range(n):
    sum = 0
    temp0 = zahyou[i]
    for j in range(n):
        if i <=  j:
            break
        temp1 = zahyou[j]
        sum = 0
        for k in range(d):
            sum = sum + (temp0[k] - temp1[k])**2
        a =  sum**(1/2)
        if a.is_integer():
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
from math import modf

N, D = [int(i) for i in input().split(" ")]

vectors = np.empty((N, D))
for i in range(N):
    vectors[i, :] = np.array([int(i) for i in input().split(" ")])

count = 0
for i, u in enumerate(vectors):
    for v in vectors[i+1:, :]:
        if modf(np.linalg.norm(u - v))[0] < 1e-7:
            count += 1

print(count)

Submission status: Accepted

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

import itertools
import math
S = list(itertools.combinations(range(N), 2))
ans = 0
for k in S:
  a = 0
  for j in range(D):
    a += abs(pow(L[k[0]][j] - L[k[1]][j], 2))
  if math.sqrt(a).is_integer():
    ans += 1
print(ans)

Submission status: Accepted

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

res = 0

for i in range(N):
  for j in range(i, N):
    if i != j:
      tmp = 0
      for k in range(D):
        tmp += (L[i][k] - L[j][k]) ** 2
      
      import math
      tmp = math.sqrt(tmp)
      if tmp - int(tmp) == 0:
        res += 1
        
print(res)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np

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

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

Submission status: Accepted

Solution code:

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

lst_A = []

ans = 0

for i in range(N):
    lst_W = input().split()
    for j in range(len(lst_W)):
        lst_W[j] = int(lst_W[j])
    lst_A.append(lst_W)

for i in range(len(lst_A) - 1):
    for j in range(i + 1, len(lst_A)):
        res = 0
        for k in range(D):
            res += (lst_A[i][k] - lst_A[j][k]) ** 2
        check = res ** 0.5 % 1
        if check == 0.0:
            ans += 1

print(ans)

Submission status: Accepted

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

cnt=0
f=0
for i in range(n-1):
    for j in range(n-i-1):
        for k in range(d):
            f+=(li[i][k]-li[n-j-1][k])**2
        f=math.sqrt(f)
        if f.is_integer()==True:
            cnt+=1
        f=0
        #print(i,n-j-1)

print(cnt)

Submission status: Accepted

Solution code:
import math

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

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

cou = 0
ans = 0

for i in range(n):
     for j in range(i+1,n):
          for k in range(d):
               cou += abs(a[i][k]-a[j][k])**2
          if cou**(1/2)%1 == 0.0:
               ans += 1
          cou = 0
print(ans)

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
x=[]
ans=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):
        t = 0
        for k in range(D):
            t += (x[i][k]-x[j][k])**2
        A=t**(1/2)   #距離
        A=int(A)   #いったん整数に戻す
        if A**2 == t:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
from numpy import*;n,_=map(int,input().split());a=0;M=[array(list(map(int,input().split()))) for i in range(n)]
for i in range(n):
	for j in range(i+1,n):
		if linalg.norm(M[i]-M[j]).is_integer():a+=1
print(a)

Submission status: Accepted

Solution code:
import math

N,D = list(map(int,input().split()))
list1 = []
all1 = 0
C = 0
for i in range(N):
    X = list(map(int,input().split()))
    list1.append(X)
for i in range(N):
    for j in range(i+1,N):
        a = list1[i]
        b = list1[j]
        for z in range(D):
            all1 = all1 + (a[z] - b[z])**2 
        if math.sqrt(all1).is_integer() :
            C = C + 1
        all1 = 0
print(C)

Submission status: Accepted

Solution code:
import numpy as N;n,_=map(int,input().split());a=0;M=[N.array(list(map(int,input().split()))) for i in range(n)]
for i in range(n):
	for j in range(i+1,n):
		if N.linalg.norm(M[i]-M[j]).is_integer():a+=1
print(a)

Submission status: Accepted

Solution code:
N,D = map(int,input().split())
X = list()
ans = 0
for i in range(0,N):
    XN = list(map(int,input().split()))
    X.append(XN)
    if i > 0:
        k = i - 1
        while(k >= 0):
            delta = 0
            for j in range(0,D):
                delta += (X[i][j] - X[k][j])**2
            if float.is_integer(delta**(1/2)) :
                ans += 1
            k -= 1
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
def input(): return sys.stdin.readline().strip()
def gcd(x, y): return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y): return (x * y) // gcd(x, y)
MOD = 10 **9 + 7

# N = int(input())
# S = input()
N, D = map(int, input().split())
# 横
# L = [int(x) for x in input().split()]
# 縦
# A = [int(input()) for _ in range(N)]
# 多次元
X = [[int(x) for x in input().split()] for _ in range(N)]

comb = list(itertools.combinations(X, 2))

ans = 0
for c in comb :
    tmp = 0
    for a, b in zip(c[0], c[1]) :
        tmp += (a - b) ** 2

    if math.sqrt(tmp) % 1 == 0 :
        ans += 1

print(ans)

Submission status: Accepted

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):
        t = 0
        for k in range(d):
            t += (X[i][k] - X[j][k]) ** 2
        a = int(t ** (1 / 2))
        if a ** 2 == t:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
X=[tuple(map(int,input().split())) for i in range(N)]
def distsquare(z,y):
    res=0
    for i in range(D):
        res+=(z[i]-y[i])**2
    return res
def issquare(M):
    tmp=0
    while(tmp*tmp<=M):
        if tmp*tmp==M:
            return True
        tmp+=1
    return False
ans=0
for i in range(N):
    for j in range(N):
        if i<j:
            if issquare(distsquare(X[i],X[j])):
                ans+=1
print(ans)

Submission status: Accepted

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

for j in range(N):
	for k in range(j):
		total = sum((lis[j][m] - lis[k][m]) ** 2 for m in range(D))
		sqr = total ** 0.5
		if sqr.is_integer():
			count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N,D = map(int, input().split())
X=np.array([[float(x) for x in input().split()] for i in range(N)])
count=0
for i in range(N):
    for j in range(i+1,N):
        count = count + ( 1 if np.linalg.norm(X[i]-X[j]).is_integer() else 0 )
print(count)

Submission status: Accepted

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

ans_count = 0
for i in range(N):
  for j in range(i):
    total = sum((X[i][k] - X[j][k]) ** 2 for k in range(D))
    distance = int(total ** 0.5)
    if (total == (distance ** 2)):
      ans_count += 1

print(ans_count)

Submission status: Accepted

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

counter = 0

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

        distance = distance ** (1/2)
        if distance == int(distance):
            counter += 1

print(counter)

Submission status: Accepted

Solution code:
N, D = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(N)]
c = 0
for i in range(N - 1):
    for j in range(i + 1,N):
        c += (sum((a-b)**2 for a,b in zip(x[i], x[j])) ** 0.5).is_integer()

print(c)

Submission status: Accepted

Solution code:
import itertools, math

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

c = 0
for i, j in itertools.combinations(range(n), 2):
    d = sum((y - z) ** 2 for y, z in zip(x[i], x[j]))
    if d == math.floor(math.sqrt(d)) ** 2:
        c += 1

print(c)

Submission status: Accepted

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

print(c)

Submission status: Accepted

Solution code:
from math import sqrt
point_num, dimension = tuple(int(i) for i in input().split(" "))
cor_list = []
for i in range(point_num):
    cor_list.append(tuple(int(j) for j in input().split(" ")))


def distance(X, Y):
    in_sqrt = 0
    for k in range(dimension):
        in_sqrt += (X[k] - Y[k]) ** 2
    return sqrt(in_sqrt)


ans = 0
for i in range(point_num - 1):
    for j in range(i + 1, point_num):
        d = distance(cor_list[i], cor_list[j])
        if d == int(d):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math

n, d = map(int, raw_input().split(" "))

x = []
for i in range(0, n):
    x.append(map(int, raw_input().split(" ")))

ans = 0
for i in range(0, n):
    for j in range(i + 1, n):
        dist2 = 0
        for a in range(0, len(x[i])):
            tmp = x[i][a] - x[j][a]
            dist2 += tmp * tmp

        root = int(math.sqrt(dist2))
        if root * root == dist2:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import itertools
import math

N, d = map(int, input().split())
P = [list(map(int, input().split())) for i in range(N)]
num = 0

for p in itertools.combinations(P, 2):
  length = [(p[0][f] - p[1][f]) ** 2 for f in range(d)]
  if math.sqrt(sum(length)).is_integer():
    num += 1
print(num)

Submission status: Accepted

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

df = []
for i in range(N):
  df.append(list(map(int,input().split())))
 
count = 0
for i in range(N):
  for j in range(i + 1,N):
    a = 0
    for k in range(D):
      a += (df[i][k] - df[j][k])**2
    
    a = math.sqrt(a)
    if a - int(a) == 0:
      count += 1
print(count)

Submission status: Accepted

Solution code:
from itertools import combinations
import math

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

li_n = list()

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

for con in combinations(li_n, 2):
    result = math.sqrt(sum([(abs(x - y)) ** 2 for x, y in zip(con[0], con[1])]))
    if result.is_integer():
        counter += 1

print(counter)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,D =map(int, input().split())
all_list = [list(map(int, input().split())) for i in range(N)]
#>>>4
count = 0
for n in range (N):
    for nn in range(n):
        distance = 0
        for d in range(D):
            kou = (all_list[n][d] - all_list[nn][d])**2
            distance += kou
        for s in range(250):
            if distance == s**2:
                count += 1
                break
print(count)

Submission status: Accepted

Solution code:
import numpy as np

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

count = 0
for i in range(N):
    for j in range(i+1, N):
        tmp = 0
        for k in range(D):
            tmp += (point_i_lst[i][k] - point_i_lst[j][k])**2
        
        tmp = np.sqrt(tmp)
        if tmp - int(tmp) == 0:
            count += 1

print(count)

Submission status: Accepted

Solution code:
import numpy as np
import math
n,d=[int(i) for i in input().split()]
x=[]
for _ in range(n):
  x.append(np.array([int(i) for i in input().split()]))
def dis(x,y):
  return int(np.sum((x-y)**2))
def iss(x):
  a=round(math.sqrt(x))
  return a**2==x
k=0
for i in range(n):
  for j in range(i+1,n):
    if iss(dis(x[i],x[j])):
      k+=1
print(k)

Submission status: Accepted

Solution code:
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):
    dis=sum([(A[i][k]-A[j][k])**2 for k in range(d)])
    if dis**(1/2)==int(dis**(1/2)):
      ans+=1
print(ans)

Submission status: Accepted

Solution code:
import math


times = input().split()
zahyou = [] 
count = 0

for i in range(int(times[0])):
  list = input().split()
  zahyou.append(list)
  
for i in range(int(times[0])-1):
  for k in range(i+1,int(times[0])):
    result = 0
    for j in range(int(times[1])):
       point1 = zahyou[i][j]
       point2 = zahyou[k][j]
       result += (int(point1) - int(point2))**2
  
    result2 = str(math.sqrt(result)).split(".")
    if result == int(result2[0])**2:
      count += 1
    
print(count)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import itertools
import numpy as np

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

ans = 0
for x1, x2 in itertools.combinations(X_LIST, 2):
    distance = np.linalg.norm(np.array(x1) - np.array(x2))
    if distance.is_integer():
        ans += 1
print(ans)

Submission status: Accepted

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

a = []
for i in range(200):
  a.append(i**2)

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

Submission status: Accepted

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

ans = 0
count = 0
for j in range(int(a)):
  for k in range(int(a)):
    if j > k:
        ans = 0
        for l in range(int(b)):
            ans = ans + (int(c[j][l]) - int(c[k][l])) ** 2
        if ans ** 0.5 == round(ans ** 0.5):
            count = count + 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import sqrt
N,D=map(int,input().split())
ans=0
Points=[]
for i in range(N):
  Points.append(list(map(int,input().split())))
bia=1
for point in Points:
  for i in range(N-bia):
    dist=0.0
    for j in range(D):
      #print(k,i+bia,j)
      dist+= (point[j]-Points[i+bia][j]) * (point[j]-Points[i+bia][j])
    dist=sqrt(dist)
    if dist==int(dist):
      ans+=1
  bia+=1
print(ans)

Submission status: Accepted

Solution code:
from scipy.spatial import distance


def solve(string):
    n, d, *x = map(int, string.split())
    x = [tuple(c) for c in zip(*[iter(x)] * d)]
    dist = distance.cdist(x, x)
    return str(((dist == dist.astype("int32")).sum() - n) // 2)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m)+'\n'.join([input() for _ in range(n)])))

Submission status: Accepted

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

for i in range(n):
    for j in range(i+1,n):
        dis=0
        for k in range(d):
            dis += (L[i][k]-L[j][k])**2
        dis = dis**0.5
        if dis % 1.0 ==0:
            ans +=1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
ans = 0
N, D = list(map(int, input().split()))
x = [np.array(list(map(int, input().split()))) for _ in range(N)]

for i in range(N):
    a = x[i]
    for b in x[i + 1 : N]:
        c = a - b
        d = np.linalg.norm(c)
        if d.is_integer():
            ans += 1
print(ans)

Submission status: Accepted

Solution code:

import math

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

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


def Distance(a = [], b = []):
    res = 0.0
    for x, y in zip(a, b):
        res += (x - y) * (x - y)
    return math.sqrt(res)

count = 0
for i in range(int(len(X))):
    for j in range(i + 1, int(len(X))):
        r = Distance(a=X[i], b=X[j])
        if r.is_integer():
            count+=1
        

print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    ans = 0
    L = []
    for _ in range(N):
        l = []
        D = input().split()
        for d in D:
            l.append(int(d))
        L.append(l)
    for n in range(N - 1):
        for i in range(N)[n + 1:]:
            s = 0
            for m in range(M):
                s += (L[n][m] - L[i][m]) ** 2
            r = 1
            while True:
                R = r * r
                if R == s:
                    ans += 1
                elif R > s:
                    break
                r += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import math

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

ans = 0
for i in range(N):
    for j in range(i+1, N):
        dis_2 = sum([(y - z) ** 2 for (y, z) in zip(X[i], X[j])])
        if int(math.sqrt(dis_2)) ** 2 == dis_2:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math

N, D = list(map(int, input().split()))
x = [input().split() for l in range(N)]
count = 0
for i in range(N):
    for j in range(i+1,N):
        norm = 0
        for k in range(D):
            diff = abs(int(x[i][k]) - int(x[j][k]))
            norm += diff * diff
        
        bool1 = False
        for k in range(1, norm+1):
            if k*k == norm:
                bool1 = True
        
        if bool1:
            count += 1

print(count)

Submission status: Accepted

Solution code:
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(i+1,N):
        ans = 0
        for x in range(D):
            ans += abs(X[i][x] - X[j][x])**2
        for k in range(ans+1):
            if k ** 2 == ans:
                cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def check(a, b, d):
  sum = 0
  for i in range(0, d):
  	sum += (a[i] - b[i])**2
  return ((sum - int(math.sqrt(sum))**2) == 0)

n, d = [int(s) for s in input().split()]
xn = []
for i in range(0, n):
  xn.append([int(s) for s in input().split()])

cnt = 0
for i in range(0, n-1):
  for j in range(i+1, n):
    if(check(xn[i], xn[j], d)):
      cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math
n, d = [int(i) for i in input().split()]
dot = []
for _ in range(n):
  zahyo = list(map(int, input().split()))
  dot.append(zahyo)
cnt = 0
for i in range(n-1):
  for j in range(i+1, n):
    test = 0
    for k in range(d):
      test += pow(dot[i][k] - dot[j][k], 2)
    test_a = float(math.sqrt(test))
    test_b = int(math.sqrt(test))
    if(test_a == test_b):
      cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import math

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

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

res = 0
x = 0
while x <= len(XX) - 2:
    y = x + 1
    while y <= len(XX) - 1:
        sum = 0
        for i in range(D):
            sum += math.pow(XX[x][i] - XX[y][i], 2)
        h = int(math.sqrt(sum))
        if math.pow(int(math.sqrt(sum)), 2) == sum:
            res += 1
        y += 1
    x += 1

print(res)

Submission status: Accepted

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

#+++++
		
def main():
	n, d = map(int, input().split())
	ll=lambda :list(map(int, input().split()))
	xl=[ll() for i in range(n)]
	
	lll= [x**2 for x in range(170)]
	cc=0
	for i, x in enumerate(xl):
		for y in xl[i+1:]:
			a=0
			for xv, yv in zip(x,y):
				a += (xv - yv)**2
			cc+=1 if a in lll else 0
		
	print(cc)
	
	
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np


def is_integer_distance(np_a):
    return isqrt(np.dot(np_a, np_a))


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


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

np_x = np.asarray(x)

count = 0
for i in range(n):
    for j in range(i+1, n):
        if is_integer_distance(np.subtract(np_x[i], np_x[j])):
            count += 1

print count

Submission status: Accepted

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

import math

result = 0

for i in range(N):
    for j in range(i + 1, N):
        d = sum((X[i][k] - X[j][k])**2 for k in range(D))
        r = math.ceil(math.sqrt(d))
        if r * r == d:
            result += 1

print(result)

Submission status: Accepted

Solution code:
from math import sqrt
N,D,A=[int(x)for x in input().split()]+[[]];exec("A+=[[int(x)for x in input().split()]];"*N);C=0
for i in range(N):
    for j in range(i+1,N):
        S=k=0;exec("S+=(A[i][k]-A[j][k])**2;k+=1;"*D);C+=1 if int(sqrt(S))==sqrt(S) else 0
print(C)

Submission status: Accepted

Solution code:
import sys
import numpy as np

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

X = np.zeros([N,D])
for n in range(N):
    X[n,:] = np.array(list(map(int, input().split())))

cnt = 0
for n1 in range(N):
    for n2 in range(n1+1,N):
        r = 0
        for d in range(D):
            r += (X[n1,d]-X[n2,d])**2

        if np.sqrt(r) == int(np.sqrt(r)):
            cnt += 1

print(cnt)

Submission status: Accepted

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

ans = 0

for i in range(n):
    for j in range(i+1,n):
        dis_sq = 0
        for k in range(d):
            dis_sq += (points[i][k]-points[j][k]) ** 2
        dis = math.sqrt(dis_sq)
        if dis.is_integer():
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math

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

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

count = 0
for i in range(n):
    for j in range(n):
        if i <= j:
            continue
        dist = 0
        for k in range(d):
            dist += (x[i][k] - x[j][k])**2
        dist = math.sqrt(dist)
        if dist % 1 == 0:
            count += 1

print(count)

Submission status: Accepted

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