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:
# abc133_b.py
# https://atcoder.jp/contests/abc133/tasks/abc133_b

# B - Good Distance /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# D次元空間上に N個の点があります。
# i番目の点の座標は (Xi1,Xi2,...,XiD)です。
# 座標 (y1,y2,...,yD)の点と座標 (z1,z2,...,zD) の点の距離は √(y1−z1)2+(y2−z2)2+...+(yD−zD)2です。
# i番目の点と j 番目の点の距離が整数となるような組 (i,j) (i<j)はいくつあるでしょうか。

# 制約
#     入力は全て整数である。
#     2≤N≤10
#     1≤D≤10
#     −20≤Xij≤20
#     同じ座標の点は与えられない。すなわち、i≠jならば Xik≠Xjk なる kが存在する。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N D
# X11 X12 ... X1D
# X21 X22 ... X2D
# ⋮
# XN1 XN2 ... XND

# 出力
# i番目の点と j 番目の点の距離が整数となるような組 (i,j) (i<j)の数を出力せよ。

# 入力例 1
# 3 2
# 1 2
# 5 5
# -2 8

# 出力例 1
# 1

# 以下のように距離が整数となる点の組は 1組です。
#     1番目の点と 2 番目の点の距離は √|1−5|2+|2−5|2=5で、これは整数です。
#     2番目の点と 3 番目の点の距離は √|5−(−2)|2+|5−8|2=√58で、これは整数ではありません。
#     3番目の点と 1 番目の点の距離は √|−2−1|2+|8−2|2=3√5で、これは整数ではありません。

# 入力例 2
# 3 4
# -3 7 8 2
# -12 1 10 2
# -2 8 9 3

# 出力例 2
# 2

# 入力例 3
# 5 1
# 1
# 2
# 3
# 4
# 5

# 出力例 3
# 10


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    # N = int(lines[0])
    N, D = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(6):
    #     values.append(int(lines[i]))
    valueses = list()
    for i in range(N):
        valueses.append(list(map(int, lines[i+1].split())))

    cnt = 0
    for n1 in range(N-1):
        for n2 in range(n1+1, N):
            log(f'n1=[{n1}], n2=[{n2}]')
            d = 0
            for dd in range(D):
                d += (valueses[n1][dd] - valueses[n2][dd])**2
            d = d**0.5
            if d == float(int(d)):
                cnt += 1

    return [cnt]


# 引数を取得
def get_input_lines():
    line = input()
    N, D = list(map(int, line.split()))
    lines = list()
    lines.append(line)
    for _ in range(N):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3 2', '1 2', '5 5', '-2 8']
        lines_export = [1]
    if pattern == 2:
        lines_input = ['3 4', '-3 7 8 2', '-12 1 10 2', '-2 8 9 3']
        lines_export = [2]
    if pattern == 3:
        lines_input = ['5 1', '1', '2', '3', '4', '5']
        lines_export = [10]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines()
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
def main():
  n,d = list(map(int,input().split()))
  x = [input().split() for l in range(n)]
  ans=0
  for i in range(0,n):
    for j in range(i+1,n):
      dist=0
      for k in range(0,d):
        dist+=abs(int(x[j][k])-int(x[i][k]))*abs(int(x[j][k])-int(x[i][k]))
      if math.sqrt(dist)%1==0:
        ans+=1
  print(ans)
main()

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
ans=0
A=[]
for x in range(N):
  X=list(map(int,input().split()))
  for y in range(len(A)):
    s=0
    for z in range(D):
      s+=(A[y][z]-X[z])**2
    if ((s**(1/2))*10)%10==0:
      ans+=1
  A.append(X)
print(ans)

Submission status: Accepted

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

arr = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N):
    for j in range(i+1, N, 1):
        kyori = 0
        for k in range(D):
            kyori += (arr[i][k]-arr[j][k])**2
        if math.sqrt(kyori) == int(math.sqrt(kyori)):
            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)]

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

        if d.is_integer():
            ans += 1

print(ans)

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)])
print(sum(1 for i in range(N) for j in range(i+1,N) if np.linalg.norm(X[i]-X[j]).is_integer()))

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

Submission status: Accepted

Solution code:
import numpy as np

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

Submission status: Accepted

