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:
# -*- coding: utf-8 -*-

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

cnt = 0
for i in range(N-1):
    p1 = cor[i]
    for j in range(1, N-i):
        p2 = cor[i+j]
        tmp = 0
        for k in range(D):
            tmp += (p1[k] - p2[k]) ** 2
        if float.is_integer(tmp ** 0.5):
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import sys
import math


def main():
    N, D = [int(s) for s in sys.stdin.readline().strip().split()]
    X = []
    for i in range(N):
        Xi = [int(s) for s in sys.stdin.readline().strip().split()]
        X.append(Xi)

    sqrts = set()
    sqrts.add(0)

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

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

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
N,D = map(int,input().split())
X_s = [list(map(int,input().split())) for _ in range(N)]
answer = 0
for i in range(N-1):
  for j in range(i+1,N):
    dist = 0
    for k in range(D):
      dist += abs(X_s[i][k] - X_s[j][k])**2
    if int(dist**0.5)**2 == dist:
      answer += 1
print(answer)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
import math
"""
def distance(a,b):
    ans=0
    for (i,j) in zip(a,b):
        ans+=(i-j)**2
    return math.sqrt(ans)
"""
n,d=map(int,input().split())
x=[]
for j in range(n):
    tmp=list(map(int,input().split()))
    x.append(tmp)

count=0
for i in range(n-1):
    for j in range(i+1,n):
        ans=0
        for (a,b) in zip(x[i],x[j]):
            ans+=(a-b)**2
        if math.sqrt(ans).is_integer():
            count+=1

print(count)

Submission status: Accepted

Solution code:
nd = list(map(int,input().split()))
n = nd[0]
d = nd[1]
point = []
for i in range(n):
  point.append(list(map(int, input().split())))

def dis(y,z,dim):
  sum = 0
  for i in range(dim):
    sum += (y[i] - z[i])**2

  return sum**(1/2)

count = 0

for i in range(n-1):
  for j in range(i+1, n):
      distance = dis(point[i], point[j], d)
      if distance == int(distance):
          count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

X = []

for _ in range(N):
    X.append([int(x) for x in input().split(' ')])


def kyori(x, y, D):
    sum = 0
    for i in range(D):
        sum += (x[i] - y[i]) * (x[i] - y[i])
    return math.sqrt(sum)


count = 0
for i in range(N):
    for j in range(N):
        if i < j:
            if float.is_integer(kyori(X[i], X[j], D)):
                count += 1

print(count)

Submission status: Accepted

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

ans = 0
temp = 0

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


for i in range(1,N):
    for j in range(i):
        temp = 0
        for k in range(D):
            temp += (C[i][k] - C[j][k])**2
        dis = math.sqrt(temp)
        if is_integer_num(dis):
            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)]
s = 0
cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(d):
            s += abs(x[i][k] - x[j][k]) ** 2
        if s ** 0.5 == int(s ** 0.5):
            cnt += 1
        s = 0
print(cnt)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np


# なんこか入力
n,d = map(int, input().split())

# n行の複数列ある数値を二次元配列へ。x[n][?]
x = [[int(i) for i in input().split()] for i in range(n)] 
#print(x)
answer = 0
for j in range(n):
    for i in range(j):
        dist2 = 0
        for k in range(d):
            dist2 += (x[i][k]-x[j][k]) * (x[i][k]-x[j][k])
#            print(dist2)
        dist = math.sqrt(dist2)
#        print(dist)
#        if dist.is_integer() == "True" :
        if round(dist)*dist == dist2:
            answer += 1

print(answer)

Submission status: Accepted

Solution code:
import numpy as np

hoge = input().split()
N = int(hoge[0])
D = int(hoge[1])
X = []
hage = []
for i in range(N):
  huga = input().split()
  for j in range(D):
    hage.append(int(huga[j]))
  X.append(hage)
  hage = []

