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 = (int(i) for i in input().split())

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

count = 0

for i in range(N):
  for j in range(i+1,N):
    check_num = 0
    for k in range(len(X[i])):
      check_num += (X[i][k] - X[j][k])**2

    if float.is_integer(math.sqrt(check_num)):
      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)]
s=0
for i in range(n):
  for j in range(n):
    if i<=j:continue
    s+=math.sqrt(sum([(y-z)**2 for y,z in zip(x[i],x[j])])).is_integer()
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

if D == 1:
    list_nd = [int(input()) for i in range(N)]
    print(N*(N-1)//2)


else:
    list_ND = [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 += (list_ND[i][k] - list_ND[j][k])**2
    
            s = math.sqrt(s)

            if s.is_integer():
                count += 1

    print(count)

Submission status: Accepted

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


count=0
sum1=0
sum1=0
for i in range(a):
    for z in range(i+1,a,1):
        for j in range(b):
            sum1+=(c[i][j]-c[z][j])**2
        
        if math.sqrt(sum1)%1.0==0:
            count+=1
        sum1=0
print (count)

Submission status: Accepted

Solution code:
import numpy as np

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

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

Submission status: Accepted

Solution code:

import math
def dist(x,y):
  result=0;
  for i in range(len(x)):
    result+=(x[i]-y[i])*(x[i]-y[i])
  return result
def isSquare(x):
  s=int(math.sqrt(x))
  return s*s==x

N,D=[int(i) for i in input().split()];
X=[[int(i) for i in input().split()]for j in range(N)];
ans=0;
for i in range(N):
  for j in range(i+1,N):
    if(isSquare(dist(X[i],X[j]))):
      ans+=1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

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

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-1):
    for j in range(i+1,n):
        for k in range(d):
            diff = sum([(s-t)**2 for s,t in zip(X[i],X[j])])
        if (diff**.5).is_integer():c += 1
print(c)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,D=map(int,input().split())
X=[]

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

ans=0
for i in range(N-1):
    for j in range(i+1,N):
        temp=0
        for k in range(D):
            #print(i,j,k)
            temp+=(X[i][k]-X[j][k])**2
        if temp**0.5==(temp**0.5)//1:
            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)]
c=0
for i in range(n-1):
    for j in range(i+1,n):
        for k in range(d):
            diff = sum([(s-t)**2 for s,t in zip(X[i],X[j])])
        if (diff**.5).is_integer():c += 1
print(c)

Submission status: Accepted

Solution code:
import math

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

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

for i in range(N-1):
  for j in range(i+1,N):
    for k in range(D):
      s+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k])
    s=math.sqrt(s)
    #print(s)
    if s==int(s):
      cnt+=1
    s=0
print(cnt)

Submission status: Accepted

Solution code:
def main():
    def dist(c1, c2):
        cur = 0
        for x1, x2 in zip(c1, c2):
            cur += (abs(x1-x2))**2
        return sqrt(cur)
    from math import sqrt
    N, D = (int(i) for i in input().split())
    c = [[int(i) for i in input().split()] for j in range(N)]
    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            if dist(c[i], c[j]).is_integer():
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
X=[]
diff=0
c=0
for _ in range(n):
    X.append(list(map(int,input().split())))
for i in range(n-1):
    for j in range(i+1,n):
        for k in range(d):
            diff += (X[i][k]-X[j][k])**2
        if (diff**.5).is_integer():c += 1
        diff=0
print(c)

Submission status: Accepted

Solution code:
N,D=map(int, input().split())
X=[list(map(int,input().split())) for i in range(N)]
from itertools import permutations, combinations,combinations_with_replacement,product

def dist(X,Y,D):
  ans = 0
  for i in range(D):
    ans += (X[i]-Y[i])**2
  ans = ans ** 0.5
  return ans

L = combinations(range(N), 2)
cnt = 0
for i in L:
  if (dist(X[i[0]],X[i[1]],D)).is_integer():
    cnt +=1
print(cnt)

Submission status: Accepted

Solution code:
import math
def resolve():
    n, d = list(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 = math.sqrt(sum([(y-z)**2 for y,z in zip(x[i],x[j])]))
            if d.is_integer():
                ans += 1
    print(ans)
resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
x=[list(int(i) for i in input().split()) for _ in range(n)]
dis=0
ans=0
for i in x:
  for j in x:
    for k in range(d):
      dis+=(i[k]-j[k])*(i[k]-j[k])
    if dis**0.5%1==0:
      ans+=1
    dis=0
ans-=n
print(ans//2)

Submission status: Accepted

Solution code:
#テストファイルで実行する時
import sys
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')

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

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

#print(x)

ans = 0

import math

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

#ルートの計算
#import math
#math.sqrt(x)

print(int(ans/2))

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    

correct = 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)) ** (1/2)
        
        if z % 1 == 0:
            correct += 1
    
