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

def check(x, y):
    s = 0
    for a, b in zip(x, y): s += (a - b) ** 2

    for i in range(0, s+1):
        if i * i == s: return 1
    return 0


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

Submission status: Accepted

Solution code:
import numpy as np
N,D = map(int, input().split())
X_matrix = [list(map(int, input().split())) for _ in range(N)]
count=0
for i in range(N):
  for k in range(i+1,N):
      if np.sqrt(sum((np.array(X_matrix[i])-np.array(X_matrix[k]))**2)).is_integer():
        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)]

ans = 0

for i in range(N):
    for j in range(i):
        d = 0
        for k in range(D):
            d += (X[i][k]-X[j][k])**2
        dsqrt = d**0.5
        if dsqrt == dsqrt//1:
            ans += 1 
print(ans)

Submission status: Accepted

Solution code:
import math

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

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

print(ans)

Submission status: Accepted

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

def dist(r1, r2):
    ans = 0
    for i in range(len(r1)):
        ans += (r1[i] - r2[i])**2
    return ans**(1/2)

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

print(ans)

Submission status: Accepted

Solution code:
from math import sqrt
n,d=map(int,input().split())
x=[]

ans=0
for i in range(n):
    x.append(list(map(int,input().split())))

for j in range(n):
    for k in range(n):
        a=0
        if j!=k:
            for l in range(d):
                a+=(x[j][l]-x[k][l])**2
            if sqrt(a).is_integer()==True:
                ans+=1
print(ans//2)

Submission status: Accepted

Solution code:
import itertools
import numpy as np

n, d = [int(_) for _ in input().split()]
a = np.array([[int(_) for _ in input().split()] for _ in range(n)])

L = list(itertools.combinations(a, 2))
cnt = 0
for u, v in L:
    dist = np.sqrt(sum((u-v)**2))
    if dist%1==0:
        cnt +=1
print(cnt)

Submission status: Accepted

Solution code:
# Good Distance

# libraries
import numpy as np
from itertools import combinations

# input
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())))

# solve
def calc_distance(y,z):
    return np.sqrt(np.sum((y - z)**2))

res = 0

for y, z in combinations(X, r = 2):
    distance = calc_distance(y, z)
    if distance - int(distance) == 0:
        res += 1

# output
print(res)

Submission status: Accepted

Solution code:
from itertools import combinations
sq = [i**2 for i in range(500)]
ans = 0
n,d = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
for (i,j) in combinations(a,2):
  dist2 = 0
  for x in range(d):
    dist2 += (i[x]-j[x])**2
  if dist2 in sq:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math

# nまでの和
def n_sum(n):
    return n * (n - 1) // 2

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

    ite_num = n_sum(N)
    ans = 0
    for i in range(N-1):
        for j in range(i+1, N):
            tmp_sum = 0
            for k in range(D):
                tmp_sum += abs(point[i][k] - point[j][k])**2
            if math.sqrt(tmp_sum).is_integer():
                ans += 1
    return ans

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

Submission status: Accepted

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

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        norm = 0
        for k in range(d):
            diff = abs(x[i][k] - x[j][k])
            norm += diff * diff
    
        flag = False
        for k in range(norm+1):
            if k * k == norm:
                flag = True
        if flag:
            ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

def ok(x,y):

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

ans = 0
for i in range(n):
    for j in range(i+1,n):
        if ok(data[i],data[j]):
            ans += 1

print(ans)

Submission status: Accepted

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

print(count)

Submission status: Accepted

Solution code:
N, D = map(int, input().strip().split())
X = [[int(n) for n in input().strip().split()] for _ in range(N)]
c = 0
for i in range(N):
    for j in range(i+1, N):
        n = 0
        for k in range(D):
            x = abs(X[i][k] - X[j][k])
            n += x * x 
        b = False
        for k in range(n+1):
            if k * k == n:
                b = True
        if b:
            c += 1
print(c)

Submission status: Accepted

Solution code:
import math
nd = list(map(int,input().split()))
n = nd[0]
d = nd[1]
x_dic = {}
for i in range(n):
    temp = list(map(int,input().split()))
    x_dic[i] = temp