count = 0
huga = 0
for i in range(N):
  for j in range(i+1,N):
    for k in range(0,D):
      huga += pow(X[i][k] - X[j][k],2)
    if np.sqrt(huga).is_integer() == True:
      count += 1
    huga = 0
    
print(count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n,d=map(int,input().split())
x=[]
for _ in range(n):
    x.append(list(map(int,input().split())))
count=0
distance=0
for i in range(n):
    for j in range(i+1,n):
        distance=[(x[i][m]-x[j][m])**2 for m in range(d)]
        if sum(distance)**(1/2)==int(sum(distance)**(1/2)):
            count=count+1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
import math
import itertools

N, K = [int(x) for x in stdin.readline().rstrip().split()]
data = [stdin.readline().rstrip().split() for _ in range(N)]
for idx in range(N):
    data[idx] = [int(n) for n in data[idx]]

data_tmp = list(itertools.combinations(data,2))
cnt = 0
for idx, item in enumerate(data_tmp):
    dst = 0
    for n in range(K):
        dst = dst + pow(item[0][n] - item[1][n], 2)
    dst = math.sqrt(dst)
    i = int(dst)
    f = dst - i
    if f == 0.0:
        cnt = cnt + 1
print(cnt)

Submission status: Accepted

Solution code:
from itertools import combinations
from math import sqrt

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

XVS = []

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

C = 0
for i, j in combinations(range(N), 2):
    D2 = 0
    for d in range(D):
        D2 += (XVS[i][d] - XVS[j][d]) ** 2
    D1 = sqrt(D2)
    if D1.is_integer():
        C += 1

print(C)

Submission status: Accepted

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

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

def euclidian(l1, l2): 
    d = 0
    for i in range(D):
        d += (l1[i] - l2[i])**2
    return d**0.5

for i in range(N):
    for j in range(i+1, N):
        list_1 = X_list[i]
        list_2 = X_list[j]
        if euclidian(list_1, list_2).is_integer():
            result += 1

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

N, D = map(int, input().split())
x_list = [ [] for n in range(N)]
for n in range(N):
    x_list[n] = list(map(int, input().split()))

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

print(count)

Submission status: Accepted

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

ans = 0
import math
for i in range(N):
    for x in X_list[i+1:]:
        result = 0
        for j in range(D):
            result += (X_list[i][j]- x[j]) ** 2
        if math.sqrt(result).is_integer():
            #print(result,'result')
            #print(math.sqrt(result),'result')
            ans +=1

print(ans)

Submission status: Accepted

Solution code:
import math

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


def solve(n, d, x_matrix):
    result = 0
    for i in range(n):
        for j in range(n - i -1):
            distance = math.sqrt(sum([(p1 - p2) ** 2 for p1, p2 in zip(x_matrix[i], x_matrix[j + i + 1])]))
            if distance == int(distance):
                result += 1
    return result


def main():
    n, d, x_matrix = input_from_console()
    print(solve(n, d, x_matrix))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import decimal
import math
n,d = list(map(int,input().split()))
x = [list(map(lambda x:decimal.Decimal(int(x)),input().split())) for i in range(n)]

def calc_distance(arr1,arr2):
    return math.sqrt(sum(list(map(lambda x,y:(x-y)**2,arr1,arr2))))
ret = 0
for i in range(n):
    for j in range(i):
        if calc_distance(x[i],x[j])%1==0.0:
            ret+=1
print(ret)

Submission status: Accepted

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

cnt = 0

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

Submission status: Accepted

Solution code:
import numpy as np
n,d=map(int,input().split())
x=[list(map(int, input().split())) for _ in range(n)]
x=np.array(x)
count=0
for i in range(n):
  for j in range(i+1,n):
    f=np.dot((x[i,:]-x[j,:]),(x[i,:]-x[j,:]))**0.5
    if f.is_integer():
      count+=1
print(count)

Submission status: Accepted

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

tmp = []
sum = 0
for i in range(n):
    for j in range(n):
        if j != i:
            for a in range(d):
                sum += abs(x[i][a]-x[j][a])**2
            tmp.append(sum)
            sum = 0
ans = 0
for i in tmp:
    if sqrt(i).is_integer(): ans += 1
print(ans//2)

Submission status: Accepted

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

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

S=[n**2 for n in range(1,130)]

c=0

for i in range(N):
    for j in range(i,N):
        d=0
        for k in range(D):
            d+=(X[i][k]-X[j][k])**2
        for k in range(129):
            if d==S[k]:
                c+=1

print(c)

Submission status: Accepted

Solution code:
import numpy as np
import itertools

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

cnt = 0
for a, b in itertools.combinations(arr, 2):
    a = np.array(a)
    b = np.array(b)
    diff = a - b
    diff = diff ** 2
    distance = diff.sum() ** 0.5
    if distance == int(distance):
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import math
d=input().split()
N,D=int(d[0]),int(d[1])
l=[None]*N
for i in range(N):
  l[i]=input().split()
  for j in range(D):
    l[i][j]=int(l[i][j])
a=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
    if math.sqrt(s)==math.sqrt(s)//1:
      a+=1
print(a)

Submission status: Accepted

Solution code:
import numpy as np
import itertools
n, d = map(int, input().split())
arr = np.zeros((n, d))
ans = 0
for i in range(n):
  arr[i] = np.array(input().split())
for i in list(itertools.combinations(arr, 2)):
  u = i[0] - i[1]
  d = str(np.linalg.norm(u))
  if d[-1]=='0':
    ans += 1
print(ans)

Submission status: Accepted

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

ans = 0

def ks(x,y):
    p = 0
    for i in range(D):
        p += (x[i]-y[i])**2
    return p**(1/2)



for j in range(N):
    for k in range(N-j-1):
        l = ks(X[j], X[-k-1])
        if l % 1 == 0:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
a = input().split()
list_dist = []
for i in range(int(a[0])):
    b = input().split()
    b = [int(i) for i in b]
    list_dist.append(b)


count = 0
for i in range(int(a[0])):
    for u in range(i):
        list_kari = [list_dist[i][t]-list_dist[u][t]
                     for t in range(len(list_dist[i]))]
        num = sum([i ** 2 for i in list_kari])
        num = num**0.5
        if num.is_integer():
            count += 1
print(count)

Submission status: Accepted

Solution code:
import math

n, d = map(int, input().split())
l = [[int(x) for x in input().split()] for y in range(n)]

cnt = 0

for i in range(n):
    for j in range(n):
        if i ==j:
            continue
        dis_nijo = 0
        for k in range(d):
            dis_nijo += (l[i][k] - l[j][k]) **2
            dis = math.sqrt(dis_nijo)
        if dis ==int(dis):
            cnt += 1

print(cnt//2)

Submission status: Accepted

Solution code:
import numpy as np
n,d = map(int, input().split())
arr = np.empty((0,d), int)
for i in range(n):
  x = np.array(list(map(int, input().split()))).reshape(1,d)
  arr = np.append(arr, x, axis = 0)
lst = []
for i in range(1,n):
  for j in range(i):
    y = sum((arr[i]-arr[j])**2)**0.5
    if y%1 == 0:
      lst.append(y)
print(len(lst))

Submission status: Accepted

Solution code:
R = lambda: map(int, input().split())
sq = lambda x: int(x ** 0.5) ** 2 == x
d2 = lambda x, y: sum((u - v) ** 2 for u, v in zip(x, y)) 
n, d = R()
a = [tuple(R()) for _ in range(n)]
print(sum(sq(d2(a[i], a[j])) for i in range(n) for j in range(i)))

Submission status: Accepted

Solution code:
import queue

"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""

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

def dist(A,B,D):
	C = 0
	for i in range(D):
		C += (A[i]-B[i])**2
	return C**.5
ans = 0
for i in range(N-1):
	for j in  range(i+1, N):
		dis = dist(X[i],X[j],D)
		if dis == int(dis):
			ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math
import numpy as np
n,d=map(int,input().split())
c=0
p=[list(map(int,input().split())) for _ in range(n)]
for i in range(n):
  for j in range(n-i):
    j+=i
    d1=np.array(p[i])
    d2=np.array(p[j])
    if i==j:
        continue
    q=math.sqrt(sum((d2-d1)**2))
    if q==int(q):
      c+=1
print(c)

Submission status: Accepted

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

import math
ans = 0
for i in range(N-1):
  for j in range(i+1, N):
    ck = 0
    for k in range(D):
      ck += (X[i][k] - X[j][k])**2
    if math.sqrt(ck).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 = list(map(int,input().split()))
    X.append(x)

def caldist(a, b, n):
    sum = 0
    for i in range(n):
        sum +=abs(a[i]-b[i])**2
    ans = sum**(0.5)
    return ans

c=0
for i in range(N-1):
    for j in range(i+1,N):
        ans = (caldist(X[i],X[j],D))
        if ans.is_integer():
            c+=1

print(c)

Submission status: Accepted

Solution code:
import math

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

count = 0
for i in range(n):
    for j in range(i,n):
        if (i == j):
            continue
        dist = 0
        for dd in range(d):
            dist += math.pow(x[i][dd] - x[j][dd], 2)
        dist = math.sqrt(dist)
        if dist == int(dist):
            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)]


A = [i**2 for i in range(1,201)]


ans = 0

for i in range(N-1) :
    for j in range(i+1,N) :
        calc = 0
        for k in range(D) :
            calc += (X[i][k] - X[j][k])**2
        
        if calc in A :
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

int_cnt = 0
for i in range(len(Xs)-1):
    for j in range(i+1,len(Xs)):
        X = Xs[i]-Xs[j]
        s = 0
        for k in range(D):
            s += X[k]**2
        if (s**(1/2)).is_integer() == True:
            int_cnt += 1
print('{}'.format(int_cnt))

Submission status: Accepted

Solution code:
import math
n,d = list(map(int,input().split()))
List = []
for i in range(n):
	List.append(list(map(int,input().split())))
count = 0
for i in range(n):
	for j in range(n):
		if(i < j):
			s = 0
			for k in range(d):
				s = s + (List[i][k] - List[j][k]) * (List[i][k] - List[j][k])
			if(math.sqrt(s).is_integer()):
				count = count + 1
print(count)

Submission status: Accepted

Solution code:
import math
n,d=map(int,input().split())
x=[]
for i in range(n):
    s=list(map(int,input().split()))
    x+=[s]
rote=0
ans=0
for i in range(n):#i番目の点を決める
    for j in range(n):#j番目の点を決める
        for y in range(d):
            rote+=(x[i][y]-x[j][y])**2
        roteans=math.sqrt(rote)
        if rote==0:
            break
        elif roteans%1==0:
            ans+=1
        rote=0
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N,D = map(int,input().split())
XD = [list(map(int,input().split()))  for i in range(N)]
dis = 0
count = 0
for i in range(N):
    for j in range(N-i):
        if j == 0:
            continue
        for k in range(D):
            dis += (abs(XD[i][k]-XD[j+i][k]))**2
        if int(np.sqrt(dis)) == np.sqrt(dis):
            count += 1
        dis = 0

print(count)

Submission status: Accepted

Solution code:
import copy
import sys
from bisect import bisect_left, bisect_right
from collections import ChainMap, Counter, deque, defaultdict, namedtuple
from fractions import gcd
from heapq import heappop, heappush
from itertools import accumulate
from math import ceil, floor, sqrt
from operator import itemgetter

# sys.setrecursionlimit(10**6)


tolerance = 1e-30


def is_dist_int(x, y):
    d = 0
    
    for i in range(len(x)):
        d += (x[i] - y[i]) ** 2

    e = floor(sqrt(d)) ** 2

    return abs(d - e) < tolerance


def main():
    n, d = [int(x) for x in input().split(' ')]

    xs = [[int(x) for x in input().split(' ')] for _ in range(n)]

    count = 0

    for i in range(n):
        for j in range(i + 1, n):
            x = xs[i]
            y = xs[j]
            if is_dist_int(x, y):
                count += 1

    print(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# B - Good Distance
import math

N, D = map(int, input().split())
p = [[0 for n in range(D)] for m in range(N)]
#print(p)

for i in range(N):
    input_line = input().split(' ')
    p_line = [int(s) for s in input_line]
    for j in range(D):
        p[i][j] = p_line[j]

#print(p)
cnt = 0
for i in range(N):
    for j in range(i,N):
        if i == j:
            continue

        distance = 0
        for k in range(D):
            distance += (p[i][k] - p[j][k])**2
        distance = math.sqrt(distance)
        #print(i,j,distance)
        if distance.is_integer():
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np 

def main():
    n,d=map(int,input().split())
    
    x=[]
    for i in range(n):
        tmp=list(map(int,input().split()))
        x.append(np.array(tmp))
    
   # print(x)

    cnt=0
    
    for k in range(n-1):
        for l in range(k+1,n):
            dist=np.sqrt(np.sum((x[k]-x[l])*(x[k]-x[l])))

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

    print(cnt)

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/local/bin/python3
#coding:utf-8
import numpy as np


def main():

   in0 = input()

   IN = in0.split(' ')

   N = int(IN[0])
   D = int(IN[1])

   X = np.zeros((N,D))

   for i in range(N):
      in0 = input()
      IN = in0.split(' ')
      for j in range(D):
         X[i,j] = int(IN[j])


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

         dist = np.sqrt(dis)

         i_dist = int(dist)

         if((dist - i_dist)==0):
            cnt = cnt + 1


   print ("%s" % (cnt))




if __name__ == "__main__":
   main()

Submission status: Accepted

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

l = []

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

# 入力取得

# カウントする

cnt = 0

# 二重for

for i in range(n) :
#	print(i,l[i])
	for j in range (i+1,n):
#		print(i,j,l[j])
		s = 0
		
		for k in range(d):
#			print(d,l[i][d],l[j][d])
			s += ( l[i][k] - l[j][k]) ** 2 
		result = s ** (1/2)

		if result.is_integer():
			cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math

s = input().rstrip().split(' ')
N = int(s[0])
D = int(s[1])

cnt = 0
d_list = []

for i in range(N):
  d_list.append(input().rstrip().split(' '))

for i in range(N-1):
  for n in range(i+1, N):
    num = 0
    for d in range(D):
        num += (int(d_list[i][d]) - int(d_list[n][d])) ** 2
    
    test = math.sqrt(num)
    
    if test.is_integer():
      cnt += 1
    
print(cnt)

Submission status: Accepted

Solution code:
import math
import itertools

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

X = []

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

def kyori2jou(p1, p2):
    sum = 0
    for x1, x2 in itertools.zip_longest(p1, p2):
        sum += (x1 - x2) ** 2
    return sum

count = 0
for i in range(len(X)):
    for j in range(i+1, len(X)):
        p1 = X[i]
        p2 = X[j]
        if p1 == p2:
            continue
        k2 = kyori2jou(p1, p2)
        k1 = math.sqrt(k2)
        k1int = round(k1)
        if k2 == k1int**2:
            count += 1

print(count)

Submission status: Accepted

Solution code:
import numpy as np


def calc(mat: np.array) -> int:
    count = 0
    for alpha in range(mat.shape[0] - 1):
        for beta in range(alpha + 1, mat.shape[0]):
            distance = np.linalg.norm(mat[alpha] - mat[beta])
            if np.abs(distance - int(distance)) < 0.001:
                count += 1
    return count


def load_input_as_int_array():
    return [int(v) for v in input().split(" ")]


n, d = load_input_as_int_array()
mat = []
for i in range(n):
    raw = load_input_as_int_array()
    mat.append(raw)

mat_array = np.asarray(mat)
print(calc(mat_array))

Submission status: Accepted

Solution code:
def kyori(l1,l2):
    l=sum([(l1[i]-l2[i])**2 for i in range(len(l1))])
    if l**0.5==int(l**0.5):
        return 1
    else:
        return 0

def resolve():
    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):
            ans+=kyori(x[i],x[j])
    print(ans)
resolve()

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):
    distance = math.sqrt(sum([
      (a - b) ** 2
      for a, b in zip(x[i], x[j])
    ]))
    if distance == int(distance):
      count += 1
