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 numpy as np

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

listX=[] #appendのために宣言が必要
while True:
    try:
        listX.append(list(map(int,input().split())))

    except:
        break;
        #または、quit(),os.exit()をして止める。
X=np.array(listX)
flag=0
for  i in range(N):
    for j in range(N):

        if i>=j:
            continue
        #print(i,j)
        dist=X[i,:]-X[j,:]
        dist=np.linalg.norm(dist)

        if dist%1==0:
            #print(dist)
            flag+=1
print(flag)

Submission status: Accepted

Solution code:
import numpy as np

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

for i in range(0,N):
  for j in range(i+1,N):
    vec_a=np.array(listX[i])
    vec_b=np.array(listX[j])
    Y=np.linalg.norm(vec_a - vec_b)
  
    if Y.is_integer()==True:
      
      if Y==0:
        next
      else:
        count+=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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())))
cnt = 0
for i in range(n):
	for j in range(i+1, n):
		sum = 0
		for k in range(d):
			s = (c[i][k]-c[j][k]) ** 2
			sum += s
		dist = math.sqrt(sum)

		if dist.is_integer():
			cnt += 1
			
print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import numpy as np

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

x = np.array(x)
count = 0
for i in range(N):
    for j in range(i+1, N, 1):
        diff_array = x[i] - x[j]
        diff = np.sqrt(np.sum(diff_array**2))
        if float(diff).is_integer():
            count += 1
print(count)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return list(map(float, sys.stdin.readline().split()))
def LS():return sys.stdin.readline().split()
def SR(n): return [list(sys.stdin.readline())[:-1] for i in range(n)]
def IR(n): return [int(sys.stdin.readline()) for i in range(n)]
def LIR(n): return [list(map(int, sys.stdin.readline().split())) for i in range(n)]
def LSR(n): return [list(map(list, sys.stdin.readline().split())) for i in range(n)]
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
sys.setrecursionlimit(1000000)
INF = float('inf')
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

N, D = LI()

X = LIR(N)

ans = 0
for xd1 in X:
    for xd2 in X:
        ret = 0
        for x1, x2 in zip(xd1, xd2):
            ret += (x2-x1)**2
        ret = math.sqrt(ret)
        ans += ret.is_integer()