Solution code:
import math
n, d = map(int, input().split())
a = []
ans = 0
x = 0
if d ==1:
  for i in range(n):
    a.append(int(input()))
  for i in range(n):
    for j in range(i,n):
      if math.sqrt((a[i]-a[j])**2)%1==0 and math.sqrt((a[i]-a[j])**2)!=0:
        ans += 1
else:
  for i in range(n):
    a.append(list(map(int, input().split())))
  for i in range(n):
    for j in range(i, n):
      x = 0
      for k in range(d):
        x += (a[i][k] - a[j][k]) **2
      if math.sqrt(x)%1 == 0 and math.sqrt(x) != 0:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
#55
import math
N,D = map(int,input().split())
x = []
dis = []
cnt = 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): 
        num = 0
        for m in range(D):
            num += (x[i][m]-x[j][m])*(x[i][m]-x[j][m])
        dis.append(num)
        
for i in dis:
    if int(math.sqrt(i)) == math.sqrt(i):
        cnt += 1
        
print(cnt)

Submission status: Accepted

Solution code:
from itertools import combinations
import math


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

xn = []
for i in range(n):
  x = [int(num) for num in input().split()]
  xn.append(x)
  
answer =  0
for i,j in combinations(range(n),2):
    sum = 0.0
    for k in range(d):
        sum += (xn[i][k]-xn[j][k])**2
    if math.sqrt(sum).is_integer():
        answer += 1
 
print(answer)

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
res = 0
List = []
for i in range (N):
  List.append(list(map(int, input().split())))
  
def calcDist(ListX,a,b):
  n = 0
  for k in range(D):
    x = ListX[a][k] - ListX[b][k]
    n += x*x
  n = n ** 0.5
  nn = int(n)
  if n-nn > 0:
    return False
  else:
    return True

for i in range(N):
  for j in range(N):
    if i == j:
      pass
    else:
      if calcDist(List,i,j):
        res += 1
res = res //2
print(res)

Submission status: Accepted

Solution code:
from itertools import combinations
from math import sqrt

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

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

l = len(X)
cnt = 0

for i in range(l):
    for j in range(i+1, l):
        distance = sum((X[i][d]-X[j][d])**2 for d in range(d))**0.5
        if distance == int(distance):
            cnt += 1
        else:
            continue
            
print(cnt)

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

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        d = sum(abs(a[i][k] - a[j][k]) ** 2 for k in range(D)) ** 0.5
        cnt += d % 1 == 0
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
import math
n,d = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(n)]
count_true = 0
for i in range(n):
  for j in range(i+1,n):
    a = 0
    for k in range(d):
      a += pow((x[i][k]-x[j][k]),2)
    a = math.sqrt(a)
    b = int(a)
    if a == b :
      count_true += 1
        
print(count_true)

Submission status: Accepted

Solution code:
import math

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

arr=[list(map(int,input().split())) for i in range(N)]
count=0

def dis(x,y):
    a=0
    for i in range(len(x)):
        a+=(x[i]-y[i])*(x[i]-y[i])
    return math.sqrt(a)
    
for i in range(N-1):
    for j in range(i+1,N):
        if dis(arr[i],arr[j])%1==0:
            count+=1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
import math

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

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

def dist(a,b):
    cnt = 0
    for i in range(len(a)):
        cnt += (a[i]-b[i])**2
    return math.sqrt(cnt)

ans = 0
    
for i in range(n):
    for j in range(i+1,n):
        if dist(l[i],l[j])%1 == 0:
            ans+=1
print(ans)

Submission status: Accepted

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

for i in x:
    for j in x:
        ans = 0
        for k in range(b):
            ans += abs(i[k]-j[k])**2
        q = math.sqrt(ans)
        if q.is_integer() == True:
            c += 1
d = (c-a)//2
print(d)

Submission status: Accepted

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

import sys
from math import sqrt
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

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


def check_bi(Y, Z):
    sum_ = 0
    for y, z in zip(Y, Z):
       sum_ += (y-z)**2

    for i in range(int(sqrt(sum_))+1):
        if i * i == sum_:
            return True
    return False


count = 0
for i, x in enumerate(X[:len(X)-1]):
    for y in X[i+1:]:
        count += check_bi(x, y)

