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:
n, d = map(int, input().split())
lst = []
for _ in range(n):
  x = list(map(int, input().split()))
  lst.append(x)
ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    dist = 0
    for k in range(d):
      dist += (lst[i][k] - lst[j][k])**2
    j = 1
    while j**2 <= dist:
      if j**2 == dist:
        ans += 1
        break
      j += 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)]

sq = set()
for i in range(1, 1000):
  sq.add(i**2)

def foo(x,y):
  t = 0
  for i, j in zip(X[x], X[y]):
    t += (i - j) * (i - j)
  if t in sq:
    return 1
  else:
    return 0
    
ans = 0

for i in range(N):
  for j in range(i+1, N):
    ans += foo(i, j)

print(ans)

Submission status: Accepted

Solution code:
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
import math
import itertools
input = sys.stdin.readline

N, D = map(int, input().split())
P = []
for i in range(N):
    P.append(list(map(int, input().split())))
ans = 0
for c in itertools.combinations(range(N), 2):
    i = c[0]
    j = c[1]
    dis = 0
    for k in range(D):
        dis += (P[j][k] - P[i][k])**2
    if math.sqrt(dis) == int(math.sqrt(dis)):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def euclid(y,z,d):
	result=0
	for i in range(d):
		result+=(y[i]-z[i])**2
	return math.sqrt(result)


n,d=input2()
X=[input_array() for _ in range(n)]

count=0
for i in range(n):
	for j in range(i+1,n):
		distance=euclid(X[i],X[j],d)
		if (distance%1) == 0:
			count+=1
print(count)

Submission status: Accepted

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

for i in range(n):
    for j in range(i+1,n):
        t = 0
        for k in range(d):
            t += abs(x[i][k] - x[j][k]) ** 2
        l.append(t)

l.sort()
i = 1
while i ** 2 <= l[-1]:
    o.append(i ** 2)
    i += 1

p = 0
for i in range(len(o)):
    p += l.count(o[i])

print(p)

Submission status: Accepted

Solution code:
import numpy as np

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

X = np.array(X)
for k in range(N):
    for l in range(k+1, N):
        Xd = X[k] - X[l]
        dis = np.linalg.norm(Xd, ord=2)

        if dis.is_integer():
            cnt += 1

print(cnt)

Submission status: Accepted

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

ans = 0
for i in range(len(x)):
    for j in range(i+1, len(x)):
        dist = sum((x-y)**2 for x, y in zip(x[i], x[j]))**0.5
        if dist.is_integer(): ans += 1

print(ans)

Submission status: Accepted

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

n, _ = rm()
li = np.array([np.array(rl()) for _ in range(n)])
cnt = 0
for i in range(n):
  for j in range(i):
    a = sum((li[i] - li[j]) ** 2)**0.5
    if a - a//1 == 0:
      cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n, _ = rm()
li = np.array([np.array(rl()) for _ in range(n)])
cnt = 0
for i in range(n):
  for j in range(i):
    a = sum((li[i] - li[j]) ** 2)**0.5
    if a - a//1 == 0:
      cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import math
N,D = map(int,input().split())
Xs = [list(map(int,input().split()))for i in range(N)]
c = 0
for i in range(N-1):
  X1 = Xs[i]
  for j in range(i+1,N):
    X2 = Xs[j]
    su = 0
    for k in range(D):
      su += abs(X1[k]-X2[k]) **2
    distance = math.sqrt(su)
    if distance.is_integer():
      c+=1
print(c)

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, D = LI()
    X = [LI() for _ in range(N)]

    MAX_DIST = 16000
    square_num = set()
    i = 1
    while i ** 2 <= MAX_DIST:
        square_num.add(i ** 2)
        i += 1

    ans = 0
    for i, j in itertools.combinations(range(N), 2):
        if sum([(k - l) ** 2 for k, l in zip(X[i], X[j])]) in square_num:
            ans += 1

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import numpy as np
import math
from collections import Counter

def cumsum(x):
    return list(np.cumsum(x))

def cumsum_number(N,K,x):
    ans=[0]*(N-K+1)
    number_cumsum = cumsum(x)
    number_cumsum.insert(0,0)
    for i in range(N-K+1):
        ans[i]=number_cumsum[i+K]-number_cumsum[i]
    return ans