print((ans-N)//2)

Submission status: Accepted

Solution code:
import math
n,d=map(int,input().split())
x,y,z=[],[],[]
flag=0
co=0
i,j,u=0,1,0
for l in range(n):
 x=x+(list(map(int,input().split())))
while i < n-1:
 while j < n:
  co+=1
  y=x[i*d:(i+1)*d]
  z=x[j*d:(j+1)*d]
  for l in range(len(y)):
   u+=(y[l]-z[l])*(y[l]-z[l])
  u=math.sqrt(u)
  if str(u)[len(str(u))-1] == "0":
   flag+=1
  u=0
  j+=1
 i+=1
 j=i+1
print(flag)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
import sys
import math
from pprint import pprint
import numpy as np

def solve(n, d, p):
  count = 0
  for i in range(n):
    for j in range(i, n):
      if i == j:
        continue
      #print(i, j)
      distance = math.sqrt(sum(map(lambda i: i ** 2, p[i] - p[j])))
      #pprint(distance)
      if float.is_integer(distance):
        count += 1

  return count


if __name__ == "__main__":
  n, d = map(int, sys.stdin.readline().rstrip().split(" "))
  p = []
  for _ in range(n):
    p.append(np.array(map(int, sys.stdin.readline().rstrip().split(" "))))

  #pprint(p)
  print solve(n, d, p)

Submission status: Accepted

Solution code:
import math as mt

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

xlis = [[0 for _ in range(D)] for _ in range(N)]

for i in range(N):
    inputlis = list(map(int, input().split()))
    for l in range(D):
        xlis[i][l] = inputlis[l]

cnt = 0

for i in range(N):
    for s in range(N):
        res = 0
        if i == s:
            continue
        for l in range(D):
           res += ((xlis[i][l] - xlis[s][l]) ** 2)

        if mt.sqrt(res).is_integer():
            cnt += 1


print(int(cnt/2))

Submission status: Accepted

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

cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        r = sum([(x[i][k] - x[j][k]) ** 2 for k in range(d)])
        for k in range(130):
            if (r == k ** 2):
                cnt += 1
                break

print(cnt)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
import math

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

c = []
for i in range(N):
    c.append(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 += (c[i][k] - c[j][k]) ** 2
    
        a = math.sqrt(a)
        if a.is_integer() == True:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
import math

N,D=input().split()

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

count=0

for i in range(int(N)):
    for j in range(i+1,int(N)):
        result1=0
        for k in range(int(D)):
            result1+=pow(x[i][k]-x[j][k],2)

        diff=math.sqrt(result1)
        if diff.is_integer():
            count+=1

print(count)

Submission status: Accepted

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

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

print(res)

Submission status: Accepted

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

for i in range(N):
    for j in range(i, N):
        if i != j:
            tmp = 0.0
            for k in range(D):
                tmp += abs(X[i][k] - X[j][k]) ** 2
            tmp = math.sqrt(tmp)
            if tmp.is_integer():
                result += 1

print(result)

Submission status: Accepted

Solution code:
import numpy as np
N,D=map(int,input().split())

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

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

print(count)

Submission status: Accepted

Solution code:
def issq(n):
    for i in range(2 * n):
        if i * i == n:
            return True
    return False
    

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

print(count)

Submission status: Accepted

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

X_list = list(list(map(int, input().split())) for _ in range(N))

# print(X_list)

ans = 0
for i in range(N-1):
    for j in range(N-i-1):
        double_s = 0
        S = 0
        for k in range(D):
            double_s += (X_list[i][k] - X_list[j+i+1][k]) ** 2

        S = math.sqrt(double_s)
        # print('SSSSS:', S)
        if(abs(S - int(S)) == 0):
            ans += 1


# S = math.sqrt(2**2)
# v = S - int(S)
# print(S - int(S))
# if(v > 0):
#     print('sss')

print(ans)

Submission status: Accepted

Solution code:
import math
N, D = map(int, input().split())
nlist = []
anslist = []
for i in range(N):
    llist = list(map(int, input().split()))
    nlist.append(llist)
a = 0
for x in range(N - 1):
    for i in range(x, N - 1):
        tmp = 0
        for j in range(D):
            tmp += (abs(nlist[x][j] - nlist[i + 1][j]) ** 2)
        anslist.append(int(math.sqrt(tmp)) - math.sqrt(tmp))

cnt = 0
for i in anslist:
    if i == 0.0:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import itertools


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

result = []
tmp = 0

for i in itertools.combinations(s, 2):
    tmp = [(x - y)**2 for (x, y) in zip(i[0], i[1])]
    tmp = sum(tmp)
    result.append(tmp)

result2 = []
for i in result:
    tmp = int(i ** 0.5)
    if abs(tmp*tmp - i) < 1e-6:
        result2.append(tmp)

print(len(result2))

Submission status: Accepted

Solution code:
import numpy as np

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

X = []

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

res = 0
X = np.array(X)
for i in range(N):
    for j in range(i + 1, N):
        if np.linalg.norm(X[i] - X[j]).is_integer():
            res += 1

print(res)

Submission status: Accepted

Solution code:
import math
a=input()
b=a.split()
b=list(map(int,b))
i = [input() for i in range(b[0])]
for o in range(b[0]):
    i[o]=i[o].split()
    i[o]=list(map(int,i[o]))
f=0
for p in range(b[0]-1):
    for g in range(b[0]-p-1):
        h=g+p+1
        c=0
        for j in range(b[1]):
            c+=(i[p][j]-i[h][j])*(i[p][j]-i[h][j])
        d=math.sqrt(float(c))
        if (d-int(d))==0:
            f+=1
print(f)

Submission status: Accepted

Solution code:
import sys 
import numpy as np 

def distance():
    N,D=map(int,input().split())
    y=[]
    ans=0
    for i in range(N):
        x=list(map(int,input().split()))
        y.append(x)
    y=np.array(y)
    y.reshape(N,-1)
    for i in range(N-1):
        for j in range(i+1,N):
            dis=(((y[i]-y[j])**2).sum())**(1/2)
            if dis.is_integer():
                ans+=1
    
    print(ans)

distance()

Submission status: Accepted

Solution code:
import numpy as np
N, D = map(int, input().split())
X = []
count = 0
for i in range(N):
    x = list(map(int, input().split()))
    X.append(x)
for j in range(N-1):
    X1 = X[j]
    for k in X[j+1:]:
        X2 = k
        XXX = 0
        for l in range(D):
            XX = (X1[l]-X2[l])**2
            XXX += XX
        XXXX = np.sqrt(XXX)
        if XXXX.is_integer() == True:
            count += 1
print(count)

Submission status: Accepted

Solution code:
import math

def dist(X1,X2):
  d=[abs(X1[i]-X2[i]) for i in range(len(X1))]
  d=[x**2 for x in d]
  d=sum(d)
  d=math.sqrt(d)
  return d
 
count=int(0)
N,D=map(int,input().split())
X=list(range(N))
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=dist(X[i],X[j])
    if d.is_integer():
      count=count+1
print(count)

Submission status: Accepted

Solution code:
import numpy as np
n, d = map(int, input().split())
x = []
for _ in range(n):
    a = list(map(int, input().split()))
    x.append(a)
#print(x)
cnt = 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])*(x[i][k]-x[j][k])
            #print((x[i][k]-x[j][k])*(x[i][k]-x[j][k]))
            #print(s)
        s = np.sqrt(s)
        #print(s)
        if s//1 == s:
            
            cnt += 1
