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 = []
for i in range(n):
    a = list(map(int, input().split()))
    x.append(a)

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    import numpy as np
    n,d=map(int, input().split())
    l=[list(map(int,input().split())) for i in range(n)]
    cnt=0
    for j in range(n-1):
        for k in range(j+1,n):
            a=np.array(l[j])-np.array(l[k])
            if (np.linalg.norm(a))%1==0:
                cnt+=1
    print(cnt)
resolve()

Submission status: Accepted

Solution code:
n,d = map(int,input().split())
arr = [list(map(int,input().split())) for i in range(n)]
from math import sqrt
count = 0
from itertools import combinations
for kumi in combinations(range(n),2):
    inroot = 0
    for i in range(d):
        inroot += (arr[kumi[0]][i]-arr[kumi[1]][i])**2
    if sqrt(inroot)%1==0:
        count += 1

print(count)

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

Submission status: Accepted

Solution code:
import math

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

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

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        ins = 0
        for k in range(D):
            ins += (l[i][k] - l[j][k]) ** 2
        #print(ins, math.sqrt(ins))
        if math.sqrt(ins) == int(math.sqrt(ins)):
            ans += 1
            #print("now")

print(ans)

Submission status: Accepted

Solution code:
import itertools

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

cnt = 0
for c in list(itertools.combinations(range(n), 2)):
    total = 0
    for i in range(d):
        total += (abs(x[c[0]][i] - x[c[1]][i])) ** 2
    ans = total ** 0.5
    if ans == int(ans):
       cnt += 1
print(cnt)

Submission status: Accepted

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

for v in itertools.combinations(X, 2):
  s = 0
  for i in range(d):
    s += (v[0][i] - v[1][i]) ** 2
  if math.sqrt(s).is_integer():
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
n,d = map(int, input().split())
arr = []
for i in range(n):
  arr.append(list(map(int, input().split())))
res = 0
for i in range(n-1):
  for j in range(i+1,n):
    dist = 0
    for k in range(d):
      dist += (arr[i][k] - arr[j][k])**2
    if dist == float(int(pow(dist,1/2))**2):
      res += 1
print(res)

Submission status: Accepted

Solution code:
import math

N, D = map(int, input().split())
Ps = []
count = 0

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

def dis2(A, B):
  dis = 0
  for i in range(D):
    dis += (A[i] - B[i])**2
  return dis

for i in range(N-1):
  for j in range(i+1, N):
    if math.sqrt(dis2(Ps[i], Ps[j])).is_integer():
      count += 1

print(count)

Submission status: Accepted

Solution code:
def dist(a, b):
    v = 0
    for d in range(D):
        v += (a[d]-b[d])**2
    v = v ** 0.5
    return v


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):
        if dist(X[i], X[j]).is_integer():
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import sys
import math

n,d=map(int,input().split())
X=[]
for i in range(n):
    X.append(list(map(int,input().split())))
ans=0
X=np.array(X)
for i in range(n-1):
    for j in range(i+1,n):
        temp=0
        for k in range(d):
            temp+=(X[i][k]-X[j][k])**2
        if math.sqrt(temp)%1==0:
            ans+=1

print(ans)

Submission status: Accepted

Solution code:
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(n):
        dis2 = 0
        for k in range(d):
            dis2 += (x[i][k]-x[j][k])**2
        dis = float((dis2)**0.5)
        if dis.is_integer() == True:
            count += 1
print(int((count-n)/2))

Submission status: Accepted

Solution code:
import math
def main():
    N, D = map(int, input().split())
    pt = []
    for _ in range(N):
        p = list(map(int, input().split()))
        pt.append(p)

    ans = 0
    for i in range(N):
        for j in range(i):
            l = 0
            for k in range(D):
                l += pow(pt[i][k]-pt[j][k], 2)
            l = math.sqrt(l)
            if l == int(l): ans += 1
    return ans

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

Submission status: Accepted

Solution code:
import numpy as np
N, D = map(int, input().split())
x = []
for i in range(N):
  x.append(list(map(int, input().split())))