print(count)

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Jul  7 20:52:12 2019

@author: YudNK
"""

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

def norm(i,j):
    norm2 = 0
    for k in range(D):
        norm2 += (i[k] - j[k])**2
    return norm2**0.5

count = 0
while len(point) > 1:
    for i in range(len(point) - 1):
        a = norm(point[-1],point[i])
        if a*10%10 == 0:
            count += 1
    point.pop(-1)
print(count)

Submission status: Accepted

Solution code:
import numpy as np
n, d = input().split()
N = int(n)
D = int(d)
x = []
for i in range(N):
    x.append([int(i) for i in input().split()])
x = np.array(x)
def calc_distance(l1, l2):
    return np.sqrt(np.sum((l1 - l2)** 2))
count = 0
for i in range(N):
    for j in range(i + 1, N):
        dd = calc_distance(x[i], x[j])
        # print(dd)
        if dd.is_integer():
            count += 1
print(count)

Submission status: Accepted

Solution code:
import math

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

ans = 0

def check(s):
    t = math.sqrt(s)
    u = int(t)
    if u * u == s:
        return 1
    else:
        return 0

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
#入力
N, D = map(int, input().split())
data = []
for i in range(N):
  data.append(list(map(int, input().split())))
data = np.array(data)


#処理
count = 0
for i in range(N):
  for j in range(N-i-1):
    pool = data[i,:] - data[i+j+1,:]
    pool = np.sqrt(np.sum(np.power(pool, 2)))
    if pool.is_integer():
      count += 1
print(count)

Submission status: Accepted

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

def dist(a,b):
    return sum([(p-q)**2 for p,q in zip(a,b)])

def is_sqrt(p):
    if p == int(p**0.5)**2:
        return True
    else:
        return False

ans = 0

for i in range(n):
    for j in range(i,n):
        if i == j:
            pass
        else:
            # print("dist:",dist(x[i],x[j]))
            if is_sqrt(dist(x[i],x[j])):
                ans += 1
print(ans)

Submission status: Accepted

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

for i in range(n):
    y = x[i]
    for z in x[i+1:]:
        dis = 0
        for j in range(d):
            dis += (y[j] - z[j])**2
        a = math.sqrt(dis)
        if int(a) == a:
            answer += 1
print(answer)

Submission status: Accepted

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

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
def is_sqrt(m,n):
    return m**2 <= n < (m+1)**2

def isqrt(n):
    low = 0
    high = n
    m = (low + high)//2

    while not is_sqrt(m,n):
        if m**2 < n: #too small! must be in [m+1,high]
            low = m+1
        else: #too big! must be in [low, m-1]
            high = m - 1
        m = (low + high) // 2
    return m

def is_square(n):
    return n == (isqrt(n))**2

n,d = map(int,raw_input().split())
x = []
for a in range(n):
  x.append(map(int,raw_input().split()))
ans = 0
for a in range(n):
  for b in range(a+1,n):
    q = 0
    for c in range(d):
      q += (x[a][c] - x[b][c])**2
    if is_square(q) == True:ans += 1
print ans

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
coodinates = [[int(x) for x in input().split()] for _ in range(n)]
result = 0
for left in range(n-1):
    for right in range(left+1,n):
        dist = 0
        for i in range(d):
            dist += (coodinates[left][i] - coodinates[right][i])**2
        dist = dist ** 0.5
        result += 1 if dist.is_integer() else 0
print(result)