def calc(list_1, list_2, d):
    dist_sq = 0
    for i in range(d):
        dist_sq += (list_1[i]-list_2[i])*(list_1[i]-list_2[i])
    dist = math.sqrt(dist_sq)
    return dist

ans = 0
for i in range(n):
    for j in range(i+1,n):
        temp = calc(x_dic[i], x_dic[j], d)
        if temp == math.ceil(temp):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math
n, d = map(int, input().split())
x = list(input().split() for i in range(n))
x = [[int(i) for i in x[j]] for j in range(len(x))]
a = 0
for i in range(n-1):
    for j in range(i+1,n):
        di = 0
        for b in range(d):
            di += (x[i][b] - x[j][b]) ** 2
        di = math.sqrt(di)
        if di == int(di):
            a += 1
        else:
            pass
print(a)

Submission status: Accepted

Solution code:
import math
n, d = map(int, input().split())
def dist(x, y):
    ans = 0
    for i in range(d):
        ans += (x[i] - y[i]) ** 2
    if int(math.sqrt(ans)) * int(math.sqrt(ans)) == ans:
        return True
    else:
        return False
arr = []
for i in range(n):
    x = list(map(int, input().split()))
    arr.append(x)
ans = 0
for i in range(n):
    for j in range(i+1, n):
        if i == j:
            continue
        if dist(arr[i], arr[j]):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
p = []
for i in range(n):
  p.append(list(map(int, input().split())))
def distance(x, y):
  a = 0
  for i in range(d):
    a += (p[x][i]-p[y][i])**2
  return(a**0.5)

ans = 0
a = 0
while a < n:
  for i in range(a+1, n):
    if distance(a, i) % 1 ==0:
      ans += 1
  a += 1

print(ans)

Submission status: Accepted

Solution code:
n,*l, = [list(map(int,s.split()))for s in open(0)]
cnt = 0
for i in range(len(l)-1):
    for j in range(i+1,len(l)):
        dist = 0
        for d in range(n[1]):
            dist += (l[i][d] - l[j][d])**2
        if (dist**(0.5))%1 ==0:
            cnt += 1
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import itertools
import math

def kyori(data1, data2):
    result = 0
    for i in range(len(data)):
        result += (data1[i]-data2[i])**2
    return math.sqrt(result)

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

comb = itertools.combinations(X, 2)
ans = 0
for c in comb:
   if kyori(c[0],c[1]).is_integer():
       ans += 1

print(ans)

Submission status: Accepted

Solution code:
import itertools


def distance(Y, Z):
    result = 0
    for y, z in zip(Y, Z):
        result += (int(y) - int(z)) ** 2
    result = result ** 0.5
    return result


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


ans = 0
for Y, Z in itertools.combinations(X, 2):
    if distance(Y, Z).is_integer():
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math
n, d = map(int, input().split())
coos = []
cnt = 0
chk = 0
for i in range(0, n):
    coo = list(map(int, input().split()))
    coos.append(coo)
for i in range(n-1):
    for j in range(i+1, n):
        chk = 0
        for k in range(d):
            chk += (coos[i][k] - coos[j][k])**2
        chk = math.sqrt(chk)
        if chk.is_integer() == True:
            cnt+=1
        else:
            continue
print(cnt)

Submission status: Accepted

Solution code:
def examA():
    N, A, B = LI()
    ans = min(A*N,B)
    print(ans)
    return

def examB():
    N, D = LI()
    X = [LI() for _ in range(N)]
    ans = 0
    for i,j in itertools.combinations(X,2):
        cur = 0
        for k in range(D):
            cur += (i[k]-j[k])**2
        cur **=0.5
        if cur==int(cur):
            ans +=1
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examB()

Submission status: Accepted

Solution code:
import math
import itertools
# math.sqrt(数値)

def calcDist(row1, row2):
    n_dist = 0
    for d in range(D):
        dist = abs(row1[d] - row2[d])
        n_dist += dist ** 2
    return n_dist

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

dimentions = []

for i in range(N):
    row = list(map(int, input().split()))
    dimentions.append(row)
    
dim_combinations = itertools.combinations(dimentions, 2)

