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:
def distance(a, b):
    d = len(a)
    s = 0
    for i in range(d):
        s += (a[i] - b[i]) ** 2
    return s ** 0.5


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

cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        d = distance(xs[i], xs[j])
        if (d - int(d)) == 0:
            cnt += 1
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools


def calc_dist(p1, p2):
    return sum([(i - j) ** 2 for i, j in zip(p1, p2)])


def is_integer(p1, p2):
    dist = calc_dist(p1, p2)
    if pow(dist, 0.5).is_integer():
        return True
    else:
        return False


def main():
    points = []
    N, D = map(int, input().split())

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

    cnt = 0
    for pair in list(itertools.combinations(points, 2)):
        if is_integer(pair[0], pair[1]):
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math


def is_integer(p1, p2):
    total = 0
    for i, j in zip(p1, p2):
        total += (i - j) ** 2
    if math.sqrt(total) * 10 % 10 == 0:
        return True
    else:
        return False


def cnt_integer(points):
    cnt = 0
    size = len(points)

    for i in range(size):
        for j in range(i):
            if is_integer(points[i], points[j]):
                cnt += 1

    return cnt


def main():
    points = []
    N, D = map(int, input().split())

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

    print(cnt_integer(points))


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

print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

import math

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


def distance(y, z):
    k = 0
    cc = 0
    for (i, j) in zip(y, z):
        k += (i - j) ** 2
    if math.sqrt(k).is_integer() == True:
        cc += 1
    return(cc)


for i, s in enumerate(x):
    for t in x[i+1:]:
        c += distance(s, t)

print(c)

Submission status: Accepted

Solution code:
N,D = list(map(int,input().split()))
ans = 0
s = 0
L = []
for i in range(N):
  A = list(map(int,input().split()))
  L.append(A)
#print(L)
#print(L[0],L[0][0])
#print(L[0][0],L[1][0],L[0][1],L[1][1])
for j in range(N):
  #print("j="+str(j))
  for k in range(j+1,N):
    s = 0
    #print("k="+str(k))
    for l in range(D):
      #print("l="+str(l))
      dif = abs(L[j][l]-L[k][l])
      dif2 = dif**2
      #print(dif2)
      s = s + dif2
      #print("s="+str(s))
    s2 = s**(1/2)
    #print("s2="+str(s2))
    if float.is_integer(s2) == True:
      ans += 1
        
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n,d = list(map(int,input().split()))
t = np.array([list(map(int,input().split())) for i in range(n)])
cnt = 0

for i in range(n):
	for h in range(n):
		x = (sum((t[i]-t[h])**2))**0.5
		if x % 1 == 0:
			cnt += 1
			
print(int((cnt-n)/2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,d = map(int,input().split())
pts = []
for i in range(n):
    pts.append( [ int(i) for i in input().split() ])
def dist(a,b):
    ans = 0
    for i in range(len(a)):
        ans += (a[i]-b[i])**2
    y = int((ans)**0.5)
    if y**2 == ans:
        return True
    else:
        return False
ans = 0
for i in range(n):
    for j in range(i+1,n):
        ans += dist(pts[i],pts[j])
print(ans)

Submission status: Accepted

Solution code:
from math import sqrt

N, D = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N)]
cou = 0
for i in range(N):
    for j in range(N):
        ans = 0
        if i == j:
            continue
        for k in range(D):
            ans += abs(L[i][k] - L[j][k]) ** 2
        if sqrt(ans).is_integer():
            cou += 1
print(int(cou/2))

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):
    for j in range(i + 1, N):
        x = 0
        for k in range(D):
            x += (X[i][k] - X[j][k]) ** 2

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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


for i,pi in enumerate(points):
    if i==n-1:
        break
    for pj in points[i+1:]:
        distance = math.sqrt(sum([(x-y)**2 for x,y in zip(pi,pj)]))
        if distance%1==0:
            ans +=1
print(ans)

Submission status: Accepted

Solution code:
import math
a=input().split(" ")
N=int(a[0])
D=int(a[1])
vector=[]
for p in range(0,N):
    v=input().split(" ")
    vec=[]
    for q in range(0,D):
        vec.append(int(v[q]))
    vector.append(vec)
