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 = [list(map(int,input().split())) for i in range(N)]
a = []
for l in range(N-1):
    for j in range(l+1,N):
        b = 0
        for k in range(D):
            b += (X[l][k]- X[j][k])**2
        a.append(math.sqrt(b))
c = 0
for m in range(len(a)):
    if len(str(a[m])) <=5:
        c += 1
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#B
import math
N, D = map(int, input().split())
Xs = []
for i in range(N):
    Xs.append(list(map(int, input().split())))
result = 0
for i in range(N-1):
    for j in range(i+1,N):
        dlength = 0
        for k in range(D):
            dlength += (Xs[i][k]-Xs[j][k])**2
        tlength = math.sqrt(dlength)
        if tlength.is_integer():
            result +=1
print(result)

Submission status: Accepted

Solution code:
import math

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

total = 0
for i in range(N):
	for j in range(N):
		if i == j or i < j:
			continue

		distance = math.sqrt(sum([(y - z)**2 for y, z in zip(X[i], X[j])]))
		if distance.is_integer():
			total += 1

print(total)

Submission status: Accepted

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

Submission status: Accepted

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

import itertools,math
cnt = 0
for i,j in itertools.combinations(range(n),2):
    distance = 0
    for y,z in zip(x[i],x[j]):
        distance += (abs(y-z))**2
    distance = math.sqrt(distance)
    if distance.is_integer():
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
# import atexit
# import io
# import sys
#
# _INPUT_LINES = sys.stdin.read().splitlines()
# input = iter(_INPUT_LINES).__next__
# _OUTPUT_BUFFER = io.StringIO()
# sys.stdout = _OUTPUT_BUFFER
#
#
# @atexit.register
# def write():
#     sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

import math
R = lambda : map(int,input().split())
import math

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


def dist(y, z):
    return math.sqrt(sum([(y[i] - z[i]) * (y[i] - z[i]) for i in range(D)]))


count = 0
for i in range(N):
    for j in range(i + 1, N):
        d = dist(Xs[i], Xs[j])
        if int(d) == d:
            count += 1

print(count)

Submission status: Accepted

Solution code:
import math

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

def dist(y, z):
    return math.sqrt(sum([(y[i] - z[i]) * (y[i] - z[i]) for i in range(D)]))

count = 0
for i in range(N):
    for j in range(i+1, N):
        d = dist(Xs[i], Xs[j])
        if int(d) == d:
            count += 1

print(count)

Submission status: Accepted

Solution code:
import numpy as np
N,D= map(int, input().split())
#2次元配列
X=[[int(j) for j in input().split()] for i in range(N)]
d=0
ans=0
for i in range(0,N-1):
    for j in range(i+1,N):
        for k in range(0,D):
            d=d+(X[i][k]-X[j][k])**2
        if d==(int(np.sqrt(d)))**2:
            ans=ans+1
        d=0
print(ans)

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()))
count=0
for i in range(N):
  for j in range(i,N):
    dis=0
    for k in range(D):
      dis += pow(X[i][k]-X[j][k],2) 
    dis = math.sqrt(dis)

    if dis==int(dis) and dis!=0:
      count+=1
print(count)

Submission status: Accepted

Solution code:
from itertools import combinations


def is_square(n):
    k = 1
    while k ** 2 < n:
        k += 1
    return k ** 2 == n


def main():
    n, d = map(int, input().split())
    xxs = [list(map(int, input().split())) for _ in range(n)]
    res = 0
    for (ys, zs) in combinations(xxs, 2):
        dist2 = sum((y - z) ** 2 for (y, z) in zip(ys, zs))
        if is_square(dist2):
            res += 1
    print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

cnt = 0
for i in itertools.combinations(x, 2):
    y = i[0]
    z = i[1]
    res = 0
    for j in range(d):
        res +=(y[j]-z[j])**2

    res = math.sqrt(res)
    if res.is_integer():
        cnt+=1

print (cnt)

Submission status: Accepted

Solution code:
import math
N, D = map(int,input().split())
X = [[int(i) for i in input().split()] for _ in range(N)]
 
ans = 0
for i in range(N):
    for j in range(i+1, N):
        yz = [(y - z)**2 for y, z in zip(X[i], X[j])]
        v = math.sqrt(sum(yz))
        if v == int(v):
            ans += 1
            
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
from itertools import combinations
 