x = np.array(x)
ans = 0
for i in range(N-1):
  for j in range(i+1,N):
    tmp = sum((x[i]-x[j])**2)
    for k in range(1,tmp+1):
      if tmp == k**2:
        ans += 1
        break
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
import fractions
import copy
import bisect
import math
import numpy as np
#import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
from operator import itemgetter
from sys import stdin
#input = sys.stdin.readline#こっちの方が入力が早いが使える時に使っていこう
from operator import mul
from functools import reduce
from collections import Counter
#from collections import deque

#input = stdin.readline


N=3
M=3
i=0
j=0
k=0
sum=0
r=1
a=[0]*5
b=[]
#n=int(input())
#r=int(input())
#print(M)
#A=int(input())
#B=int(input())
#print(N)
"1行1つの整数を入力を取得し、整数と取得する"

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

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

for i in itertools.combinations(brray, 2):
    #print(i[0][0])
    #print(i)
    for j in range(D):
        sum=((abs(i[0][j]-i[1][j]))**2)+sum

    judge=np.sqrt(sum)
    #print(judge.is_integer())
    #()を付けないとオブジェクトのままで
    #()を付けると処理できる値で出てくる
    #これなんでやっけ
    if judge.is_integer():#これでif以下の条件式がTrueかfalseか自動判定してくれる
        k=k+1
    sum=0
print(k)
#入力完了
#number_list=list(map(int, input().split(" ")))#数字の時
#print(number_list)
"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#メモ
for i in number_list:#こっちの方がrage使うより早いらしい
    print(number_list[i-1])#

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''
#array=[input().split()for i in range(N)]
#print(type(array[0][0]))
#print(array)
"正方行列にstr型の値を入力"
'''

#brray=[list(map(int, input().split(" ")))for i in range(N)]
#print(type(brray[0][0]))
#print(brray)
'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"
#以下に別解を記載
#N, M = [int(i) for i in input().split()]
'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''




#s=input()
#a=[int(i) for i in s]
#print(a[0])
#print([a])
#単数値．桁ごとに分割したい．入力と出力は以下の通り
#イメージとして1桁ごとにリストに値を入れているかんじ

'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()#str style 何個でもいけることが多い
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''


#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"


#a,b=map(int, input().split())  #int style 複数数値入力　「A B」みたいなスペース空いた入力のとき

#なんかうまく入力されるけど
#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)
#複数行の数値を入力して正方行列を作成


##############################################################################################
##############################################################################################
#under this line explains example calculation


#nCr combination
'''
def cmb(n,r):
    #When n < r , this function isn't valid
    r= min(n-r,r)
    #print(n,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    #flochart mul(n,n-1)=x
    #next     mul(x,n-2)........(n-r+1,n-r)
    #mul read a,b and returns a*b

    under = reduce(mul, range(1, r+1))
    #print(over, under)
    #reduce is applied mul(1,2)=2
    #next   mul(2,3)=6
    #next   mul(6,4)=4.........last(r!,r+1)=r+1!

    return over // under
    #// is integer divide
    #calc example 5C2
    #over=5*4*3
    #under=3*2*1
a = cmb(n, r)
#print(a)
'''

'''
#集計
#example
#a=[2,2,2,3,4,3,1,2,1,3,1,2,1,2,2,1,2,1]
#a=Counter(a)
for i in a.most_common(n):print(i)
#most_common()メソッドは、出現回数が多い要素順にCounterオブジェクトを並び替えます。
#引数にint型の数字nを設定した場合は、出現回数が高い上位ｎ個の要素を返します。
#何も設定しなければ、コンテナ型にあるすべての要素を出現回数の順番に並び替えたタプル型オブジェクトを返します。
#out put
#(2, 8)
 #(1, 6)