count=0
for r in range(0,N):
    for s in range(r+1,N):
        distance2=0
        for t in range(0,D):
            distance2+=(vector[r][t]-vector[s][t])**2
        if math.sqrt(distance2)%1==0:
            count+=1
print(count)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
l1=[]
for a in range(n):
    l=list(map(int,input().split()))
    l1.append(l)
count=0
for i in range(n-1):
    for j in range(i+1,n):
        sum2 = 0
        for k in range(d):
            sum2+=(l1[i][k]-l1[j][k])**2
        if (sum2**0.5)%1==0:
            count+=1
print(count)

Submission status: Accepted

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

for i in range(n):
    x[i] = list(map(int,input().split()))
for i in range(n-1):
    for j in range(n-1-i):
        j+=i+1
        check=0
        for k in range(d):
            check+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k])
        check=check**(1/2)
        if(check%1==0):
            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(0,N-1):
    for j in range(i+1,N):
        dis = math.sqrt(sum([(X[i][k]-X[j][k])**2 for k in range(D)]))
 
        if dis.is_integer():
            ans += 1
print(ans)

Submission status: Accepted

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

from math import sqrt

res = 0
for i in range(n):
    for j in range(i + 1, n):
        ci = coords[i]
        cj = coords[j]
        s = 0
        for k in range(d):
            s += (ci[k] - cj[k]) ** 2
        sq = sqrt(s)
        if sq.is_integer():
            res += 1
print(int(res))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

N, D = map(int, input().split())
point_list = list(list(map(int, input().split())) for i in range(N))
tmp = 0
output = 0

for k in range(N - 1):
    X = point_list[k]
    for l in range(k + 1, N):
        Y = point_list[l]
        for i in range(D):
            tmp += (X[i] - Y[i]) ** 2

        if math.sqrt(tmp).is_integer():
           output += 1

        tmp = 0

print(output)

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

        if dis.is_integer():
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
n, d = (int(i) for i in input().split())
num = list((list(map(int, input().split())) for j in range(n)))
sum = 0
cnt = 0
for k in range(n - 1) :
  for t in range(k + 1, n) :
    for h in range(d) :
      sum += (num[k][h] - num[t][h])**2
    work = sum**(1 / 2)
    temp = work * 10
    temp = temp % 10
    if temp == 0 :
      cnt += 1
    sum = 0
print(cnt)

Submission status: Accepted

Solution code:
import math
import itertools

n, d = map(int, input().split())
comb_list = list(range(n))
c = itertools.combinations(comb_list, 2)
l = []
count = 0
for i in range(n):
    array = list(map(int, input().split()))
    l.append(array)

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

print(count)

Submission status: Accepted

Solution code:
import itertools
import math
N, D = map(int, input().split())
cnt = 0
lst = []
for i in range(N):
    lst.append(list(map(int, input().split())))
for x, y in itertools.combinations(lst, 2):
    leng = 0
    for d in range(D):
        leng += (x[d] - y[d])**2
    leng = math.sqrt(leng)       
    if leng == int(leng):
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import math
from itertools import combinations
N,D = map(int,input().split())
X = [list(map(float, input().split())) for i in range(N)]
counter = [(sum([(a-b)**2 for a, b in zip(x0,x1)])**0.5).is_integer() for x0,x1 in combinations(X, 2)]
print(sum(counter))

Submission status: Accepted

Solution code:
import math
from itertools import combinations
N,D = map(int,input().split())
X = [list(map(float, input().split())) for i in range(N)]
counter = 0
for x0,x1 in combinations(X, 2):
    if math.sqrt(sum([(a-b)**2 for a, b in zip(x0,x1)])).is_integer():
        counter+=1
print(counter)

Submission status: Accepted

Solution code:
import math
from itertools import combinations
N,D = map(int,input().split())
X = [list(map(float, input().split())) for i in range(N)]
counter = 0
for x0,x1 in combinations(X, 2):
    if x0 == x1:
      continue
    if math.sqrt(sum([(a-b)**2 for a, b in zip(x0,x1)])).is_integer():
            counter+=1