all_dist = []

for pair in dim_combinations:
    n_dist = calcDist(pair[0], pair[1])
    all_dist.append(math.sqrt(n_dist))

cnt = 0
for dist in all_dist:
    if dist.is_integer():
        cnt += 1
        
print(cnt)

Submission status: Accepted

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

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, *L,  = [list(map(int, s.split())) for s in open(0)]
cnt = 0
for i in range(len(L) - 1):
    for j in range(i+1, len(L)):
        dist = 0
        for d in range(N[1]):
            dist += (L[i][d] - L[j][d]) ** 2
        if (dist ** (0.5)) % 1 == 0:
            cnt += 1
print(cnt)

Submission status: Accepted

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

def Euclid_dist(tpl1, tpl2):
    if len(tpl1) != len(tpl2): raise TypeError("The length differs between tpl1 and tpl2")
    sum = 0
    for i in range(len(tpl1)):
        sum += pow(tpl1[i]-tpl2[i], 2)
    return math.sqrt(sum)

N, D = map(int,input().split())
li_X = [list(map(int, input().split())) for _ in range(N)]
count = 0
for i in range(N):
    for j in range(i+1, N):
        if Euclid_dist(li_X[i], li_X[j]).is_integer():
            count += 1
print(count)

Submission status: Accepted

Solution code:
import math

def distance(X1, X2):
    res = 0
    for x1, x2 in zip(X1, X2):
        res += pow(x1-x2, 2)
    return math.sqrt(res)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from scipy.spatial import distance
import itertools

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

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

combi = list(itertools.combinations(x, 2))

ans = 0
for i in range(len(combi)):
    dis = distance.euclidean(combi[i][0], combi[i][1])
    if dis.is_integer():
        ans += 1

print(ans)

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
import math

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

cnt=0
for i in range(n-1):
	for j in range(i+1,n):
		a=0
		for dd in range(d):
			a += abs(lst[i][dd] - lst[j][dd])**2    	
		aa=math.sqrt(a)
		if aa.is_integer():
			cnt += 1
print(cnt)

Submission status: Accepted

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

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


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


dists = []
for i in range(N):
    for j in range(i + 1, N):
        dists.append(dist(X[i], X[j]))

v = [i**2 for i in range(1000)]

ans = 0
for d in dists:
    if d in v:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