print(count)

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
X=[list(map(int,input().split())) for i in range(N)]
l=len(X)
c=0
for i in range(l):
 for j in range(i+1,l):
  t=sum((X[i][d]-X[j][d])**2for d in range(D))**0.5
  c+=t==int(t)
print(c)

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
X=[list(map(int,input().split())) for i in range(N)]
l=len(X)
cnt=0
for i in range(l):
 for j in range(i+1,l):
  t=sum((X[i][d]-X[j][d])**2for d in range(D))**0.5
  cnt+=t==int(t)
print(cnt)

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
X=[list(map(int,input().split())) for i in range(N)]
l=len(X)
cnt=0
for i in range(l):
 for j in range(i+1,l):
  t=sum((X[i][d]-X[j][d])**2for d in range(D))**0.5
  if t==int(t):cnt+=1
print(cnt)

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

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):
  for j in range(i+1, N):
    c += (sum((X[i][p]-X[j][p])**2 for p in range(D))**.5).is_integer()
print(c)

Submission status: Accepted

Solution code:
import sys
import itertools
N,D = map(int,input().split())
array = [ list(map(int,input().split())) for x in range(N) ]

if not ( 2 <= N <= 10 and 1 <= D <= 10 ): sys.exit()
for I in array:
    if not ( -20 <= min(I) and max(I) <= 20 ): sys.exit()

count = 0
for I in list(itertools.combinations(array,2)):
    tmp_distance = 0
    for J in range(D):
        tmp_distance += abs(I[0][J] - I[1][J]) ** 2
    distance = tmp_distance ** 0.5 
    if distance.is_integer(): 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)]
c = 0
for i in range(n):
    for j in range(n):
        x = 0
        for k in range(d):
            x += (l[i][k] - l[j][k])**2
        y = math.sqrt(x)
        if y != 0 and y.is_integer():
            c += 1
print(c//2)

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
coordinates = []
c_append = coordinates.append
count = 0

for _ in range(N):
    X = list(map(int, input().split()))
    c_append(X)

for i in range(N-1):
    for j in range(i+1, N):
        distance = 0
        tmp1 = coordinates[i]
        tmp2 = coordinates[j]
        for k in range(D):
            distance += (tmp1[k] - tmp2[k]) ** 2
        distance = distance ** (1/2)
        if distance == int(distance):
            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)]
num = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        A, B = X[i], X[j]
        d = math.sqrt(sum([(A[k] - B[k]) ** 2 for k in range(D)]))
        if abs(d - int(d)) < 10 ** (-4):
            num += 1
print(num)

Submission status: Accepted

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

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

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

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

count = 0

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