print(counter)

Submission status: Accepted

Solution code:
import math
from itertools import product
N,D = map(int,input().split())
X = [list(map(float, input().split())) for i in range(N)]
counter = 0
for x0,x1 in product(X, repeat=2):
    if x0 == x1:
      continue
    if math.sqrt(sum([(a-b)**2 for a, b in zip(x0,x1)])).is_integer():
            counter+=1
print(counter//2)

Submission status: Accepted

Solution code:
import math
N,D = map(int,input().split())
X = [list(map(float, input().split())) for i in range(N)]
counter = 0
for i, x0 in enumerate(X): 
    for x1 in X[i+1:]:
        if math.sqrt(sum([(a-b)**2 for a, b in zip(x0,x1)])).is_integer():
            counter+=1
print(counter)

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())))
cnt = 0
for i in range(N-1):
    for j in range(i+1,N):
        nijo = 0
        for k in range(D):
            nijo += (X[i][k]-X[j][k])**2 
        cnt += int(math.sqrt(nijo)==int(math.sqrt(nijo)))
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(n):
    for j in range(i+1,n):
        dist=np.linalg.norm(x[i]-x[j])
        if dist==int(dist):
            cnt+=1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N,D = map(int,input().split())
X = [list(map(float, input().split())) for i in range(N)]
counter = 0
for i in range(N): 
    for j in range(i+1, N):
        if math.sqrt(sum([(a-b)**2 for a, b in zip(X[i],X[j])])).is_integer():
            counter+=1
print(counter)

Submission status: Accepted

Solution code:
N,D = list(map(int,input().split()))
X = []
for n in range(N):
    X.append(list(map(int,input().split())))
#N個のリスト入力を受け取る

cnt = 0

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

print(cnt)

Submission status: Accepted

Solution code:
import numpy as np

N,D = list(map(int,input().split()))
X = []
for n in range(N):
    X.append(list(map(int,input().split())))
#N個のリスト入力を受け取る

cnt = 0

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

print(cnt)

Submission status: Accepted

Solution code:
import numpy as np

N,D = list(map(int,input().split()))
X = []
for n in range(N):
    X.append(list(map(int,input().split())))
#N個のリスト入力を受け取る

vec = np.array(X)
#listをnumpyの行列型に変換
cnt = 0
for i in range(N):
    for j in range(i+1,N):
        dist = np.linalg.norm(vec[i]-vec[j])
        if dist.is_integer():
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:

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

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

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

Submission status: Accepted

Solution code:
n,d= map(int,input().split())
l = []
a = 0
def dis(l1,l2):
    c = 0
    for i in range(0,len(l1)):
        c = c+(l1[i]-l2[i])**2
    return c**0.5

for _ in range(n):
    l.append(list(map(int,input().split())))
for i in range(0,n-1):
    for j in range(i+1,n):
        if float(dis(l[i],l[j])).is_integer() == True:
            a = a + 1
print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def dis2(x, y):
  T = []
  for i in range(len(x)):
    T.append((int(x[i])-int(y[i])) ** 2)
  return sum(T)

n, d = map(int, input().split())
x_list = [input().split() for _ in range(n)]
ans = 0
for i in range(n):
  for j in range(i+1, n):
    R = dis2(x_list[i], x_list[j])
    for k in range(R+1):
      if k**2 == R:
        ans += 1
        continue

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n, d = map(int, input().split())
x = []
for i in range(n):
	x.append(np.array(list(map(int, input().split()))))

c = 0
for i in range(n-1):
	for j in range(i+1, n):
		if np.linalg.norm(x[i]-x[j]).is_integer():
			c += 1
print(c)

Submission status: Accepted

Solution code:
import numpy as np
n,d = map(int,input().split())
x = []
for i in range(n):
    x.append(np.array(list(map(int, input().split()))))
    
count = 0
for i in range(n-1):
  for k in range(i+1,n):
    if (np.linalg.norm(x[i]-x[k]))%1 == 0:
      count += 1
      
print(count)

Submission status: Accepted

