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 io
import math

nim, delta = list(map(int, input().split()))

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

counter = 0

for i in range(nim):
    for j in range(i + 1, nim):
        pio = 0
        for k in range(delta):
            pio += (xen[i][k] - xen[j][k]) ** 2
        root = pio ** 0.5
        if root.is_integer():
            counter += 1
print(counter)

Submission status: Accepted

Solution code:
N,D=map(int, input().split())
X = [ list(map(int,input().split(" "))) for i in range(N)]
count = 0
for i1 in range(N):
  for i2 in range(i1+1,N):
    sos = 0
    for k in range(D):
      sos = sos + (X[i1][k]-X[i2][k])**2
    if sos**0.5 % 1 == 0:
      count = count + 1
print(count)

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
point = [[int(i) for i in input().split()] for j in range(n)]
count = 0
for i in range(n):
    for j in range(i + 1, n):
        norm = 0
        for pi, pj in zip(point[i], point[j]):
            norm += (pi - pj) ** 2
        if int(norm**0.5) == norm**0.5:
            count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = [i*i for i in range(400)]
n,d = map(int,input().split())
x = []
for _ in range(n):
    x.append(list(map(int,input().split())))
ans = 0
for i in range(n-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 in a:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n,d = map(int,input().split())
d_list  = []
ans_list = []
for i in range(n):
     d_list.append(list(map(int,input().split())))

cnt = 0
for i in range(len(d_list)-1):
    for j in range(i+1,len(d_list)):
        tmp = 0
        for n in range(d):
            tmp += (d_list[i][n] - d_list[j][n])**2
        if int(np.sqrt(tmp))**2 == tmp:
            cnt += 1
            
print(cnt)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
def dis(a,b):
    ret=0
    for x,y in zip(a,b):
        ret+=(x-y)**2
    return int(ret**(1/2))**2==ret
ans=0
for i in range(n):
    for j in range(i+1,n):
        if dis(l[i],l[j]):ans+=1
print(ans)

Submission status: Accepted

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

c = 0
for i in range(N):
  for j in range(i+1,N):
    s = 0
    for k in range(D):
      s += (X[i][k] - X[j][k])**2
    for l in range(1,math.floor(math.sqrt(s))+1):
      if s == l*l:
        c +=1
print(c)

Submission status: Accepted

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

count = 0
for i in range(N-1):
    X_i = X[i]
    for j in range(i+1, N):
        X_j = X[j]
        dis_list = [(X_i[k] - X_j[k])**2 for k in range(D)]
        dis = sum(dis_list) ** 0.5
        if dis.is_integer():
            count += 1
print(count)

Submission status: Accepted

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




count =0

for i in range(N):
    for j in range(i+1,N):
        n = 0
        for k in range(D):
            n += (X[i][k] - X[j][k])**2
        n_d = int(n**0.5)**2
        if n == n_d:
            count += 1
print(count)

Submission status: Accepted

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

count = 0
for i in range(N):
    for j in range(i+1, N):
        dist = 0
        for k in range(D):
            dist += abs(X[i][k] - X[j][k]) ** 2

        if math.sqrt(dist).is_integer():
            count += 1
        
print(count)

Submission status: Accepted

Solution code:
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):
    Dis = 0
    for k in range(D):
      Dis += (X[i][k] - X[j][k])**2 
    Dis = (Dis)**0.5
    if int(Dis) == Dis:
      ans += 1

print(ans)

Submission status: Accepted

Solution code:
def distance_judge(d,x,y):
  dis = 0
  for index in range(d):
    dis = dis + pow(x[index]-y[index],2)
  dis = dis**0.5
  if int(dis)==dis: return True
  else: return False

def main():
  n,d = map(int, input().split())
  whole = []
  count = 0
  for i in range(n):
    coord = list(map(int, input().split()))
    whole.append(coord)

  for i in range(n-1):
    for j in range(i+1,n):
      flag = distance_judge(d,whole[i],whole[j])
      if flag==True: count += 1
  print(count)
  