print(cnt)

Submission status: Accepted

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

import numpy as np
from scipy.spatial import distance

distance = distance.cdist(data, data, metric='euclidean')
count = 0
for n in range(0,N):
  for d in range(n+1,N):
    if distance[n][d].is_integer() and distance[n][d] != 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())))

cnt = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        d = 0
        for xi, xj in zip(X[i], X[j]):
            d += (xi - xj)** 2
        if d ** (1 / 2) == int(d ** (1 / 2)):
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math
def dis(a, b):
    res = 0
    for i in range(len(a)):
        res += math.pow(a[i] - b[i], 2)
    return math.sqrt(res)

def main():
    N, D = [int(n) for n in input().split()]
    points = []
    res = 0
    for _ in range(N):
        points.append([int(a) for a in input().split()])
    for i in range(N):
        for j in range(i+1, N):
            if float.is_integer(dis(points[i], points[j])):
                res += 1
    print(res)
main()

Submission status: Accepted

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

for i in range(N):
    a = input().split()
    a = [int(i) for i in a]
    point.append(a)
ans = 0

for p1 in range(0,len(point)-1):
    for p2 in range(p1+1, len(point)):
        if numpy.linalg.norm(numpy.array(point[p2]) - numpy.array(point[p1])).is_integer():
            ans += 1
    
print(ans)

Submission status: Accepted

Solution code:
import math

def cul(a,b,d):
    num = 0
    for i in range(d):
        num += (a[i] - b[i]) ** 2
    return math.sqrt(num)

N,D = map(int,input().split())
X = []
count = 0
d = 0
for i in range(N):
        X.append(list(map(int,input().split())))
for i in range(N):
    for j in range(i+1,N):
        if(i != j):
            d = cul(X[i],X[j],D)
        if (d - int(d)) == 0.0:
            count += 1

print(count)

Submission status: Accepted

Solution code:
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) :
        x = X[i]
        y = X[j]
        dist = 0
        for k in range(D) :
            dist += (x[k] - y[k])**2
        b = int(dist**0.5)
        if abs(b**2 - dist) < 1e-10 :
            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)]
#pair = []

cnt = 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
    sum = pow(sum,1/2)
    #print(111,sum)
    if sum == int(sum):
      cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