Solution code:
import math
n,d=map(int,input().split())
L=[]
for i in range(n):
   L.append(list(map(int,input().split())))
c=0
for j in range(n):
    for k in range(j+1,n):
        s=pow(sum([(L[j][m]-L[k][m])**2 for m in range(d)]),0.5)
        if math.ceil(s)==math.floor(s):
            c+=1
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
a=[input().split() for i in range(N)]
c=0
for i in range(N-1):
  for j in range(i+1,N):
    b=0
    for m in range(D):
      b+=(int(a[i][m])-int(a[j][m]))**2
    if b**0.5==float(int(b**0.5)):
                    c+=1
print(c)

Submission status: Accepted

Solution code:
import numpy as np
n,d = [int(i) for i in input().split()]

l = []
for i in range(n):
    dots = [int(i) for i in input().split()]
    l.append(dots)
    
ans = 0
for i in range(len(l)):
    m = np.array(l.pop())
    for j in l:
        j = np.array(j) - m
        dist = np.sum(j**2)
        if np.sqrt(dist).is_integer():
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
from math import sqrt
from numpy import array 
import numpy as np

N,D = map(int,input().split())
Xlist = array([list(map(int,input().split())) for a in range(N)])
counter = 0
for j in range(N):
    for i in range(j):
        dis = sqrt(np.sum(np.power(Xlist[i]-Xlist[j],2)))
        if dis==int(dis):
            counter += 1

print(counter)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from math import floor, sqrt
n,d = map(int, input().split())
l = []
for _ in range(n):
	l.append(tuple(map(int, input().split())))
ans = 0
for i in range(n - 1):
	for j in range(i + 1, n):
		s = 0
		for k in range(d):
			s += (l[i][k] - l[j][k]) ** 2
		x = sqrt(s)
		if floor(x) == x:
			ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


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


result = 0

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

Submission status: Accepted

Solution code:
n, d = map(int, raw_input().split())
x = []
comb = []
for j in range(n):
    x.append(map(int, raw_input().split()))
    comb.append(j+1)

import itertools
x_comb = list(itertools.combinations(comb,2))

import numpy as np

c = 0

for i in range(len(x_comb)):
    if np.linalg.norm(np.array(x[x_comb[i][0]-1])-np.array(x[x_comb[i][1]-1])).is_integer() == True:
        c +=1

print(c)

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)])
ans = 0
Dist = 0

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

Submission status: Accepted

Solution code:
import numpy as np

N, D=map(int, input().split())
a=np.zeros((N, D))
for i in range(N):
  a[i, :]=list(map(int, input().split()))
  
counter=0
for i in range(N-1):
  for j in range(i+1, N):
    temp=pow(np.sum((a[i]-a[j])**2), 1/2)
    if temp-int(temp)==0:
      counter+=1
      
print(int(counter))

Submission status: Accepted

Solution code:
import numpy as np
X = []