"""
int #整数
float #小数

#リスト
list0 = [] #リスト生成
list0 = [1,2,3,4] #初期化
list0 = [0]*10 #[0,0,0,0,0,0,0,0,0,0]
list1= [i for i in range(10)] #>>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list1 = list(map(int, input().split()))　# 複数の入力をリストに入れる
number=[int(input()) for i in range(int(input()))] #複数行の入力をリストに
list1 = list1 + [6, 7, 8] #リストの追加
list2.append(34) #リストの追加　最後に（）内が足される
list.insert(3,10) #リストの追加　任意の位置（追加したい位置,追加したい値）
len(list4) #リストの要素数
max(sa) #list saの最小値
list5.count(2) #リスト(文字列も可）内の2の数
list1.sort() #並び替え小さい順
list1.sort(reverse=True)  #並び替え大きい順
set(list1) #list1内の重複している要素を削除し、小さい順に並べる
sum([2,3,   ,3]) #リストの合計

number=Counter(list) #listを値（文字）ごとにカウントし辞書型で返す [1:4,2:5 …]

abs(a) #aの絶対値
max(a,b) min(a,b) #最大値　最小値
text1 = text1.replace("34","test") #text1内の"34"を"test"に書き換える(文字列内の文字を入れ替える)
sorted(S) #Sを辞書順にソート
exit(0) #強制終了

cumsum(リスト) #累積和をリストで返す
cumsum_number(N,K,x) #N個の数が含まれるリストx内のK個からなる部分和をリストで返す

alphabet={0:"A",1:"B",2:"C",3:"D",4:"E",5:"F",6:"G",7:"H",8:"I",9:"J",
          10:"K",11:"L",12:"M",13:"N",14:"O",15:"P",16:"Q",17:"R",18:"S",19:"T",
          20:"U",21:"V",22:"W",23:"X",24:"Y",25:"Z",}
print(*S,sep="") #リストSを1つずつ出力

math.floor() #切り捨て
math.ceil() #切り上げ
"""
def dist(a,b):
    res = 0
    for i in range(D):
        res += (a[i]-b[i])**2
    res = res**0.5
    return res

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 math
n, d = map(int, input().split())
x = []
cnt = 0
for i in range(n):
    l = list(map(int, input().split()))
    x.append(l)
for i in range(n-1):
    for j in range(i+1, n):
        di = 0
        for k in range(d):
            di += (x[i][k] - x[j][k]) ** 2
        if math.sqrt(di).is_integer():
            cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n,d = i2()
x = []
for i in range(n):
	a = intl()
	x.append(a)

def dist(a,b,d):
	dist = 0
	for i in range(d):
		dist += (a[i] - b[i])**2
	return dist		

cnt = 0
for i in range(n-1):
	for j in range(i+1,n):
		test = dist(x[i], x[j], d)
		if ( (test)**(1/2) )%1 == 0:
			cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
import itertools

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

i = 1
sq = []
while i**2 <= 40**2*10:
    sq.append(i**2)
    i += 1

cnt = 0
l = [int(i) for i in range(n)]
for v in itertools.combinations(l, 2):
    i, j = v[0], v[1]
    sub = x[i] - x[j]
    dist = sum(sub**2)
    if dist in sq:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
def resolve():
    N, D = list(map(int, input().split()))
    X = [list(map(int, input().split())) for _ in range(N)]
    cnt = 0
    import itertools
    for i, j in itertools.combinations(list(range(N)), 2):
        dist = 0
        for d in range(D):
            dist += (X[i][d] - X[j][d])**2
        dist = dist**(0.5)
        if dist == int(dist):
            cnt += 1
    print(cnt)
    
if '__main__' == __name__:
    resolve()

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

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:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, D = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    ans=0
    for i in range(N):
        for j in range(i+1,N):
            si=S[i]
            sj=S[j]
            dis=0
            for k in range(D):
                dis+=(si[k]-sj[k])**2
            if round(dis**0.5)**2==dis:
                ans+=1
    print(ans)





if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def d(a, b):
    ans = 0
    n = len(a)
    for i in range(n):
        ans += (a[i] - b[i]) ** 2
    return int(ans**0.5) == ans**0.5

def solve():
    n, _ = [int(x) for x in input().split()]
    ans = 0
    points = []
    for _ in range(n):
        arr = [int(x) for x in input().split()]   
        points.append(arr)
    for i in range(n):
        for j in range(i+1, n):
            ans += d(points[i], points[j])
    print(ans)

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()