print(count // 2)

Submission status: Accepted

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

points = []

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

def distance(a, b):
    dist = 0

    for a, b in zip(a, b):
        dist += (a - b) ** 2

    if dist == 0:
        return False

    return int(dist ** 0.5) ** 2 == dist

count = 0

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

print(count // 2)

Submission status: Accepted

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

Submission status: Accepted

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

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

def isSquare(x):
  f = 1
  while f * f <= x:
    if f * f == x:
      return True
    else:
      f += 1
  return False
  
def calcSquareOfDistance(p1,p2,dimension):
  s = 0
  for i in range(dimension):
    s += (p1[i] - p2[i])**2
  return s

def judge(p1,p2,dimension):
  return isSquare(calcSquareOfDistance(p1,p2,dimension))

ans = 0
for i in range(N-1):
  for j in range(i+1,N):
    if judge(a[i],a[j],D):
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools
import numpy as np

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

ans = 0
for d_list in list(itertools.combinations(Dist, 2)):
  x = np.array(d_list[0])
  y = np.array(d_list[1])
  tmp = 0
  for i in (x-y):
    tmp += i*i
  k = tmp**0.5
  if k == int(k):
    ans += 1

print(ans)

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

Submission status: Accepted

Solution code:
n,d = map(int,input().split())
dots = []
ans = 0
for _ in range(n):
  t = list(map(int,input().split()))
  if len(dots)!=0:
    for l in dots:
      a = [(y-z)**2 for y,z in zip(t,l)]
      if ((sum(a))**.5).is_integer():
        ans += 1
  dots.append(t)
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

def distance(list1, list2) :
    dist = 0
    for i in range(len(list1)) :
        dist += (list1[i] - list2[i]) ** 2
    return math.sqrt(dist)

for i in range(n) :
    for j in range(i+1,n) :
        if i != j :
            if int(distance(x[i], x[j])) == distance(x[i], x[j]) :
                cnt += 1
print(cnt)

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

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):
    for j in range(i+1, n):
        count = 0
        for y in range(d):
            count += abs(x[i][y]-x[j][y])**2

        if (count**0.5) % 1 == 0:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
n, d = list(map(int, input().split()))
# A = list(map(int, input().split()))
#a = list(map(int, input().split()))
# data = [list(map(int, input().split())) for i in range(n)]
# q = int(input())
#a = list(map(int, input().split()))
# b = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
x = [list(map(int, input().split())) for i in range(n)]
# print(min(15*n, 100*(n//10+1), 100*(n//10)+15*(n % 10)))
# for i in range(1, int(n**0.5)+1):

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
(n,d),*xx = [list(map(int, s.split())) for s in open(0)]

from itertools import combinations

ans = 0
for i, j in combinations(range(n),2):
    s = sum((a-b)**2 for a,b in zip(xx[i],xx[j]))
    if s == round(s**0.5)**2:
        ans += 1

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

def main():
    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):
            v = sum((y - z) ** 2 for y, z in zip(X[i], X[j]))
            dist = round(math.sqrt(v))
            if v == dist ** 2:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n,d =map(int,input().split())
    X = []
    for i in range(n):
        tmp = [int(i) for i in input().split()]
        X.append(tmp)
    ans = 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
            s = s**0.5
            #print(s)
            if s.is_integer():
                ans += 1
    print(ans)
main()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations
N, D = map(int, input().split())
X = [tuple(map(int, input().split())) for _ in range(N)]
res = 0
for i, j in combinations(list(range(N)), 2):
    tmp = sum((y - z) ** 2 for y, z in zip(X[i], X[j]))
    tmp **= 0.5
    if tmp == int(tmp):
        res += 1
print(res)

Submission status: Accepted

Solution code:
# 8m AC
import math
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


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

Submission status: Accepted

Solution code:
# 32
import math
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


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

Submission status: Accepted

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def calcTwoPointDistance(x1, y1, x2, y2):
    return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, D = il()
    XY = [il() for _ in range(N)]

    ret = 0
    for x, y in itertools.combinations(XY, 2):
        tmp = 0
        for d in zip(x, y):
            tmp += abs(d[0] - d[1])**2

        if (tmp ** 0.5).is_integer():
            ret += 1
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import combinations
import math
n,d=map(int,input().split())
X=[list(map(int,input().split())) for _ in range(n)]
cnt=0
for perm in list(combinations(range(n),2)):
    d=sum(map(lambda x: (x[0]-x[1])**2,zip(X[perm[0]],X[perm[1]])))
    if d==int(math.sqrt(d))**2:
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
from itertools import combinations
import math
N, D = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
for perm in list(combinations(range(N), 2)):
    d = sum(map(lambda x: (x[0] - x[1]) ** 2, zip(X[perm[0]], X[perm[1]])))
    if d == int(math.sqrt(d)) ** 2:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import math
N,M=list(map(int,input().split()))
all=[list(map(int,input().split())) for k in range(N)]
cnt=0
for i in range(N-1):
  for t in range(i+1,N):
    ans=0
    for h in range(M):
      ans+=(all[i][h]-all[t][h])**2
    ans=math.sqrt(ans)
    if ans%1==0:
      cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

N, D = rl()
X = []
for i in range(N):
	X.append(rl())

def check(x, y):
	d = 0
	for i in range(D):
		d += (x[i]-y[i])**2
	d = d**0.5
	if d == int(d):
		return True
	return False

ans = 0
for i in range(N):
	for j in range(i+1, N):
		if check(X[i], X[j]):
			ans += 1
print(ans)

Submission status: Accepted

Solution code:

import math 

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

Submission status: Accepted

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

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

        flag = False
        for k in range(diff_total + 1):
            if (k * k) == diff_total:
                flag = True
        if flag:
            ans += 1
print(ans)

Submission status: Accepted

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

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