if __name__=='__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N,D = list(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):
        rec = 0
        for d in range(D):
            rec += abs(X[i][d] - X[j][d]) ** 2
        rec = math.sqrt(rec)
        if rec - math.floor(rec) == 0:
            count += 1
print(count)

Submission status: Accepted

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

count = 0

for i in range(n-1):
    for j in range(i+1,n):
        sum = 0
        for k in range(d):
            sum += (c[i][k]-c[j][k])**2
        
        if sum ** 0.5 % 1 == 0:
            count += 1

print(count)

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n,d = iim()
cd = []
for i in range(n):
    cd.append(iil())
cnt = 0
for i in range(n):
    for j in range(i+1,n):
        di = sum([(y-x)**2 for (x,y) in zip(cd[i],cd[j])])**0.5
        if di == int(di):
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math
N,D = map(int,input().split())
k = []
ans_2 = 0
ans_1 = 0
now = 0
for i in range(N):
    k.append(list(map(int,input().split())))
for i in range(0,N):
    for j in range(i+1,N):
        for _ in range(D):
            now += (k[i][_]-k[j][_])**2
        ans_1 = math.sqrt(now)
        if ans_1%1 == 0:
            ans_2 += 1
        now = 0
        ans_1 = 0
print(ans_2)

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n,d=MI()
co=[]
for i in range(n):
    co.append(LI())
#print(co)
ans=0
for i in range(n):
    for j in range(n):
        l2=0
        for k in range(d):
            l2+=(co[j][k]-co[i][k])**2
        l=math.sqrt(l2)
        if l-int(l)==0:
            ans+=1
trans=(ans-n)//2
print(trans)

Submission status: Accepted

Solution code:
from math import sqrt

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

def get_dist(x1, x2):
    return sqrt(sum([(y-z)**2 for y, z in zip(x1, x2)]))

cnt = 0
for i in range(N-1):
    X_i = C[i]
    for X_j in C[i+1:]:
        d = get_dist(X_i, X_j)
        if d.is_integer():
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
X=[]
kotae=0
for i in range(n):
    x=list(map(int,input().split()))
    X.append(x)
    for j in range(i):
        ans=0
        for p in range(d):
            ans+=abs(x[p]-X[j][p])**2
        if (ans**0.5).is_integer()==1:
            kotae+=1
print(kotae)

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):
        tmp = 0
        for k in range(D):
            tmp += (X[i][k] - X[j][k])**2
        if tmp**0.5 %1 == 0:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

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

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

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

print(ans)

Submission status: Accepted

Solution code:
N, D = [int(i) for i in input().split()]
X = []
for i in range(N):
  X += [[int(i) for i in input().split()]]
a = 0
for i in range(N):
  for j in range(i):
    y = 0
    for k in range(D):
      y += (X[i][k] - X[j][k]) ** 2
    if y == int(y ** 0.5) ** 2:
      a += 1
print(a)

Submission status: Accepted

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

vector = [[0 for i in range(d)] for j in range(n)]

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

cnt = 0
for i in range(n - 1):
    for j in range(i + 1,n):
        
        num = 0
        for k in range(d):
            num += (vector[i][k] - vector[j][k])**2 * 1.0
        
        if np.sqrt(num).is_integer():
            cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def heho(n):
    for i in range(1,n+1):
        if i*i==n:
            return True

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

if d!=1:
    for i in range(n-1):
        for j in range(i+1,n):
            z=0
            for k in range(d):
                z+=abs(x[i][k]-x[j][k])**2
            if heho(z):
                cnt+=1
else:
    for i in range(n-1):
        for j in range(i+1,n):
            v=0
            v+=abs(x[i][0]-x[j][0])**2
            if heho(v):
                cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
import math

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

print(ans)

Submission status: Accepted

Solution code:
import math

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

for i in range(2 ** n):
    ans = []
    for j in range(n):
        if (i >> j) & 1:
            ans.append(x[j])
    
    if len(ans) == 2:
        u = 0
        for a, b in zip(ans[0], ans[1]):
            u += abs(int(a)-int(b)) ** 2

        if math.sqrt(u).is_integer():
            c += 1

print(c)