print(correct)

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

count = 0

for i in range( N-1 ):
    for j in range( i+1 , N ):
        distance = ( np.sum( ( X[i] - X[j] ) ** 2 ) ) ** ( 1/2 )
        if int(distance) == distance:
            count += 1
print(count)

Submission status: Accepted

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


def distance(X1, X2):
    r = 0
    for i in range(len(X1)):
        r += (X1[i] - X2[i]) ** 2
    return r ** 0.5


def main():
    N, D = map(int, input().split())
    X = [None for i in range(N)]

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

    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            r = distance(X[i], X[j])
            if r.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 _ in range(N)]
count = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        r = 0
        for k in range(D):
            r += (X[i][k] - X[j][k]) ** 2
        if r ** 0.5 % 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 i in range(n)]
l = []
for a in range(n-1):
        for b in range(a+1, n): 
                r = 0 
                for c in range(d):
                        r += (x[a][c] - x[b][c])**2
                l.append(math.sqrt(r))
print(sum(i.is_integer() for i in l))

Submission status: Accepted

Solution code:
import numpy as np

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

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

cnt = 0

for i in range(n-1):
    for j in range(i+1,n):
        total = 0
        # print('xi',x[i])
        # print('xj',x[j])
        for k in range(d):
            dis = (x[i][k] - x[j][k]) ** 2
            total += dis
        tdis = np.sqrt(total)
        idis = int(np.sqrt(total))
        if tdis == idis:
        # print(type(tdis),tdis)
        # if 'int' == type(tdis):
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math

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

ND = list(map(int,input().split()))
N=ND[0]
D=ND[1]
X = [list(map(int,input().split())) for l in range(N)]
cnt=0
for i in range(N-1):
     for j in range(i+1,N):
         summary=0
         for k in range(D):
             summary=summary+(X[i][k]-X[j][k])*(X[i][k]-X[j][k])
         distance=math.sqrt(summary)
         if is_integer_num(distance):
             cnt=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)]
buf_1 = 0
buf_2 = 0

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

Submission status: Accepted

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

x = [[]] * n

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

ans = 0

for i in range(n-1):
  std_vertex = x[i]
  for j in range(i+1, n):
    other_vertex = x[j]
    tmp = 0
    for dim in range(d):
      tmp += (std_vertex[dim] - other_vertex[dim]) ** 2
    dist = math.sqrt(tmp)
    # print(dist)
    # print(dist % 1)
    if dist % 1 == 0:
      ans += 1
  
# print(n, d, x)

print(ans)

Submission status: Accepted

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

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

com = itertools.combinations(nums, 2)
ans =0
for c in com: 
    d = 0
    for y, z in zip(c[0], c[1]):
        d += abs(y - z) ** 2
    d = math.sqrt(d)
    ans += 1 if d == int(d) else 0

print(ans)

Submission status: Accepted

Solution code:
N, D = [int(x) for x in input().split()]
X = [input() for i in range(N)]
answer = 0
for i in range(N):
    for j in reversed(range(N)):
        if i == j:
            break
        else:
            answer_list = []
            X_list = [int(x) for x in X[i].split()]
            X_list_rev = [int(x) for x in X[j].split()]
            for k in range(D):
                answer_list.append(abs(X_list[k] - X_list_rev[k])**2)
            if sum(answer_list)**0.5 % 1 == 0:
                answer += 1
print(answer)

Submission status: Accepted

Solution code:
n,d = map(int,input().split())
pnt = [list(map(int,input().split())) for _ in range(n)]
 
def dst(i, j):
    a = pnt[i]
    b = pnt[j]
    ret = 0
    for p, q in zip(a, b):
        ret += (p - q) ** 2
    r = int(ret ** (0.5))
    if r ** 2 == ret:
        return True
    else:
        return False
 
ret = 0
for i in range(n):
    for j in range(i + 1, n):
        tmp = dst(i, j)
        if tmp:
            ret += 1
print(ret)

Submission status: Accepted

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

result = 0

for i in range(len(x)):

    for i1 in range(i,len(x)):

        tmp1 = x[i]
        tmp2 = x[i1]

        ans = 0
        for i2 in range(len(tmp1)):
            ans = ans + (tmp1[i2]-tmp2[i2])**2
        ans = math.sqrt(ans)

        if ans.is_integer() and 0 < ans:
            result  = result + 1
print(result)

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):
        a=[]
        for y,z in zip(x[i],x[j]):
            q=(y-z)**2
            a.append(q)
        ans+=((sum(a))**0.5).is_integer()