"""

4
1 2
2 4
1 3
3
2 2 4
4 5 6

6
1 2
2 3
3 4
4 5
4 6
3
3 5 6
2 17 31 5 11

"""

Submission status: Accepted

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

for i in range(N):
  for j in range(i):
    d = sum([(X[i][d]-X[j][d])**2 for d in range(D)])**0.5
    if d.is_integer():
      a+=1

print(a)

Submission status: Accepted

Solution code:
import sys
import itertools
import math
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, d = map(int, input().split())
    x = []
    for _ in range(n):
        x.append(list(map(int, input().split())))
    ans = 0
    for comb in itertools.combinations(range(n), 2):
        dis = 0
        for i, j in zip(x[comb[0]], x[comb[1]]):
            dis += (i - j)**2
        if str(math.sqrt(dis)).split('.')[-1] == '0':
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def f(x,y):
    A=0
    for i in range(len(x)):
        A+=(x[i]-y[i])*(x[i]-y[i])
    return A

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

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

S=set()
k=0
L=4*M*M*D
while k*k<=L:
    S.add(k*k)
    k+=1
    
K=0
for i in range(N):
    for j in range(i+1,N):
        K+=(f(X[i],X[j]) in S)
print(K)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N,D = (int(x) for x in input().split())
X = np.zeros((N,D),dtype=int)
for I in range(0,N):
    X[I,:] = np.array([int(x) for x in input().split()],dtype=int)
    
Count = 0
for I in range(0,N-1):
    for II in range(I+1,N):
        if np.linalg.norm(X[I,:]-X[II,:]).is_integer():
            Count += 1
print(Count)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import numpy as np

n, d = map(int, input().split())
x = [np.array([*map(int, input().split())]) for _ in range(n)]
c = 0
for i in range(n):
    for j in range(i + 1, n):
        c += np.linalg.norm(x[i] - x[j]).is_integer()
print(c)

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
import math

def get_distance(l1, l2):
    dis = 0
    for i in range(len(l1)):
        dis += (l1[i]-l2[i]) ** 2
    return math.sqrt(dis)

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

for n in range(N-1):
    for d in range(n+1, N):
        dis = get_distance(X[n], X[d])
        if dis.is_integer():
            ans += 1

print(ans)

Submission status: Accepted

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

def dist_squere(x, y):
    d = 0
    for i,j in zip(x,y):
        d += (i-j)**2
    return d**.5

from itertools import combinations

ans = 0
for x,y in combinations(X, 2):
    if dist_squere(x, y).is_integer():
        ans += 1

print(ans)

Submission status: Accepted

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

def dist_squere(x, y):
    d = 0
    for i,j in zip(x,y):
        d += (i-j)**2
    return d

squares = set([i*i for i in range(10000)])
def is_square(x):
    return x in squares

from itertools import combinations

ans = 0
for x,y in combinations(X, 2):
    if is_square(dist_squere(x, y)):
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
x = []
sum_ = 0
count = 0

for ni in range(n):
    e = list(map(int, input().split()))
    x.append(e)

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

print(count)

Submission status: Accepted

Solution code:
def lin(x,y):
    return np.sqrt(sum((x-y)**2))

from itertools import combinations as cb
n,d = map(int,input().split())
import numpy as np

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

cnt = 0
for a,b in cb(range(n),2):
    #print(x[a],x[b])
    if lin(x[a],x[b]).is_integer():
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
N,D = list(map(int,input().split()))
 
lis =[list(map(int,input().split())) for i in range(N)]
lis_np = np.array(lis)
counter = 0
for i in range(N-1):
    for j in range(i+1,N):
        kyori = (sum((lis_np[:][i] - lis_np[:][j])**2))**0.5
        if kyori == int(kyori):
            counter += 1
        
print(counter)

Submission status: Accepted

Solution code:
import math

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

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

print(ans)

Submission status: Accepted

Solution code:
n,d = [int(z) for z in input().split()]
p=[]
for g in range(n):
      p.append([int(z) for z in input().split()])
c=0

def dist(a,b):
      s=0
      for i in range(d):
            s+= (a[i]-b[i])**2
      return s**0.5

for j in range(n):
      for k in range(j+1,n):
            z = dist(p[j],p[k])
            #print(z)
            if (type(z)==float)or(type(z)==int):
                       if (z%1==0):
                             c+=1
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