A=[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):
    X=0
    for k in range(d):
      X+=(A[i][k]-A[j][k])**2
    if (X**0.5)==((X**0.5)//1):    
      cnt+=1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, d = map(int, (input().split()))
lst = [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):
        sum = 0
        for k in range(d):
            sum += (lst[i][k] - lst[j][k]) ** 2
        if int(sum ** 0.5) ** 2 == sum:
            ans += 1

print(ans)

Submission status: Accepted

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

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

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

        m = 1
        while m*m < f:
            m += 1
        if m*m == f:
            ans += 1

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

cnt = 0
for i in range(1, N):
    A = np.sqrt(np.sum(np.square(X[i:] - X[i - 1]), axis=1))
    cnt += np.count_nonzero(A % 1 == 0)

print(cnt)

Submission status: Accepted

Solution code:

import itertools
import math

(n, d) = map(int, input().split())
l = [0] * n
for i in range(n):
    l[i] = list(map(int, input().split()))

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

count=0
for i in range(n):
    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(num**.5)**2:
            count+=1

print(count)

Submission status: Accepted

Solution code:
from itertools import combinations
from math import sqrt
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
print(len(list(filter(lambda x: x==float(int(x)), map(lambda t: sqrt(sum(map(lambda y,z: (y-z)**2, t[0], t[1]))), combinations(X, 2))))))

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

Submission status: Accepted

Solution code:
import math
n, d = map(int, input().split())
x = [list(map(int,input().split())) for i in range(n)]
cnt = 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
		b = math.sqrt(a)
		if b == int(b):
			cnt += 1
print (cnt)

Submission status: Accepted

Solution code:
from math import sqrt
n,d=map(int,input().split())
l=[list(map(float,input().split())) for i in range(n)]
nums=[i for i in range(n-1)]
fa=[i for i in range(d)]
cnt=0
ans=0
t=[]
for i in nums:
  for j in l[i+1:]:
    cnt=0
    for k in fa:
      cnt+=(l[i][k]-j[k])**2
    cnt=sqrt(cnt)
    t.append(cnt)
for v in t:
  if(v.is_integer()):
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
import math

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

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

cnt = 0
sum = 0

for i in range(n-1):

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

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

        if ((sum**0.5).is_integer()):
            cnt += 1
        sum = 0

print(cnt)

Submission status: Accepted

Solution code:
import math

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

point = []
cnt = 0

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

def calc_dist(x, y):
    dist = 0
    for xx, yy in zip(x, y):
        dist += ((xx - yy) ** 2)
    return math.sqrt(dist)

for i in range(N):
    for j in range(i+1, N):
        dist = calc_dist(point[i], point[j])

        if int(dist) == dist:
            cnt += 1
print(cnt)

Submission status: Accepted

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

ans=0
kyori=0

#
for i in range(N-1):
    
  for j in range(i+1,N):
    
    for k in range(D):
      kyori+=(zahyo[i][k]-zahyo[j][k])**2
    if (kyori**0.5).is_integer():
      ans+=1
      
    kyori=0
    
print(ans)

Submission status: Accepted

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

a=list(range(N))
b=list(itertools.combinations(a,2))

sum=0
count=0

for i in range(len(b)):
    for j in range(D):
        sum+=(X[b[i][0]][j]-X[b[i][1]][j])**2
    if sum**(1/2)%1!=0:
        sum=0
    else:
        count+=1
        sum=0

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

distance = 0
count = 0
for i in range(n-1):
    for j in range(i+1, n):
        combined1 = [x - y for (x, y) in zip(x[i], x[j])]
        distance = math.sqrt(sum(list(map(lambda x: x**2, combined1))))
        if distance%1 == 0:
            count += 1

print(count)

Submission status: Accepted

Solution code:
import itertools
import math
n, d = map(int, input().split())
l = list()
for i in range(n):
    l.append(list(map(int, input().split())))
a = list(itertools.combinations(l, 2))
count = 0
for i in range(len(a)):
    x = 0
    for j in range(d):
        x += (a[i][0][j]-a[i][1][j])**2
    if math.sqrt(x).is_integer():
        count += 1
print(count)

Submission status: Accepted

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

def dis(P1,P2):
  ans=0
  for i in range(len(P1)):
    ans+=(P1[i]-P2[i])**2
  ans=ans**0.5
  return ans

cnt=0
for i in range(n):
  for j in range(i+1,n):
    if dis(P[i],P[j])%1==0:
      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)]

cnt = 0
x = 0

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

print(cnt)

Submission status: Accepted

Solution code:
def main():
	import itertools
	
	n,d = map(int,input().split())
	# print(n,d)
	List = [list(map(int,input().split())) for i in range(n)]
	# print(len(List))
	combi = list(range(n))
	# print(combi)
	ans = 0
	for v in itertools.combinations(combi, 2):
		# print("v is {}".format(v))
		# print("v0 = {}".format(v[0]))
		# print("v1 = {}".format(v[1]))
		di = 0
		for i in range(d):
			# print("i = {}".format(i))
			# print("list v0 = {}".format(List[v[0]][i]))
			# print("list v1 = {}".format(List[v[1]][i]))
			di += (List[v[0]][i] - List[v[1]][i])**2
			# print("List[v[0]][i] =={}".format(List[v[0]][i]))
			# print("List[v[1]][i] =={}".format(List[v[1]][i]))
			# print("di = {}".format(di))
		# print(di)
		di = di**0.5
		# print(di)
		# print(isinstance(di,int))
		if di == int(di):
			ans += 1
			# print("ans = {}".format(ans))
		else:
			ans += 0
	print(ans)



	

if __name__ == "__main__":
	main()

Submission status: Accepted

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

for i in range(N):
    Xi = list(map(int, input().split()))
    X.append(Xi)
    
for i in range(N-1):
    for j in range(i+1, N):
        dis_sq = 0
        for d in range(D):
            dis_sq += (X[i][d]-X[j][d]) ** 2
        dis = dis_sq ** 0.5