N, D = map(int, input().split())
X = np.array([list(map(int, input().split())) for i in range(N)]) #二次元配列
cnt = 0
 
for p1, p2 in combinations(X, 2): #Xから二個選ぶ組み合わせ
    cnt+= (sum((p1-p2)**2)**.5).is_integer() #.is_integer()　整数かを判定
print(cnt)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import itertools
import math

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

X = [[0 for x in range(D)] for y in range(N)]

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

ans = 0
for target in itertools.combinations(X, 2):
    res = sum([abs(y - z) ** 2 for y, z in zip(target[0], target[1])])

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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import itertools
import math

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

X = [[0 for x in range(D)] for y in range(N)]

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

count = 0
for target in itertools.combinations(X, 2):
    y = target[0]
    z = target[1]
    res = 0
    for i in range(D):
        res += (y[i] - z[i])**2

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

print(count)

Submission status: Accepted

Solution code:
import math
N, D = [int(i) for i in input().split()]
X = [[int(i) for i in input().split()] for _ in range(N)]
 
ans = 0
for i in range(N):
    for j in range(i+1, N):
        yz = [abs((y - z)**2) for y, z in zip(X[i], X[j])]
        v = math.sqrt(sum(yz))
        if v == int(v):
            ans += 1
            
print(ans)

Submission status: Accepted

Solution code:
import math
n,d=map(int, input().split())
x=[[0 for _ in range(d)] for _ in range(n)]
for j in range(n):
    x[j]=list(map(int, input().split()))
count=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)==int(math.sqrt(dis)):
      count+=1
print(count)

Submission status: Accepted

Solution code:
from itertools import combinations
import math


def solve():
    n, d = map(int, input().split())
    x = list(list(map(int, input().split())) for _ in range(n))
    c = 0
    for p1, p2 in combinations(x, 2):
        d = 0
        for i in range(len(p1)):
            d += abs(p1[i] - p2[i]) ** 2
        d = math.sqrt(d)
        if d.is_integer():
            c += 1
    return c


if __name__ == "__main__":
    print(solve())

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
cnt = 0
for x1 in range(n):
    for x2 in range(x1 + 1, n):
        di = 0
        for i in range(d):
            di += abs(x[x1][i] - x[x2][i]) ** 2
        if di ** 0.5 == int(di ** 0.5):
            cnt += 1
print(cnt)

Submission status: Accepted

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

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

k = 0
for i in range(N):
        for j in range(i+1,N,1):
                dd = 0
                for d in range(D):
                        dd += math.pow(x[i][d]-x[j][d], 2)
                if math.sqrt(dd).is_integer():
                        k += 1