print(ans)

Submission status: Accepted

Solution code:
# ABC 133: B – Good Distance
from itertools import combinations

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

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

pairs = list(combinations(x, 2))
the_number_of_pairs = 0

#print(pairs)

for i in range(len(pairs)):
    distance = 0

    for j in range(d):
        distance += (abs(pairs[i][0][j] - pairs[i][1][j])) ** 2
    
    distance = distance ** 0.5

    if distance == int(distance):
#        print(pairs[i])
        the_number_of_pairs += 1

print(the_number_of_pairs)

Submission status: Accepted

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


cnt=0
def abc(n,m,i,res):
    global cnt,x,d
    if i==d:
        return res
    else:
        res=abc(n,m,i+1,res+(x[m][i]-x[n][i])**2)
    return res

for i in range(n-1):
    for j in range(i+1,n):
        a=abc(i,j,0,0)**0.5
        if int(a)==a:
            cnt+=1
print(cnt)

Submission status: Accepted

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

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


count = 0
for n1 in range(N - 1):
    for n2 in range(n1 + 1, N):
        summary = 0
        for d in range(D):
            summary += (X[n1][d] - X[n2][d]) ** 2
        if sqrt(summary).is_integer():
            count += 1
print(count)

Submission status: Accepted

Solution code:
import math
N,D=map(int,input().split()) #Nはポイントの数　Dは次元数（点を示す変数の数）
P=0
Q=0
X= [list(map(int, input().split())) for t in range(N)]
for i in range(N-1):
  for j in range(i+1,N):
    for k in range(D):
      P=P+(X[i][k]-X[j][k])**2
    if int(math.sqrt(P))==math.sqrt(P):
      Q=Q+1
    P=0
print(Q)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
def print_ans(N, D, dr):
    """Test Case
    >>> print_ans(3, 2, [[1, 2], [5, 5], [-2, 8]])
    1
    >>> print_ans(3, 4, [[-3, 7, 8, 2], [-12, 1, 10, 2], [-2, 8, 9, 3]])
    2
    >>> print_ans(5, 1, [[1],[2],[3],[4],[5]])
    10
    """
    dr = [np.array(d) for d in dr]
    ans = 0
    for i in range(N-1):
        for k in range(i + 1, N):
            multi_ar = dr[i] - dr[k] 
            abs_tmp = float(np.sum(multi_ar ** 2) ** (1/2))
            if(abs_tmp.is_integer()):
                ans += 1
    print(ans)



if __name__ == '__main__':
    N, D = map(int, input().rstrip().split())
    dr = [list(map(int, input().rstrip().split())) for _ in range(N)]
    print_ans(N, D, dr)

Submission status: Accepted

Solution code:
# 2019-11-15 13:51:51(JST)
import sys
# import collections
import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n, d = [int(x) for x in sys.stdin.readline().split()]
    x = [tuple(int(x) for x in sys.stdin.readline().split()) for _ in range(n)]

    count = 0
    for i in range(n-1):
        for j in range(1, (n-1)-i+1):
            dist = sum([ (x[i+j][k] - x[i][k]) ** 2 for k in range(d)]) ** 0.5
            if dist == math.floor(dist):
                count += 1

    print(count)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict,deque, Counter
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

def is_square(integer):
    root = math.sqrt(integer)
    return integer == int(root + 0.5) ** 2

ans = 0
[n,d] = inpl()
Xmatrix = [inpl() for _ in range(n)]
npXmatrix = np.array(Xmatrix)
for i in range(n):
    for j in range(i+1,n):
        if is_square(((npXmatrix[i]-npXmatrix[j])**2).sum()):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
from math import sqrt
N, D = map(int, input().split())
Xlist = [np.array(list(map(int, input().split()))) for _ in range(N)]
counter = 0
for i in range(N):
    for j in range(i + 1, N):
        dis = sqrt(np.sum((Xlist[i] - Xlist[j])**2))
        if int(dis) == dis:
            counter += 1
print(counter)

Submission status: Accepted

Solution code:
import math
N,D = map(int,input().split())
X_ = [0] * N
X = [0]*N
for i in range(N):
    X_[i] = input().split()
for i in range(len(X_)):
    X[i] = [int(j) for j in X_[i]]
cnt = 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 #i番目の点とj番目の点の距離の二乗
        if math.sqrt(l2) == int(math.sqrt(l2)):
            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)]
a = 0
ans = 0

for x1 in range(0, N):
  for x2 in range(x1+1, N):
    for i in range(0, D):
      a += (X[x1][i]-X[x2][i])**2
    if math.sqrt(a).is_integer():
      ans += 1
    a = 0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