#         print(dis)
        if dis.is_integer():
            ans += 1
print(ans)

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

ans = 0
for i in range(n):
    for j in range(n):
        t0 = 0
        for k in range(d):
            t0 += pow(p[i][k]-p[j][k],2)
        t  = math.sqrt(t0)
        if t.is_integer() and t != 0:
            ans += 1
print(ans//2)

Submission status: Accepted

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

for i in range(n):
    x[i]=list(map(int,input().split()))
for i in range(n-1):
    for j in range(i+1,n):
        kyori=0
        for k in range(d):
            kyori+=(x[i][k]-x[j][k])**2
        a=int(kyori**0.5)
        if a**2==kyori:
            count+=1
print(count)

Submission status: Accepted

Solution code:
import math
n,d=map(int,input().split())
v=[list(map(int,input().split())) for i in range(n)]
e=0
for i in range(n-1):
    for j in range(i+1,n):
        c=0
        for g in range(d):
            c+=abs(v[i][g]-v[j][g])**2
        if math.sqrt(c)%1==0:
            e+=1
print(e)

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 y, z in itertools.combinations(x, 2):
    s = 0
    for _y, _z in zip(y, z):
        s += abs(_y - _z)**2

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

print(ans)

Submission status: Accepted

Solution code:
N,D = map(int,input().split())
array = []
for i in range(N):
    l = list(map(int,input().split()))
    array.append(l)

c = 0
for i in range(N):
    for j in range(N):
        if i < j:
            dist2 = 0
            for k in range(D):
                dist2 += (array[i][k] - array[j][k])**2
            dist = (dist2)**(1/2)
            if dist == int(dist):
                c += 1
print(c)

Submission status: Accepted

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

for i1 in range(N):
    for i2 in range(i1+1, N):
        total = 0
        for index in range(D):
            total += (XX[i1][index] - XX[i2][index])**2
        val = int(total ** (1/2))
        if total == val ** 2:
            ans += 1

print(ans)

Submission status: Accepted

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

for i1 in range(N):
    for i2 in range(i1+1, N):
        total = 0
        for index in range(D):
            total += (XX[i1][index] - XX[i2][index])**2
        val = total ** (1/2)
        if isinstance(val, complex):
            val = val.real
        if val.is_integer():
            ans += 1

print(ans)

Submission status: Accepted

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

for i1, zahyo_1 in enumerate(XX):
    for i2, zahyo_2 in enumerate(XX):
        if i1 == i2:
            continue
        total = 0
        for index in range(D):
            total += (zahyo_1[index] - zahyo_2[index])**2
        val = total ** (1/2)
        if isinstance(val, complex):
            val = val.real
        if val.is_integer():
            ans += 1

print(ans//2)

Submission status: Accepted

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


cnt = 0
for i in range(N-1):
  y = x_list[i]
  for j in range(i+1, N):
    z = x_list[j]
    d = (sum([ (y[k]-z[k])**2 for k in range(D) ])) ** 0.5
    if d % 1 == 0:
      cnt += 1
      
print(cnt)

Submission status: Accepted

Solution code:
import math

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

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

combinations = []
for i in range(N):
    for j in range(N):
        if i != j:
            combinations.append([i, j])

combinations2 = []
for i in combinations:
    P = dots[i[0]]
    Q = dots[i[1]]
    r2 = 0
    for j in range(D):
        r2 += (P[j] - Q[j]) ** 2
    r = math.sqrt(r2)
    if r % 1 == 0:
        combinations2.append(i)

print(len(combinations2) // 2)

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N):
    for j in range(i+1, N):
        d = sum([(y - z)**2 for y, z in zip(X[i], X[j])])**0.5
        if isinstance(d, int) or d.is_integer():
            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([int(j) for j in input().split()])

sum=0
count=0
for x in range(0, N-1):
    for y in range(x+1, N):
        for z in range(D):
            sum +=abs((X[x][z]-X[y][z])*(X[x][z]-X[y][z]))

        sq=math.sqrt(sum)
        if(sq==int(sq)):
            count+=1
        sum=0

print(count)