N, D = map(int, input().split())
coords = np.array([np.array([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):
    a = coords[i]
    b = coords[j]
    d = np.linalg.norm(a-b)
    ans += d == d.astype(np.integer)
    
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-1):
    for j in range(i+1, n):
        cnt = 0
        for y, z in zip(x[i], x[j]):
            cnt += abs(y-z)**2
        if cnt ** 0.5 % 1 == 0:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
import math

a1=list(input().split( ))
a=list(map(int, a1))

b = [input().split() for l in range(a[0])]
g=0
for j in range(a[0]):
 for k in range( a[0] - j  - 1 ):
  c=0
  for m in range(a[1]):
   c  +=  ( int(b[j][m]) - int(b[j + k+1][m]) )**2
  d = float(math.sqrt(c))
  e = float(int(d))
  if e==d:
   g += 1

print(g)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

ans = 0
for i in range(N):
    for j in range((N - i) - 1):
        A = 0
        if N - i == 0:
            continue
        for k in range(D):
            B = 0
            point1 = X[i][k]
            point2 = X[(i + j) + 1][k]
            B = B + point1 - point2
            A = A + pow(B, 2)
        C = math.sqrt(A)
        if C.is_integer():
            ans = ans + 1

print(ans)

Submission status: Accepted

Solution code:
def get_distance(x, y, d):
    result = 0
    for i in range(d):
        result += (x[i] - y[i]) ** 2
    return result

def is_2jou(i):
    ii = i ** 0.5
    if ii == float(round(ii)):
        return True
    else:
        return False

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

    cnt = 0
    for _ in range(len(x)):
        head = x.pop(0)
        for j in x:
            distance = get_distance(head, j, d)
            flag = is_2jou(distance)
            if flag:
                cnt += 1

    print(cnt)

main()

Submission status: Accepted

Solution code:
import numpy as np
N,M  = map(int,input().split())

num_l=[]

for i in range(N):
  d=list(map(int,input().split()))
  num_l.append(d)
         
num_2=np.array(num_l)


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

Submission status: Accepted

Solution code:
import itertools

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

_result = 0
_sum = 0
for i in itertools.combinations(range(N),2):
    for j in range(D):
        _result += abs(lst[(i[0])][j] - lst[(i[1])][j])**2
    if (_result ** 0.5).is_integer():
        _sum += 1
    _result = 0
print(_sum)

Submission status: Accepted

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

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

    dist = dist ** 0.5

    return dist

for i in range (N):
    a = X[i]
    B = X[:i] + X[i+1:]

    for b in B:
        d = distance(a, b)
        if d == d // 1:
            ans += 1

print(ans // 2)

Submission status: Accepted

Solution code:
import math

nd = [int(i) for i in input().split()]
x = []
for i in range(nd[0]):
    tmp = [int(i) for i in input().split()]
    x.append(tmp)
result = 0
for i in range(nd[0]):
    for j in range(i+1, nd[0]):
        before_root = 0
        for k in range(len(x[0])):
            before_root += (x[i][k] - x[j][k])**2
        if math.sqrt(before_root).is_integer():
            result += 1
print(result)

Submission status: Accepted

Solution code:
import itertools
import math


def calcDistanceIsInt(p1, p2):
    sum = 0
    for i in range(len(p1)):
        sum += math.pow(abs(p1[i] - p2[i]), 2)

    sq = math.sqrt(abs(sum))
    if sq.is_integer():
        return True
    else:
        return False


nd = list(map(int, input().split()))
n, d = nd[0], nd[1]

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

# print(points)
# print(list(itertools.combinations(points, 2)))

int_count = 0
for i in list(itertools.combinations(points, 2)):
    # print(i[0], i[1])
    # print(calcDistanceIsInt(i[0], i[1]))
    if calcDistanceIsInt(i[0], i[1]):
        int_count += 1
print(int_count)

Submission status: Accepted

Solution code:
# coding: utf-8
import itertools
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]

cnt = 0
for c in list(itertools.combinations(x,2)):
        dist = 0
        for i in range(d):
                dist += (c[0][i]-c[1][i])**2
        dist = dist**0.5
        if dist.is_integer():
                cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math
n, d = [int(s) for s in input().split(" ")]
pts = []
for _ in range(n):
  pts.append([int(s) for s in input().split(" ")])

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

cnt = 0
for i in range(n):
  for j in range(i + 1, n):
    d = dist(pts[i], pts[j])
    if int(d) == d:
      cnt += 1

print("%d" % cnt)

Submission status: Accepted

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

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

for i in range(N-1):
	x = list(map(int, input().split()))
	length = len(l)
	for j in range(math.floor(length/D)):
		num = 0
		for k in range(D):
			num += (x[k] - l[(j*D)+k]) ** 2
			if k == D - 1 and (math.sqrt(num)).is_integer() == True:
				cnt += 1
			if (j == math.floor(length/D) -1):  
				l.append(x[k])

print(cnt)

Submission status: Accepted

Solution code:
# B
import math
N, D = map(int,input().split())
X = [[int(i) for i in input().split()] for i in range(N)] 

answer = 0

def distance(x, a, b):
    list = []
    for d in range(D):
        list.append((x[a][d] - x[b][d])**2)
    r = math.sqrt(sum(list))
    return r


# 整数判定
def isinteger(x):
    if isinstance(x, float):
        return x == int(x)

for j in range(N):
    for i in range(j+1,N):
        # print(j, i)
        # print(distance(X, i, j))
        if isinteger(distance(X, i, j)):
            answer = answer + 1

print(answer)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
list_a = []
for i in range(n):
    List = [int(j) for j in input().split()]
    list_a.append(List)
    
#print(list_a)

ans=0
for i in range(n):
    for j in range(i+1,n):
        kyorino2zyou=0
        for k in range(d):
            kyorino2zyou=kyorino2zyou+(list_a[i][k]-list_a[j][k])**2
            kyori=(kyorino2zyou)**(1/2)
            kyori2=int(kyori)
           # print(kyori)
          
        if kyori2-kyori==0:
                ans=ans+1
print(ans)

Submission status: Accepted

Solution code:
import itertools
import math
N, D = map(int, input().split())
A = [[int(i) for i in input().split()] for j in range(N)]
B = [int(j) for j in range(N)]

count = 0
for x in itertools.combinations(B, 2):
    abs_A =[(A[x[0]][l]-A[x[1]][l])**2 for l in range(D)]
    if math.sqrt(sum(abs_A))%1 == 0 :
        count+=1
    else:
        count+=0
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(N):
        if i == j:
            continue
        else:
            tmp = 0
            for k in range(D):
                tmp += (x[i][k] - x[j][k]) ** 2
            dis = tmp ** 0.5
            if dis.is_integer():
                ans += 1
print(int(ans / 2))

Submission status: Accepted

Solution code:
n,d = map(int,input().split())
lid,a,dis,b = [],0,[],[]
import itertools
for i in range(n):
    lid.append(list(map(int, input().split())))

dis = list(itertools.combinations(lid,2))

for i in range(len(dis)):
    for j in range(d):
        a += (dis[i][0][j]-dis[i][1][j])**2
        #print(a)
    a = a**0.5
    b.append(a)  
    a = 0
    
ans = 0
for i in range(len(b)):
    if b[i]%1 == 0:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        #または、quit(),os.exit()をして止める。

count = 0
for i in range(n):
    for j in range(n):
        if(i < j):
            dis = 0
            for k in range(d):
                dis += (listA[i][k]-listA[j][k]) ** 2
            dis = np.sqrt(dis)
            #if(dis.is_integer()):
            if( dis/int(dis) == 1 ):
                count += 1


print(count)

Submission status: Accepted

Solution code:
import math

vectors = list()

n, d = (int(x) for x in input().split())
for c in range(n):
    vectors.append([int(x) for x in input().split()])

counter = 0

for i in range(n-1):
    for j in range(i+1, n):
        distance = math.sqrt(sum([
            (vectors[i][k] - vectors[j][k]) ** 2 for k in range(d)
            ]))
            
        if float(distance).is_integer():
            counter += 1

print(counter)

Submission status: Accepted

Solution code:
import math
x = 0
num = list(map(int,input().split()))
n = [list(map(int, input().split())) for i in range(num[0])]
for i in range(num[0]):
  k=1
  while i+k < num[0]:
    dd = 0
    for l in range(num[1]):
      dd += (n[i][l] - n[i+k][l]) ** 2      
    d = math.sqrt(dd)
    k += 1
    if d.is_integer() == True:
      x += 1
print(x)

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
dis=0
if d==1:
    print(n*(n-1)//2)
else:
    for i in range(n-1):
        for j in range(i+1,n):
            distance=0
            dis=0
            for k in range(d):
                dis+=(x[i][k]-x[j][k])**2
            distance=math.sqrt(dis)   
            if distance.is_integer()==True:
                cnt+=1
    print(cnt)

Submission status: Accepted

Solution code:
import math
N, D = map(int, input().split())
points = []
count = 0
for i in range(N):
    points.append(list(map(int,input().split())))
for j in range(len(points)-1):
    for k in range(j+1,len(points)):
        sum = 0
        for l in range(D):
            sum += abs(points[j][l] - points[k][l])**2
        if math.sqrt(sum).is_integer():
            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())))