import itertools

N,D=map(int,input().split(' '))
X = np.zeros(shape=(N,D))
for i in range(N):
  X[i]=np.array(list(map(int,input().split(' '))))

def distance(v1,v2):
  return np.linalg.norm(v1-v2)

res=0
C=itertools.combinations(list(range(N)),2)
for c in C:
  res+=distance(X[c[0]],X[c[1]]).is_integer()
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

n, d = list(map(int, input().split()))
x = [[0] * d] * n

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

ans = 0

for i in range(n):
    for j in range((i + 1), n, 1):
        diffs = 0

        for k in range(d):
            diffs += (x[i][k] - x[j][k]) ** 2

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

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

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

Submission status: Accepted

Solution code:
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    N, D = map(int, input().split())
    X_l = [[int(x) for x in input().split()] for _ in range(N)]

    import math

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



    

# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("abc133","b",main)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import sqrt


def solve():
    N, D = map(int, input().split())
    x_l = [0 for _ in range(N)]
    for i in range(N):
        x_l[i] = list(map(int, input().split()))
    ans = 0

    for i in range(N-1):
        for j in range(i+1, N):
            distance = 0
            for k in range(D):
                distance += (x_l[i][k] - x_l[j][k]) ** 2
            distance = sqrt(distance)
            if distance.is_integer():
                ans += 1

    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

cub_of_ds = 0
cnt = 0

for i in range(n):
    for j in range(i+1, n):
        for k in range(d):
            cub_of_ds += (ls_x[i][k] - ls_x[j][k])**2
        if ((cub_of_ds)**(1/2)).is_integer() == True:
            cnt += 1
        cub_of_ds = 0
        
print(cnt)

Submission status: Accepted

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

cub_of_ds = 0
cnt = 0

for i in range(n):
    for j in range(n):
        for k in range(d):
            cub_of_ds += (ls_x[i][k] - ls_x[j][k])**2
        if (((cub_of_ds)**(1/2)).is_integer() == True) and (i > j):
            cnt += 1
        cub_of_ds = 0
        
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np

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

li = np.array(li)
count = 0

for i in range(n-1):
    for j in range(i+1,n):
         x = np.linalg.norm(li[i]-li[j])
         if float.is_integer(x):
             count += 1

print(count)

Submission status: Accepted

Solution code:
import math

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

cnt = 0
    
for i in range(n-1):
    for j in range(i+1, n):
        L=0
        for k in range(d):
            L += (p[i][k] - p[j][k])**2
        L = math.sqrt(L)
        if L.is_integer() == True:
            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)]
Sum = 0
d = [0]*(N*(N-1)//2)
t = 0
for i in range(N-1):
    for j in range(i+1,N):
        for s in range(D):
            d[t] += abs(X[i][s]-X[j][s])**2
        d[t] = pow(d[t],0.5)
        if d[t].is_integer():
            Sum += 1
        t += 1
print(Sum)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    def check(i,j):
        if(i>=j): return False
        d=sum((X[i][k]-X[j][k])**2 for k in range(D))**.5
        return d==int(d)

    n,D=map(int,input().split())
    X=[list(map(int,input().split())) for _ in range(n)]
    from itertools import product
    print(sum(check(i,j) for i,j in product(range(n),repeat=2)))
resolve()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

xll = []
for _ in range(n):
    xl = list(map(int,input().split()))
    xll.append(xl)
    
ans = 0
for i in range(n):
    for j in range(i+1, n):
        tmp = 0
        for x1, x2 in zip(xll[i], xll[j]):
            tmp += (x1-x2)**2
        tmp = tmp ** (1/2)
        if tmp == int(tmp):
            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())))

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

Submission status: Accepted

Solution code:
from math import sqrt
from itertools import combinations


def main(n, d, x):
    ans = 0
    for a, b in combinations(x, 2):
        r = 0
        for c, d in zip(a, b):
            r += abs(c - d)**2

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

    print(ans)


if __name__ == '__main__':
    n, d = map(int, input().split())
    x = [list(map(int, input().split())) for _ in range(n)]

    main(n,d,x)

Submission status: Accepted

Solution code:
N,D = map( int, input().split() )
distance = []
c = 0
for i in range(N):
    a = list( map( int, input().split() ) )
    distance.append(a)

for i in range(N):
    for j in range(i+1,N):
        t = 0
        ans = 0
        for k in range(D):
            t += ( distance[i][k] - distance[j][k] )**2
        ans = t**(1/2)
        if ans.is_integer():
            c += 1
print(c)

Submission status: Accepted

Solution code:
from sys import stdin

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