Submission status: Accepted

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

for i in range(N):
    for j in range(1,N):
        if i+j > N-1:
            continue
        for k in range(D):
            Answer += (List[i][k]-List[i+j][k])**2
        if (int(Answer**(1/2)))**2 == Answer :
            Count += 1
        Answer = 0

print(Count)

Submission status: Accepted

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

count = 0
eps = 10**-6
for i in range(n-1):
    for j in range(i+1, n):
        total = 0
        for k in range(d):
             total += pow(x[i][k] - x[j][k], 2)
        v = math.sqrt(total)
        if math.ceil(v + eps) != math.ceil(v - eps):
            count += 1
print(count)

Submission status: Accepted

Solution code:
from math import sqrt
from itertools import combinations

N, D = map(int,input().split())
cnt = 0
listX = []
for j in range(N):
    listX.append(list(map(int,input().split())))

comb = list(combinations(listX, 2))

for i in comb:
    goukei = 0
    for m, n in zip(i[0], i[1]):
        goukei += (m - n) ** 2
    if sqrt(goukei) == int(sqrt(goukei)):
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import itertools

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

ans = 0
for x1, x2 in itertools.combinations(x, 2):
    d = sum((yi - zi)**2 for yi, zi in zip(x1, x2)) ** 0.5
    if d == int(d):
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
A=[0]*N
i=0
while i<N:
    A[i]=list(map(int,input().split()))
    i+=1

i=0
ans=0
while i<N:
    j=i+1
    while j<N:
        k=0
        d1=0
        while k<D:
            d1+=(A[i][k]-A[j][k])**2
            k+=1
        d2=d1**0.5
        ans+=1*d2.is_integer()
        j+=1
    i+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

def d(x, y):
  x = np.array(x)
  y = np.array(y)
  return np.sqrt(np.sum((x - y)**2))
  
X = [[list(map(int, input().split()))] for _ in range(N)]

cnt = 0
for i in range(N):
  for j in range(N):
    if i < j:
      cnt += d(X[i], X[j]).is_integer()

print(cnt)

Submission status: Accepted

Solution code:
from itertools import *
n,d = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(n)]
ans = 0
for a,b in combinations(x,2):
  delta = 0
  for i in range(d):
    delta += (a[i] - b[i])**2
  if (delta **0.5).is_integer():
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
def q2():
    import math
    N, D = (int(i) for i in input().split())
    X = []
    for n in range(N):
        X.append([int(i) for i in input().split()])

    ans = 0
    for i in range(N):
        for j in range(N):
            if i >= j:
                continue  # 既に評価した座標はスキップ

            s = 0  # 距離の合計
            for d in range(D):
                s += (X[i][d] - X[j][d])**2

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

    print(ans)


if __name__ == '__main__':
    q2()

Submission status: Accepted

Solution code:
import math

# 0924 start
inputted = list(map(int, input().split()))
N = inputted[0]
D = inputted[1]

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

calculate = lambda y, z : math.sqrt(sum([(yi - zi) ** 2 for yi, zi in zip(y, z)]))

answer = 0
for i in range(N):
    for j in range(N):
        if i >= j: continue

        distance = calculate(X[i], X[j])
        if distance.is_integer(): answer += 1

print(answer)

Submission status: Accepted

Solution code:
import math
p,q= input().split()
a,b =(int(p), int(q))
ans_list = []
for i in range(a):
    blank_list = input().split()
    ans_list.append(blank_list)
a_list = [0,1,2,3,4,5,6,7,8,9]
count = 0

for x in range(a):
    a_list.pop(0)
    
    for y in range(a-x-1):
        total = 0 
        y_num = a_list[y]
        for i in range(b):
            
            total += (int(ans_list[x][i]) - int(ans_list[y_num][i]))** 2
            distance = total ** 0.5
        
        if distance == math.floor(distance):
            count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations
n,d = map(int,input().split())
l = []
ans = 0

for i in range(n):
    l.append(list(map(int,input().split())))
for a,b in combinations(l,2):
    if (sum((a[i]-b[i])**2 for i in range(d))) ** (1/2) % 1 == 0:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:

from itertools import combinations
n,d = map(int,input().split())
l = []
ans = 0

for i in range(n):
    l.append(list(map(int,input().split())))
for a,b in combinations(l,2):
    if (sum((a[i]-b[i])**2 for i in range(d)))**(1/2) % 1 == 0:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
n, d = map(int, input().split())
l = []
count = 0
for i in range(n):
    l.append(list(map(int, input().split())))
for a, b in combinations(l, 2):
    if (sum((a[i]-b[i])**2 for i in range(d)))**(1/2) % 1 == 0:
        count += 1
print(count)

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
square = [i**2 for i in range(1, 10 * 40**2)]

def distsq(i, j):
    total = 0
    for k in range(d):
        total += (x[i][k]-x[j][k])**2
    return total

count = 0
for i in range(n-1):
    for j in range(i+1, n):
        if distsq(i, j) in square:
            count+=1
print(count)

Submission status: Accepted

Solution code:
from itertools import permutations, combinations,combinations_with_replacement,product
n , d= map(int,input().split())

a=[i for i in range(n)]
p = list(combinations(a,2))

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

ans = 0
for x , y in p:
    ty = 0
    for j in range(d):
        ty += (s[x][j]-s[y][j])**2
    if ((ty)**0.5).is_integer():
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n,d=map(int,input().split())
nda=np.empty((0,d),int)
ans=0
for i in range(0,n):
  a=np.array([list(map(int,input().split()))])
  for j in range(i):
    chklen=np.linalg.norm(a-nda[j])
    if chklen==chklen//1:
      ans+=1
  nda=np.append(nda,a,axis=0)
print(ans)

Submission status: Accepted

Solution code:
import math
def main():

    x = []
    N, D = map(int, input().split())
    for _ in range(N):
        y = list(map(int, input().split()))
        x.append(y)
    ans = 0
    for i in range(N):
        for j in range(i):
            d1 = 0
            for k in range(D):
                d1 += pow(x[i][k]-x[j][k], 2)
            d1 = math.sqrt(d1)
            if d1 == int(d1): ans += 1
    return ans

if __name__ == '__main__':
    print(main())

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

#!/usr/bin/env python3

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

def dist(X,i,j):
    dist = 0
    for k in range(D):
        dist += (X[i][k] - X[j][k]) **2
    dist = dist ** 0.5
    return dist.is_integer()

for i in range(N):
    for j in range(N):
        if i >= j :
            continue
        else:
            if dist(X,i,j):
                cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
from itertools import combinations

N, D = [int(n) for n in input().split()]
X = []
for i in range(N):
    X.append([int(n) for n in input().split()])
ans = 0
for i, j in combinations(X, 2):
    if (sum([(j[d]-i[d])**2 for d in range(D)])**0.5).is_integer():
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

N, D = [int(n) for n in input().split()]
X = []
for i in range(N):
    p = [int(n) for n in input().split()]
    X.append(p)
ans = 0
for i,j in combinations(X, 2):
    dd = 0
    for d in range(D):
        dd += (j[d]-i[d])**2
    if (dd**0.5).is_integer():
        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)]
count = 0
for i in range(n-1):
    for j in range(i+1, n):
        res = 0
        for k in range(d):
            res += pow(x[i][k]-x[j][k], 2)
        if pow(res, 0.5).is_integer():
            count += 1
print(count)

Submission status: Accepted

Solution code:
def chkSQ(n):
  for i in range(128):
    if n==i**2:
      return 1
  return 0

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

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

print(ans)

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
X=[list(map(int,input().split())) for i in range(N)]
import math
def dis(X,Y):
  return math.sqrt(sum([pow((x-y),2) for x,y in zip(X,Y)]))
ans=0
for i in range(N):
  for j in range(i+1,N):
    if dis(X[i],X[j]).is_integer():
      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)]


def dist(a, b):
    sm = 0
    for ea, eb in zip(a, b):
        sm += (ea - eb) ** 2

    return sm