N, D = map(int, input().split())
X = np.array([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 np.sqrt(np.sum((X[i] - X[j]) ** 2)).is_integer() == True:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
X = []

N, D = map(int, input().split())
for i in range(N):
    X = np.append(X, np.array(list(map(int, input().split()))))
X = np.reshape(X, (N, D))
ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
import math
N,D=map(int,input().split())
l=[]
anss=0
for i in range(N):
  a=list(map(int,input().split()))
  l.append(a)
for i in range(N):
  for j in range(i+1,N):
    ans=0
    for k in range(D):
      ans+=(l[i][k]-l[j][k])**2
    if (ans**0.5)%1==0:
      anss+=1
print(anss)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding:utf-8
import math
n, d = map(int, input().split())

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

#print(grid)
counter = 0

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

        #y^2がkと等しければ整数があることになる
        if int(round(math.sqrt(float(tmp)))**2) == tmp:
            counter += 1


print(counter)

Submission status: Accepted

Solution code:
N, D = map(int, input().split(" "))
X = [list(map(int, input().split(" "))) for i in range(N)]
dist = []
n = 0
while n * n <= 16000:
    dist.append(n * n)
    n += 1


def Dis(x, y):
    return sum([(a - b)**2 for a, b in zip(x, y)])


cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        dd = Dis(X[i], X[j])
        for d in dist:
            if dd == d:
                cnt += 1
                break
print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math
def isSquare(x):
    x_sqrt = int(math.floor(math.sqrt(x)))
    if x_sqrt * x_sqrt == x:
        return True
    else:
        return False

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

def solve(N: int, D: int, X: "List[List[int]]"):
    count = 0
    for i in range(N):
        for j in range(i+1, N):
            if isSquare(distSquare(X[i], X[j], D)):
                count += 1
    print(count)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    X = [ [ int(next(tokens)) for _ in range(D) ] for _ in range(N) ]  # type: "List[List[int]]"
    solve(N, D, X)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

def main():
    N, D = map(int, input().split())
    points = []
    for i in range(N):
        p = [int(c) for c in input().split()]
        points.append(p)

    count = 0
    for i in range(N-1):
        for j in range(i+1, N):
            v = 0
            for k in range(D):
                v += pow(points[i][k]-points[j][k], 2)
            vsqrt = math.sqrt(v)
            if int(vsqrt) == vsqrt:
                count += 1
    return count

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

Submission status: Accepted

Solution code:
import numpy as np
n ,d = map(int, input().split())
X = np.zeros((n,d) ,dtype=np.int) 

for i in range(n):
    X[i] = np.array( list(map(int,input().split())) )
cnt = 0
for j in range(n):
    for k in range(1,n-j):
        if (np.sqrt(sum((X[j] - X[j+k])**2))).is_integer():
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
def solve(X:list, N:int):
    cnt = 0
    for i in range(N):
        for j in range(i):
            dist = 0
            for a, b in zip(X[i], X[j]):
                dist += (a-b)**2
            if dist**.5%1 == 0:
                cnt += 1
    print(cnt)

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
List=[list(map(int,input().split())) for i in range(N)]
i=0
tmp=0 #2点間の距離
k=1 #整数確認
ans=0 #組数

for n in range(N):
    for m in range(n+1,N):
        for d in range(D): #D次元分繰り返す
            tmp+=(List[n][d]-List[m][d])**2
        while k**2 <= tmp:
            if k**2 == tmp:
                ans+=1
            k+=1
        tmp,k=0,0
print(ans)

Submission status: Accepted

Solution code:
input_data = input().split(" ")
N = int(input_data[0])
D = int(input_data[1])
p_data = [list(map(lambda x:int(x),input().split(" "))) for i in range(N)]
distance = []

for n in range(N):
  for t in range(n,N):
    if n == t:
      pass
    else:
      tes = list(map(lambda x,y:(x-y)**2,p_data[n],p_data[t]))
      dis = (sum(tes)**0.5).is_integer()
      distance.append(dis)

print(sum(distance))

Submission status: Accepted

Solution code:
## B - Good Distance(ABC133)
N,D=list(map(int, input().split()))
X=[]
A=0
B=[]
for i in range(N):
    X.append(list(map(int, input().split())))
for i in range(N):
    for v in range(i+1,N):
        A=0
        for x in range(D):
            A+=(X[i][x]-X[v][x])**2
            if x==D-1:
                B.append(A)
C=0
for i in B:
    for v in range(1,i+1):
        if i/v==v:
            C+=1
            break
print(C)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
table = []
for _ in range(N):
    row = list(map(int, input().split()))
    table.append(row)
cnt = 0
for i in range(N):
    for k in range(i+1, N):
        diff = 0
        for d in range(D):
            diff += (table[i][d] - table[k][d]) ** 2
        result = diff ** 0.5
        if float(int(result)) == result:
            cnt += 1
print(cnt)

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):
        sm = 0
        temp = 0
        for k in range(D):
            sm += (X[i][k] - X[j][k]) ** 2
        temp = sm ** 0.5
        if temp // 1 == temp:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

tmp = 0
ans = 0
  
for i,a in enumerate(point):
  for j in range(i+1,n):
    for k in range(d):
      tmp += (a[k]-point[j][k])**2
    if np.sqrt(tmp).is_integer():
      ans += 1
    tmp = 0
    
print(ans)