print(k)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
"""
# 標準入力取得
## 文字列
     = sys.stdin.readline().rstrip()
     = list(sys.stdin.readline().rstrip())

## 数値
     = int(sys.stdin.readline())
     = map(int, sys.stdin.readline().split())
     = list(map(int, sys.stdin.readline().split()))
     = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
     N, D = map(int, sys.stdin.readline().split())
     L = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]  # 二次元配列入力　二次元マップみたいな入力のとき
     cnt = 0
     for i in range(N):
          l1 = L[i]
          for j in range(i + 1, N):
               l2 = L[j]
               tmp = 0.0
               for v1, v2 in zip(l1, l2):
                    tmp += (v1 - v2) ** 2
               root_tmp = math.sqrt(tmp)
               if root_tmp == int(root_tmp):
                    cnt += 1
     print(cnt)

Submission status: Accepted

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

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

cnt = 0

for i in range(N-1):
  for j in range(i+1,N):
    dist2 = 0
    for index in range(D):
      dist2 += (X[i][index] - X[j][index]) ** 2
    dist = math.sqrt(dist2)
    if dist == float(int(dist)):
      cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
from itertools import combinations

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

for p1, p2 in combinations(X, 2):
    cnt+= (sum((p1-p2)**2)**.5).is_integer()
print(cnt)

Submission status: Accepted

Solution code:
# B - Good Distance

import numpy as np
from itertools import combinations

N, D = map(int, input().split())
X = np.array([list(map(int, input().split())) for i in range(N)])
cnt = 0
# for p1, p2 in combinations(X, 2):
#     d = sum((p1-p2)**2)**.5
#     if d.is_integer():
#         cnt+= 1
for p1, p2 in combinations(X, 2):
    cnt+= (sum((p1-p2)**2)**.5).is_integer()
print(cnt)

Submission status: Accepted

Solution code:
# B - Good Distance

import numpy as np
from itertools import combinations

N, D = map(int, input().split())
X = np.array([list(map(int, input().split())) for i in range(N)])
cnt = 0
for p1, p2 in combinations(X, 2):
    d = sum((p1-p2)**2)**.5
    if d.is_integer():
        cnt+= 1
print(cnt)

Submission status: Accepted

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

distance = 0
dis_int = 0

for i in range(N):
	for l in range(i+1, N):
		distance=0
		for g in range(D):
			distance += (X[i][g]-X[l][g])**2
		distance = distance**0.5
		if distance%1==0:
			dis_int+=1

print(dis_int)

Submission status: Accepted

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

X = [[[] * x for x in range(D)] * y for y in range(N)]
for i in range(N):
  X[i] = list(map(int, input().split()))
Cnt = 0
for i in range(N):
  for j in range(i+1,N):
    Dst = 0.0
    for k in range(D):
#      print (i, j, k ,X[i][k], X[j][k])
      Dst += (X[i][k] - X[j][k]) ** 2
    Dst = math.sqrt(Dst)
#    print (Dst , " is ", Dst.is_integer)
    if Dst % 1 == 0:
      Cnt += 1
print (Cnt)

Submission status: Accepted

Solution code:
import math
n, d = map(int, input().split())
x = [[int(e) for e in input().split()] for _ in range(n)]
result = 0
for i in range(n - 1):
  for j in range(i + 1, n):
    t = math.sqrt(sum((x[i][k] - x[j][k]) * (x[i][k] - x[j][k]) for k in range(d)))
    if t == math.ceil(t):
      result += 1
print(result)

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
mat=[]
for d in range(N):
     mat.append([int(x) for x in input().split()])

import math
c=0
for i in range(len(mat)-1):
    for j in range(i+1,len(mat)):
        dist=math.sqrt(sum([(x-y)**2 for x,y in zip(mat[i],mat[j])]))
        if int(dist)==dist:
                c+=1
print(c)

Submission status: Accepted

Solution code:
import functools
import itertools
import math

N, D = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(N)]
comb = list(itertools.combinations(data, 2))
count = 0

for pair in comb:
    cols = list(zip(*pair))
    c_sum = 0
    for col in cols:
        c_sum += abs(functools.reduce(lambda x, y: x - y, col)) ** 2
    if math.sqrt(c_sum).is_integer():
        count += 1

print(count)

Submission status: Accepted

Solution code:
import numpy as np
li = list(map(int,input().split()))
N = li[0]
D = li[1]

a = []
for i in range(N):
    a.append(list(map(int,input().split())))
count = 0
for i in range(N):
    for j in range(i+1,N):
        d = np.linalg.norm(np.array(a[i])-np.array(a[j]))
        if d % 1 == 0:
            count += 1
print(count)

Submission status: Accepted

Solution code:
import math

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

a = []
cnt = 0

for i in range(n):
	a.append(list(map(int, input().split())))
	
	for j in range(i):
		check = 0
		
		for k in range(d):
			check += pow(abs(a[i][k] - a[j][k]), 2)
			
		if((math.sqrt(check)).is_integer()):
			cnt += 1
			
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
n, d = map(int, input().split())
a = [[int(i) for i in input().split()] for _ in range(n)]
a = np.array(a)
count = 0
for i in range(n-1):
    for j in range(i+1,n):
        if np.linalg.norm(a[i]-a[j],2).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)]
ans = 0
for i in range(n):
  for j in range(i+1,n):
    sq= 0
    for k in range(d):
      sq += (x[i][k]-x[j][k])**2
    if math.sqrt(sq).is_integer():
      ans += 1
print(ans)

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import itertools
import math

n, d = list(map(int, input().split()))
x_list = []

for _ in range(n):
    x_list.append(list(map(int, input().split())))

# 全探索でいける？
l = list(range(0, n))
c = itertools.combinations(l, 2)
integer_count = 0

for v in c:
    a_index = v[0]
    b_index = v[1]
    work_list = []
    for a, b in zip(x_list[a_index], x_list[b_index]):
        work_list.append((a - b) ** 2)
    length = math.sqrt(sum(work_list))

    if length.is_integer():
        integer_count += 1

print(integer_count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math


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


if __name__ == '__main__':
    main()

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-1):#xの何番目のリストが対象なのか
    main = x[i]
    for j in range(i+1,n):#その時に合計で何人の相手と距離を求めるか
        li = []
        for k in range(d):
            num = (abs(main[k]-x[j][k]))**2
            li.append(num)
            
        target = (sum(li))**(1/2)
        if target.is_integer():
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math

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

t = 0
for i in range(N):
  for j in range(N):
    if i >= j:
      continue
    else:
      lsti = data[i]
      lstj = data[j]
      dist = 0
      for k in range(D):
        ik = lsti[k]
        ij = lstj[k]
        dist += (ik - ij)**2
      dist = math.sqrt(dist)
      if int(dist) - dist == 0:
        t += 1
        
print(t)

Submission status: Accepted

Solution code:
import numpy as np
A = list(map(int,input().split()))
B = []
N = A[0]
D = A[1]
while len(B) < N:
    B.append(list(map(int,input().split())))
k,l = 0,1
count = 0
while k < N - 1:
    while l < N:
        dis = 0
        for _ in range(D):
            dis += (B[k][_] - B[l][_]) ** 2
        if int(np.sqrt(dis)) == np.sqrt(dis):
            count += 1
        l += 1
    k += 1
    l = k + 1
print(count)

Submission status: Accepted

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

count=0
for i in range(n-1):
    for j in range(i+1,n):
        a=place[i]
        b=place[j]
        distance=0
        for u in range(d):
            distance+=(a[u]-b[u])**2
        distance=distance**0.5
        
        if distance.is_integer():
            count+=1
        
        
print(count)

Submission status: Accepted

Solution code:
import numpy as np
import itertools
 
n, d = map(int, input().split())
a = [[int(i) for i in input().split()] for n in range(n)]
count = 0
 
for i in list(itertools.combinations(a, 2)):
  length = 0
  i = np.array(list(i))
  for j in np.array(i[0]-i[1]):
    length += j**2
  if np.sqrt(length).is_integer():
    count+=1
print(count)

Submission status: Accepted

Solution code:
import sys
import numpy as np
import itertools
input = sys.stdin.readline

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

for i in list(itertools.combinations(a, 2)):
  length = 0
  i = np.array(list(i))
  for j in np.array(i[0]-i[1]):
    length += j**2
  if np.sqrt(length).is_integer():
    count+=1
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
import itertools

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

cnt = 0
for i1, i2 in itertools.product(range(n), range(n)):
    if i1 == i2:
        continue
    x1 = np.array(x[i1])
    x2 = np.array(x[i2])
    d = sum(list(map(lambda x : x ** 2, list(x1 - x2)))) ** 0.5
    if d == int(d):
        cnt += 1

print(int(cnt / 2))

Submission status: Accepted

Solution code:
import math

#n = int(input())
n, d= [int(i) for i in input().split()]
table = [[int(i) for i in input().split()] for j in range(n)]
#table = [list(input()) for n in range(h)]
#list = [int(i) for i in input().split()]
#num = [int(i) for i in range(n)]
#s = [input() for i in range(n)]
#s = input()
#list = list(s)
#temp = [[0 for _ in range(13)] for _ in range(13)]

ans = 0

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

print(ans)

Submission status: Accepted

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

print(b)

Submission status: Accepted

Solution code:
import math

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

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

print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations as comb
from math import sqrt
n, d = map(int, input().split())
dn = []
for i in range(n):
    dn.append(list(map(int, input().split())))

comb_list = list(comb([i for i in range(n)], 2))
ans = 0
for comb in comb_list:
    y_point = dn[comb[0]]
    z_point = dn[comb[1]]
    sum = 0

    for i in range(len(y_point)):
        sum += (y_point[i] - z_point[i])**2

    if sqrt(sum).is_integer():
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math
n, d = map(int, input().split())
x = []
ans=0
for i in range(n):
        o = list(map(int, input().split()))
        x += [o]
for i in range(n):
        for j in range(i+1,n):
                dis_net = 0
                dis=0
                for u in range(d):
                        dis += (x[i][u] - x[j][u])** 2
                dis_net = math.sqrt(dis)
                if dis_net % 1 == 0 and dis_net>=1:
                        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import numpy as np
def input():
    return sys.stdin.readline().rstrip()
def dist(y, z, d):
    ret = 0.0
    for i in range(d):
        ret += pow(y[i] - z[i], 2)
    return pow(ret, 0.5)
def main():
    n, d = [int(e) for e in input().split()]
    x = [[int(e) for e in input().split()] for _ in range(n)]
    ans = 0
    for i in range(n):
        for j in range(i + 1, n):
            dist_yz = dist(x[i], x[j], d)
            if math.ceil(dist_yz) == math.floor(dist_yz):
                ans += 1
    print(ans)
main()

Submission status: Accepted

Solution code:
import math
n, d = map(int, input().split())
x = []
ans=0
for i in range(n):
        o = list(map(int, input().split()))
        x += [o]
for i in range(n):
        for j in range(i+1,n):
                dis_net = 0
                dis=0
                for u in range(d):
                        dis += (x[i][u] - x[j][u])** 2
                dis_net = math.sqrt(dis)
                if dis_net % 1 == 0 and dis_net>=1:
                        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)]
count = 0
for i in range(N-1):
    i_point = X[i]
    for j in range(i+1,N):
        j_point = X[j]
        sum = 0
        for k in range(D):
            sum += (i_point[k]-j_point[k])**2
        if math.sqrt(sum).is_integer() :
            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)]
An = 0

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

Submission status: Accepted

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

answer = 0
for i in range(N):
    for j in range(N-i-1):
        j = N - j - 1
        B = 0
        A = []
        S = K[j]
        T = K[i]
        for l in range(D):
            A.append(S[l]-T[l])
        for k in range(D):
            B += (A[k])**2
        C = np.sqrt(B)
        CC = np.floor(C)
        if C == CC:
            answer += 1
        
print(answer)

Submission status: Accepted

Solution code:
import math

def is_good_distance(i, j):
    sum = 0

    for k in range(d):
        sum += (points[i][k] - points[j][k]) * (points[i][k] - points[j][k])

    return math.sqrt(sum).is_integer()




n, d = [int(i) for i in input().split()]

points = []

for i in range(n):
    points.append([int(j) for j in input().split()])

count = 0

for i in range(n):
    for j in range(i+1, n):
        if(is_good_distance(i, j)):
            count += 1

print(count)

Submission status: Accepted

Solution code:
from math import sqrt


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


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

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

print(count)

Submission status: Accepted

Solution code:

import math

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

res = 0
for i in range(0, n):
    for j in range(i + 1, n):
        d = 0
        for k in range(D):
            d += (ps[i][k] - ps[j][k]) * (ps[i][k] - ps[j][k])
        s = int(round(math.sqrt(d)))
        if s * s == d:
            res += 1
print(res)

Submission status: Accepted

Solution code:
#B
n,d = list(map(int, input().split(' ')))
x = [list(map(int,input().split(' '))) for i in range(n)]
count = 0
for i in range(n-1):
    for p in range(i+1,n):
        a = 0
        for s in range(d):
            a += (x[i][s]-x[p][s])**2
        a = a**(1/2)
        if a.is_integer() == True:
            count += 1
print(count)

Submission status: Accepted

Solution code:
import itertools

n, d = map(int, input().split())
x = [input().split() for x in range(n)]
l = list(itertools.combinations(x, 2))

ans = 0
for i in l:
    tmp = 0
    for j in range(d):
        tmp += (int(i[0][j]) - int(i[1][j])) ** 2
    if (tmp ** 0.5).is_integer():
        ans += 1


print(ans)

Submission status: Accepted

Solution code:
#ライブラリのインクルード
import math
#点間距離計算変数
S = 0
#整数カウンタの設定
C = 0
#事前情報を取得
n = input().split()
#D次元空間上にN個の点が存在
N = int(n[0])
D = int(n[1])
#座標データ格納
X = []
for k in range(N):
  X.append(input().split())
#点間距離計算
for N1 in range(N):
  for N2 in range(N):
    if N1 < N2:
      for i in range(D):
        S = S + (int(X[N1][i]) - int(X[N2][i])) ** 2
      S = math.sqrt(S)
      #整数判定(decimal：小数部分,integer:整数部分)
      decimal, integer = math.modf(S)
      if decimal == 0:
        C = C + 1
      S = 0
print(C)

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