for _ in range(N):
    line = tuple(map(int, input().split()))
    coordinates.append(line)

count = 0
for i in range(N):
    for j in range(i+1, N):

        total = 0
        for y, z in zip(coordinates[i], coordinates[j]):
            total += abs(y - z) ** 2
    
        for k in range(1, total+1):
            if k * k == total:
                count += 1

print(count)

Submission status: Accepted

Solution code:
import math
a,b=map(int,input().split())
c=[]
for _ in range(a):
    c.append(list(map(int,input().split())))
ans=0
for i in range(a):
    for j in range(i):
        n=c[i]
        m=c[j]
        result=[(x-y)**2 for (x,y) in zip(n,m)]
        if math.sqrt(sum(result))%1==0:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
N,D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]
count = 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
        if(s==int(s)):
            count+=1
print(count)

Submission status: Accepted

Solution code:
def main():
    import math
    n, d = map(int, input().split())
    inlis = []
    for i in range(n):
        inlis.append(list(map(int, input().split())))
    
    ans = 0
    for i in range(n):
        for j in range(n):
            if i < j:
                dist = 0
                for k in range(d):
                    dist += (inlis[i][k] - inlis[j][k])**2
                if (dist ** 0.5).is_integer():
                    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)]
count = 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
        if int(s) == s:
            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)]

ans = 0

for i in range(n-1):
    for j in range(i+1,n):
        sub = 0
        for k in range(d) :
            sub += abs(x[i][k]-x[j][k])**2
        sub = sub**0.5
        if sub.is_integer() :
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math
N,D=map(int,input().split())
cord=[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):
        distance=math.sqrt(sum((cord[i][s]-cord[j][s])**2 for s in range(D)))
        if distance-int(distance)<=0.0001:
            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)]

ans = 0
for i in itertools.combinations(x, 2):
    length = 0
    for j in range(d):
        length += (i[0][j] - i[1][j]) ** 2
    if math.sqrt(length) % 1 == 0:
        ans += 1
print(ans)

Submission status: Accepted

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

cnt = 0
for i in range(N-1):
    for j in range(i+1, N):
        a = 0
        for l in range(D):
            a += (X[i][l] - X[j][l])**2
        a = a ** 0.5
        if a.is_integer():
            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)]

a = 0
cnt = 0
for i in range(N-1):
    for j in range(i+1, N):
        for l in range(D):
            a += (X[i][l] - X[j][l])**2
        a = a ** 0.5
        if a.is_integer():
            cnt += 1
        a = 0

print(cnt)

Submission status: Accepted

Solution code:
def distance(a,b):
    return abs((a-b)**2)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math


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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
sqs = set([i ** 2 for i in range(500)])
lst = []
for i in range(n):
  temp = list(map(int, input().split()))
  lst.append(temp)
cnt = 0
for i in range(n - 1):
  for j in range(i + 1, n):
    nrm = 0
    for k in range(d):
      nrm += (lst[i][k] - lst[j][k]) ** 2
    if nrm in sqs:
      cnt += 1
print(cnt)

Submission status: Accepted

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


resolve()

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 - 1):
    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.is_integer():
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
N,D=map(int,input().split())
X=[np.array(input().split(),dtype=np.int64) for _ in range(N)]
ans=0
for i in range(N):
    for j in range(i+1,N):
        d=((X[i]-X[j])*(X[i]-X[j])).sum()
        dd=int(round(d**.5))
        if d==dd*dd:
            ans +=1
print(ans)

Submission status: Accepted

Solution code:
import math

def gooddistance(l1, l2):
    calc = []
    
    for i in range(len(l1)):
        calc.append((l1[i] - l2[i])**2)

    if math.sqrt(sum(calc)).is_integer():
        return 1
    else:
        return 0

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

for i in range(n):
    for j in range(i+1,n):
       count += gooddistance(lst[i],lst[j])

print(count)

Submission status: Accepted

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

l=[]
for i in range(n):
  X=[int(x) for x in input().rstrip().split()]
  l.append(X)

ans=0
for i in range(n):
  ni=l[i]
  for j in range(i+1,n):
    nj=l[j]
    now=0
    for s in range(d):
      now+=(ni[s]-nj[s])**2
    now=now**0.5
    if now.is_integer():
        ans+=1
print(ans)

Submission status: Accepted

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

from math import sqrt
ans=0

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