ans = 0
for i in range(n):
    for j in range(i + 1, n):
        dst = dist(x[i], x[j])
        for k in range(int(dst ** 0.5) + 1):
            if k ** 2 == dst:
                ans += 1
                break

print(ans)

Submission status: Accepted

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


def dist(a, b):
    sm = 0
    for ea, eb in zip(a, b):
        sm += (ea - eb) ** 2

    return sm ** 0.5


ans = 0
for i in range(n):
    for j in range(i + 1, n):
        dst = dist(x[i], x[j])
        for k in range(int(16000 ** 0.5) + 1):
            if k == dst:
                ans += 1
                break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
import numpy as np

def main():
    N, D = input_nums()
    Xs = {}
    for i in range(N):
        Xs[i] = np.array(input_nums())
    cnt = 0
    for i in range(N):
        for j in range(i+1, N):
            a = np.sqrt(np.sum(np.square(Xs[i] - Xs[j])))
            if a == int(a):
                cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
N,D=map(int,input().split())
X=[list(map(int,input().split())) for _ in range(N)]
count=0
ans=0
for k in range(N):
    for l in range(k+1,N):
        for m in range(D):
            ans=ans+(X[k][m]-X[l][m])**2
        ans=math.sqrt(ans)
        if ans.is_integer():
            count=count+1
        ans=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=0
for i in range(n-1):
    for j in range(i+1,n):
        dist=sum( (x[i][k]-x[j][k])**2 for k in range(d) )**0.5
        if dist%1==0: 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)]
tmp = 0
ans = 0
for i in range(N):
    for j in range(i + 1,N):
        for d in range(D):
            tmp += (x[i][d] - x[j][d])**2
        tmp = math.sqrt(tmp)
        if tmp.is_integer():
            ans += 1
        tmp = 0
print(ans)

Submission status: Accepted

Solution code:
import math

n, d = map(int,input().split())
x=[]
ans = 0
y = 0.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): #それより前にリストに入っていたものについて
        y = 0.0
        for k in range(d): #次元数だけループ
            y = y + (x[i][k] - x[j][k])**2 #距離を計算
        if math.sqrt(y).is_integer() == True: #距離が整数なら
            ans = ans + 1 #答えに1を加える

print(ans)

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def distance(x,y):
    dist=0
    for i in range(len(x)):
        dist+=(x[i]-y[i])**2.0
    dist=(dist**0.5)
    return dist

def do():
    n,d=INTM()
    xs=[]
    ct=0
    for i in range(n):
        xs.append(LIST())
    for i in range(n-1):
        for k in range(i+1,n):
            temp=0
            distan=distance(xs[i],xs[k])
            if distan==int(distan):
                ct+=1
    print(ct)
            
if __name__ == '__main__':
    do()

Submission status: Accepted

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

c=0

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

Submission status: Accepted

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

  
for i in range(126):
  heiho.append(i*i)


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 dis in heiho:
      ans+=1
print(ans)

Submission status: Accepted

Solution code:
import math
n,d = map(int,input().split())
c=0
pos={}
for i in range(n):
    pos[i]=list(map(int,input().split()))

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

print (c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

Xlist = []
countsum = 0
for count in range(N):
    X = list(map(int,input().split()))
    Xlist.append(X)

for count1 in range(N):
    X1 = Xlist[count1]
    for count2 in range(count1 + 1,N):
        X2 = Xlist[count2]
        cul = 0
        for count3 in range(D):
            cul += abs(X1[count3] - X2[count3])**2
        if math.sqrt(cul) % 1 == 0:
            countsum += 1
print(countsum)

Submission status: Accepted

Solution code:
import numpy as np
n,d=map(int,input().split()) 
x=np.array([list(map(int,input().split())) for i in range(n)])
a=0
for k in range(n):
    for i in range(k+1,n):
        if np.linalg.norm(x[k]-x[i]).is_integer():
            a+=1
print(a)

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

for i in range(n-1):
  for j in range(i+1, n):
    in_root = 0.0
    for k in range(d):
      in_root += (x[i][k]-x[j][k])**2
      ans = math.sqrt(in_root)
    if ans.is_integer():
      count += 1
        
print(count)