import itertools

ans = 0

for v in itertools.combinations(x, 2):
  a, b = v
  n = 0
  for i in range(d):
    n += (a[i] - b[i]) ** 2
  n = n ** 0.5
  if str(n)[-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)]
a = 0
for i in range(len(x)):
    for j in range(i+1, len(x)):
        t = 0
        for k in range(d):
            t += (x[i][k]-x[j][k])**2
        if float.is_integer(t**0.5):
            a += 1
print(a)

Submission status: Accepted

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

cnt=0
for n in range(N):
    for nn in range(N):
        if n==nn:
            continue
        else:
            a=[]
            for d in range(D):
                a.append((x[n][d]-x[nn][d])**2)
            c=math.sqrt(sum([abs(i) for i in a]))
            if c%1==0:
                cnt+=1
print(int(cnt/2))

Submission status: Accepted

Solution code:
import itertools


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


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

cnt = 0
for a, b in itertools.combinations(x, 2):
    if is_integer(sum([(ad - bd) ** 2 for ad, bd in zip(a, b)]) ** 0.5):
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import itertools
import math

n,d = map(int,input().split())
x = [[int(i) for i in input().split()] for i in range(n)] 
seq = list(itertools.combinations(range(n),2))
tmp = 0.0
cnt = 0
for i,j in seq:
    for k in range(d):
        tmp += (x[i][k] - x[j][k])**2
    tmp = math.sqrt(tmp)
    if tmp.is_integer():
        cnt += 1
    tmp = 0.0
print(cnt)