#(3, 3)
#(4, 1)
'''


#二部探索(binary search)
#A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6]
#print(A)
#index = bisect.bisect_left(A, 5) # 7 最も左(前)の挿入箇所が返ってきている
#A.insert(index, 5)
#print(index)
#print(A)
'''
bisect.bisect_left(a, x, lo=0, h=len(a))
引数
a: ソート済みリスト
x: 挿入したい値
lo: 探索範囲の下限
hi: 探索範囲の上限
(lo, hiはスライスと同様の指定方法)
bisect_leftはソートされたリストaに対して順序を保ったままxを挿入できる箇所を探索します。leftが示す通り、aにすでにxが存在している場合は、挿入箇所は既存のxよりも左側になります。また、lo, hiを指定することで探索範囲を絞り込むことも可能です。デフォルトはaの全体が探索対象です。
'''





########################################################################
########################################################################
#b2=a[:]  #1次元のときはコピーはこれで良い
#print(b2)

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b3=copy.deepcopy(a)  #2次元配列はこうコピーする
#print(b3)

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)]
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
        
        if sqrt(dist) % 1 == 0:
            ans += 1
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import math
def main():
    N, D = map(int, input().split())
    X = [list(map(int, input().split())) for i in range(N)]
    DIST, CNT = 0, 0
    for i in range(N-1):
        for j in range(i+1,N):
            for d in range(D):
                DIST += abs(X[i][d] - X[j][d])**2
            if math.sqrt(DIST).is_integer():
                CNT +=1
            DIST = 0
    print(CNT)
    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

count=0
for j in range(0,n-1):
  for k in range(j+1,n):
    dist=0
    for l in range(0,d):
      dist+=(lis[j][l]-lis[k][l])**2
    if (dist**(1/2))%1==0:
      count+=1
print(count)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc133/tasks/abc133_b

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

matrix = []
for _ in range(n):
    row = [int(i) for i in input().split()]
    matrix.append(row)

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        s = matrix[i]
        t = matrix[j]
        dist = 0
        for k in range(d):
            dist += (s[k] - t[k]) ** 2
        
        temp = 1
        while temp ** 2 <= dist:
            if temp ** 2 == dist:
                ans += 1
                break
            else:
                temp += 1
print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc133/tasks/abc133_b

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

matrix = []
for _ in range(n):
    row = [int(i) for i in input().split()]
    matrix.append(row)

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        s = matrix[i]
        t = matrix[j]
        dist = 0
        for k in range(d):
            dist += (s[k] - t[k]) ** 2
        
        temp = 1
        while temp ** 2 <= dist:
            if temp ** 2 == dist:
                ans += 1
                break
            else:
                temp += 1
print(ans)

Submission status: Accepted

Solution code:

import numpy as np
n,d=map(int,input().split())
zahyo=[0]*n
count=0

# 入力受けて多次元アレイ作成
for i in range(n):
    zahyo[i]=list(map(int,input().split()))
arr=np.array(zahyo)

# 
for i in range(n):
    for j in range(i+1,n):
        dis=sum((arr[i]-arr[j])**2)
        if (dis**0.5).is_integer():
            count+=1
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def dist(x, y):
    d = 0.0
    for i in range(len(x)):
        d += (x[i] - y[i]) ** 2
    return d ** 0.5

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

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        d = dist(x[i], x[j])
        if abs(d - int(d)) < 1e-6:
            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)]
res=0
for i in range(n):
	for j in range(i+1,n):
		cnt = 0
		for k in range(d):
			cnt += (x[i][k]-x[j][k])**2
		if (cnt**0.5)==(cnt**0.5)//1:
			res += 1
print(res)

Submission status: Accepted

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

ans = 0
for i in range(N):
    for j in range(i+1, N):
        dist = 0
        for k in range(D):
            dist += (pts[i][k]-pts[j][k])**2
        if dist**0.5 == int(dist**0.5):
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
N,D=map(int, sys.stdin.readline().split())
X=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]

L=[]  #2乗した数  
for i in range(201):
    L.append(i**2)

ans=0
for i in range(N-1):
    for j in range(i+1,N):
        t=0
        for x1,x2 in zip(X[i],X[j]):
            t+=(x1-x2)**2
        if t in L:
            ans+=1
print ans

Submission status: Accepted

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


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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
l = list("")
for i in range(n):
    x = list(map(int, input().split()))
    l.append(x)
c = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        a = 0
        for k in range(d):
            a += (l[i][k] - l[j][k]) ** 2
        a = a ** 0.5
        if int(a) == a:
            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())))
sum = 0
count = 0
for j in range(N-1):
    for k in range(j+1, N):
        for x in range(D):
            sum += (X[j][x] - X[k][x])**2
        if (sum**0.5).is_integer():
            count += 1
        sum = 0
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
a=[list(map(int,input().split())) for j 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+=(a[i][k]-a[j][k])**2
    dis=dis**(0.5)
    if dis==int(dis):
      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):
    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 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):
        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
n,d = map(int,input().split())
a = [list(map(int,input().split())) for hoge in range(n)]
ans = -n
for b in a:
  for c in a:
    k = 0
    s = 0
    while k < d:
      s += (b[k]-c[k])**2
      k += 1
    poge = math.sqrt(s)
    if poge%1 == 0:
      ans += 1
print(ans//2)

Submission status: Accepted

Solution code:
import math

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

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

ans=0

for i in range (n-1):
    for j in range(i+1,n):
        sum=0.0

        #各次元についての距離を求める
        for k in range(d):
            sum+=math.pow(a[i][k]-a[j][k],2)
        
        sum=math.sqrt(sum)

        #実数を整数にしても数が変わらないなら整数
        if(sum==int(sum)):
            ans+=1

print(ans)

Submission status: Accepted

Solution code:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
# map(int, input().split())
# int(input())
# input().split()
# mojiretu = ','.join(str_list)
# sorted(input())

n, d = map(int, input().split())
x = []
for _ in range(n):
    x.append(list(map(int, input().split())))
cnt = 0
for i in range(n-1):
    for j in range(i+1, n):
        ans = 0.0
        for k in range(d):
            ans += (x[i][k] - x[j][k])**2
        if sqrt(ans).is_integer():
            cnt += 1
        #print(i, j, sqrt(ans), sqrt(ans).is_integer())
print(cnt)

Submission status: Accepted

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


def f(x, y):
    s = 0
    for i in range(len(x)):
        s += (x[i] - y[i])**2

    return math.sqrt(s)


count = 0
for i in range(len(L)):
    for j in range(i + 1, len(L)):
        fn = f(L[i], L[j])
        n = int(fn)
        if (n == fn):
            count += 1
        else:
            continue

print(count)

Submission status: Accepted

Solution code:
import numpy as np


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

Submission status: Accepted

Solution code:
import math
def main():
	n ,d = map(int,input().split())
	arr = [ ]
	for _ in range(n):
		arr.append(list(map(int,input().split())))
	ans = 0
	for i in range(n):
		for j in range(i+1,n):
			cnt  = 0	
			for k in range(d):
				cnt += (arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k])
			if math.sqrt(cnt)==int(math.sqrt(cnt)):
				ans+=1
	print(ans)
	return



main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n, d = map(int,input().split())
xs = []
for _ in range(n):
  x = list(map(int, input().split()))
  xs.append(x)
ans = 0
for i in range(n-1):
  xi = xs[i]
  for j in range(i+1, n):
    xj = xs[j]
    dist = 0
    for k in range(d):
      dist += (xi[k] - xj[k])**2
    dist = math.sqrt(dist)
    if dist - int(dist) == 0.0:
      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)]
cnt = 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
        distance = distance**0.5
        if distance == int(distance):

            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
# B - Good Distance

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

ans = 0

for i in range(n):
    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 itertools
import math
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
res = 0
for v in itertools.combinations(x, 2):
    dist = 0
    for i in range(d):
        dist += abs(v[0][i]-v[1][i])**2
    if math.sqrt(dist).is_integer():
        res += 1
print(res)

Submission status: Accepted

Solution code:
N,D = map(int,input().split())
L = []
for i in range(N):
    X = list(map(int,input().split()))
    L.append(X)
import itertools
C = list(itertools.combinations(L,2))
ans = 0
for i in range(len(C)):
    s = 0
    for j in range(D):
        s += (C[i][0][j]-C[i][1][j])**2
    s = s**0.5
    if s == int(s):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
ans=0
keep=[]
lis=[0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849, 1936, 2025, 2116, 2209, 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025, 3136, 3249, 3364, 3481, 3600, 3721, 3844, 3969, 4096, 4225, 4356, 4489, 4624, 4761, 4900, 5041, 5184, 5329, 5476, 5625, 5776, 5929, 6084, 6241, 6400, 6561, 6724, 6889, 7056, 7225, 7396, 7569, 7744, 7921, 8100, 8281, 8464, 8649, 8836, 9025, 9216, 9409, 9604, 9801, 10000, 10201, 10404, 10609, 10816, 11025, 11236, 11449, 11664, 11881, 12100, 12321, 12544, 12769, 12996, 13225, 13456, 13689, 13924, 14161, 14400, 14641, 14884, 15129, 15376, 15625, 15876, 16129]
for i in range(N):
  s=list(map(int,input().split()))
  keep.append(s)
for j in range(0,N):
  for k in range(j+1,N):
    num=0
    for l in range(D):
      num+=abs(keep[j][l]-keep[k][l])**2
    if num in lis:
      ans+=1
print(ans)

Submission status: Accepted

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

all_pattern = list(itertools.combinations(a,2))
ans = 0
for i in range((n*(n-1)) // 2):
    x1 = x[all_pattern[i][0]]
    x2 = x[all_pattern[i][1]]
    distance = 0
    for j in range(d):
        distance += ((x1[j] - x2[j]) ** 2)
    if math.sqrt(distance) == int(math.sqrt(distance)):
        ans += 1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
n,d = map(int,input().split())
x = []
while True:
  try:
    tmp = list(map(int,input().split()))
    x.append(tmp)
    
  except:
    break
    
ans = 0
for i in range(n):
  for j in range(i+1,n):
    t = 0
    for k in range(d):
      t += (x[i][k]-x[j][k])**2
    if int(math.sqrt(t))==math.sqrt(t):
      ans +=1
print(ans)

Submission status: Accepted

Solution code:
'''自分はこれをもう一回といた時にこのコードを見てあまり考えすぎずに
何をしているのがわかるのか教えて欲しいもしあまりにも考えてしまうなら
コメントを書いといてあげたほうがいいかもねこれからはなしでも何をしてどうやって解いているのか
関数とかを調べれば思い出せるならコメント書く時間は無駄かもね'''


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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

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

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        tmp = 0
        for k in range(D):
            tmp += (X[i][k] - X[j][k]) ** 2
        if np.sqrt(tmp) % 1 == 0:
            ans += 1
            
print(ans)

Submission status: Accepted

Solution code:
N,D = map(int,input().split())
X = [input().split() for x in range(N)]
ans = 0
d = 0
distance = []
for i in range(N):
  for j in range(i,N):
    if d != 0:
      distance.append(d ** (1/2))
    d = 0
    for k in range(D):
      d += (int(X[i][k]) - int(X[j][k])) ** 2
for i in range(len(distance)):
  if distance[i] - int(distance[i]) == 0:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import math
n,d = map(int,input().split())
A =np.array([list(map(int,input().split())) for _ in range(n)])
ans =0
for i in range(n):
    for j in range(i+1,n):
        B = np.array(A[i] - A[j])
        if math.sqrt(sum(np.square(B))) == -1*(math.sqrt(sum(np.square(B))) //-1):
            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)]

import numpy as np    

ans = 0

for i in range(n-1):
    for j in range(i+1,n):
        x = np.array(X[i])
        y = np.array(X[j])
        z = sum(np.power((x - y), 2)) ** 0.5
        
        if z % 1 == 0:
            ans += 1
    
print(ans)

Submission status: Accepted

Solution code:
import math
n,d=map(int,input().split())
cnt=0
dlist=[list(map(int,input().split())) for _ in range(n)]
for i in range(n-1):
    for j in range(i+1,n):
        ans=0
        for k in range(d):
            ans+=(dlist[i][k]-dlist[j][k])**2
        cnt+=math.floor(ans**0.5)==math.ceil(ans**0.5)

print(cnt)

Submission status: Accepted

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

temp_list = []
for _ in range(n):
    x_list = [int(x) for x in input().split()]
    temp_list.append(x_list)

ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        dist = sum([(y - z) ** 2 for y, z in zip(temp_list[i], temp_list[j])]) ** 0.5
        if int(dist) == dist:
            ans += 1
print(ans)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:

from itertools import combinations

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

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

for a,b in combinations(X,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:
import math
N, D = map(int, input().split())
x = []
for i in range(N):
  t = list(map(int, input().split()))
  x.append(t)

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