Problem:


Score : 200 points

Problem Statement

There are N points in a D-dimensional space.

The coordinates of the i-th point are (X_{i1}, X_{i2}, ..., X_{iD}).

The distance between two points with coordinates (y_1, y_2, ..., y_D) and (z_1, z_2, ..., z_D) is \sqrt{(y_1 - z_1)^2 + (y_2 - z_2)^2 + ... + (y_D - z_D)^2}.

How many pairs (i, j) (i < j) are there such that the distance between the i-th point and the j-th point is an integer?

Constraints

All values in input are integers.

2 \leq N \leq 10

1 \leq D \leq 10

-20 \leq X_{ij} \leq 20

No two given points have the same coordinates. That is, if i \neq j, there exists k such that X_{ik} \neq X_{jk}.

Input

Input is given from Standard Input in the following format:

N D
X_{11} X_{12} ... X_{1D}
X_{21} X_{22} ... X_{2D}
\vdots
X_{N1} X_{N2} ... X_{ND}

Output

Print the number of pairs (i, j) (i < j) such that the distance between the i-th point and the j-th point is an integer.

Sample Input 1

3 2
1 2
5 5
-2 8

Sample Output 1

1

The number of pairs with an integer distance is one, as follows:

The distance between the first point and the second point is \sqrt{|1-5|^2 + |2-5|^2} = 5, which is an integer.

The distance between the second point and the third point is \sqrt{|5-(-2)|^2 + |5-8|^2} = \sqrt{58}, which is not an integer.

The distance between the third point and the first point is \sqrt{|-2-1|^2+|8-2|^2} = 3\sqrt{5}, which is not an integer.

Sample Input 2

3 4
-3 7 8 2
-12 1 10 2
-2 8 9 3

Sample Output 2

2

Sample Input 3

5 1
1
2
3
4
5

Sample Output 3

10



Sample input:
3 2
1 2
5 5
-2 8


Sample output:
1

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
i=0
s=[]
s2=[]
while i!=n:
    s2=list(map(int,input().split()))
    i+=1
    s.append(s2)

ans=0
sans=[]
i=0
j=0
k=0
sum=0
while i!=n:
    while j!=n:
        if i!=j:
            while k!=d:
                sum+=(s[i][k]-s[j][k])**2
                k+=1
            sans.append(sum**(1/2))
        sum=0
        k=0
        j+=1
    i+=1
    j=0
i=0
#print(sans)
while True:
    try:
        if sans[i]%1==0.0:
            ans+=1
        i+=1
    except:
        break
print(int(ans/2))

Submission status: Accepted

Solution code:
import math
N, D = map(int, input().split())
coordinates = []
count = 0
for i in range(N):
    coordinate = [int(i) for i in input().split()]
    coordinates.append(coordinate)

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

Submission status: Accepted

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

s = []
for i in range(len(x)):
    for j in range(i + 1, len(x)):
        a = 0
        for y, z in zip(x[i], x[j]):
            a += (y - z) ** 2
        s.append(a)

ans = 0
for si in s:
    for i in range(400):
        if i ** 2 == si:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math

N,D=map(int,input().split())
A=[]
for _ in range(N):
    tmp=list(map(int,input().split()))
    A.append(tmp)
ans = 0
for i in range(N):
    for j in range(N):
        if i < j:
            tmp = 0
            for d in range(D):
                tmp += (A[i][d] - A[j][d]) ** 2
            if math.sqrt(tmp) % 1 == 0:
                ans += 1
print(ans)

Submission status: Accepted

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

P = []
for n in range(N):
  P_ = input().split()
  P = P + [P_]
ct = 0
for n in range(N):
  for m in range(n+1,N):
    dist = 0
    for d in range(D):
      dist += (int(P[n][d])-int(P[m][d]))**2
    if int(dist**0.5)**2==dist:
      ct += 1
print(ct)

Submission status: Accepted

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

# print(x)

xn = np.array(x)

# print(xn[0, 0])

cnt = 0
for i in range(n - 1):
    tmp1 = xn[i, :]
    for j in range(i + 1, n):
        tmp2 = xn[j, :]
        tmp = 0
        for k in range(d):
            tmp += (tmp1[k] - tmp2[k]) * (tmp1[k] - tmp2[k])
        ans = np.sqrt(tmp)
        if ans % 1 == 0:
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import numpy as np


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

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

X = np.array(X)
ans = 0
dis = []
for i in range(n):
	for k in range(i+1, n):
		dis = np.sqrt(np.power(X[i]-X[k],2).sum()) 
		if int(dis)==dis:
			ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

# 文字列の入力
X = []
for i in range(N):
    X.append(list(map(int, input().split())))

count=0

for i in range(len(X)-1):
    for j in range(i+1, len(X)):
        tmp=0
        for k in range(D):
            tmp+=(X[i][k]-X[j][k])**2
        tmp=tmp**0.5
        if tmp.is_integer():
            count+=1
print(count)

Submission status: Accepted

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

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
        if math.sqrt(d).is_integer():
            cnt += 1

print(cnt)

Submission status: Accepted

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

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):
    x_i = X[i]
    for j in range(i+1, N):
        x_j = X[j]
        dist = 0
        for d in range(D):
            dist += (x_i[d] - x_j[d])*(x_i[d] - x_j[d])

        dist = dist**0.5
        if dist - int(dist) == 0:
            count += 1

print(count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import random
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def main():

	#N = int(input())
	#S = list(input())
	N,D = map(int, input().split(" "))
	#L = list(map(int, input().split(" ")))

	Xs = []
	for i in range(N):
		tmp = input().split(" ")
		tmp = [int(s) for s in tmp]
		Xs.append(tmp)

	ans = 0
	for i, val in enumerate(Xs):
		for ii in range(i+1, len(Xs)):

			vol = Xs[ii]

			to = 0
			for j in range(D):
				tmp = (abs(vol[j] - val[j]))**2
				to += tmp

			to = to ** (1/2)
			#print(to)
			if to.is_integer():
				ans += 1

	print(ans)




if __name__ == "__main__":
	main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

cnt = 0

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

print(cnt)

Submission status: Accepted

Solution code:

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

X=[]

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

num=0
for i in range(N):
    for j in range(i+1,N):
        dis = 0
        for d in range(D):
            dis += (X[i][d]-X[j][d])**2
        dis = dis**0.5
        dis2 = float(round(dis))

        if abs(dis-dis2) < 0.0000000001:
            num+=1
print(num)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

N, D = map(int, input().split())
l = []
ans = 0
for i in range(N):
  l.append([int(x) for x in input().split()])
for i in range(N-1):
  for j in range(i+1, N):
    d = 0
    for k in range(D):
      d += (l[i][k] - l[j][k]) ** 2
    d = np.sqrt(d)
    if d % 1 == 0:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math

def dist(a,b):
	if len(a)!=len(b):
		return -1
	else:
		tmp=0
		for i in range(len(a)):
			tmp+=(a[i]-b[i])**2
		return math.sqrt(tmp)

n,d=map(int,input().split())
x=[[] for i in range(n)]
for i in range(n):
	x[i]=list(map(int,input().split()))
ans=0
for i in range(n):
	for j in range(n):
		if i>=j:
			pass
		else:
			tmp=dist(x[i],x[j])
			if tmp.is_integer()==True:
				ans+=1
print(ans)

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
pos = [0]*N
for p in range(N):
    pos[p] = [int(x) for x in input().split()]
ans = 0

for i in range(N):
    for j in range(i):
        dis = 0.0
        for k in range(D):
            dis += ((pos[i][k] - pos[j][k]) ** 2)
        if (dis)**0.5 % 1 == 0:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
inf = 10**9


def dist(a, b):
    sum = 0
    for i in range(len(a)):
        sum += (a[i]-b[i])**2
    return sum**(1/2)


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

    for i in range(n):
        x[i] = list(map(int, input().split()))
    count = 0
    for i in range(n-1):
        for j in range(i+1, n):
            dis = dist(x[i], x[j])
            # print(dis, math.floor(dis))
            if dis == math.floor(dis):
                count += 1

    print(count)


if __name__ == '__main__':
    main()

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

print(ans)

Submission status: Accepted

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

# https://yatt.hatenablog.jp/entry/20130128/1359370204
def bisearch(f, n):
    l = 0
    r = n
    fl = f(l)
    fr = f(r)
    while l <= r:
        m = (l + r) // 2
        fm = f(m)
        if fm == n:
            return m
        elif fm > n:
            r = m - 1
            fr = f(r)
        else:
            l = m + 1
            fl = f(l)

def is_distance_integer(lista, listb):
    sum_ = 0
    for a, b in zip(lista, listb):
        sum_ += (a - b)** 2
    return bisearch(lambda n: n*n, sum_)


sum_ = 0
for i in range(N - 1):
    for xn in xnds[i + 1:]:
        if is_distance_integer(xnds[i], xn):
            sum_ += 1
print(sum_)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

points = []
counter = 0

for i in range(n):
    points.append(input().split())

for p in points:
    for i in range(d):
        p[i] = int(p[i])
        

for p in points:
    for q in points:
        if p == q:
            continue
        dist = 0
        for i in range(d):
            dist += (p[i] - q[i])**2
        
        dist = math.sqrt(dist)
        if dist.is_integer():
            counter += 1

print(int(counter/2))

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

x_list=[]

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

ans=0
for i in range(n):
  for j in range(i+1,n):
    #print(i,j)
    tmp=0
    for s in range(d):
      #print(s)
      tmp+=(x_list[i][s]-x_list[j][s])**2
    kai=math.sqrt(tmp)
    if kai.is_integer():
      ans+=1
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

import numpy as np
import sys
import collections
import scipy.misc
import math
from operator import itemgetter
import itertools
import copy
import bisect
import heapq

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
    

"""
N, X = map(int, input().split())

x = list(map(int, input().split()))

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)

#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]

#Distance Transformation
    for h in range(0,H):
        for w in range(0,W):
            if h == 0 and w == 0:
                pass
            elif h == 0:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h-1][W-w]+1)
            elif w == 0:   
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1)
            else:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1, D[H-h-1][W-w]+1, D[H-h][W-w]+2)
            d_max = max(D[H-h-1][W-w-1], d_max)

"""


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



    
def main(): 
    res = 0
    for cb in itertools.combinations(range(N),2):
        i, j = cb
        r2= float(0.0)
        for d in range(D):
            r2 += (X[i][d] - X[j][d])**2.
        r = float(math.sqrt(r2))
        if r.is_integer():
            res +=1
    print(res)
                
                
                
            
            
                

    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

def distance(list1,list2):
    dis=0
    for i in range(len(list1)):
        dis=dis+(list1[i]-list2[i])*(list1[i]-list2[i])
    return dis
                                     

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

ans=0
for i in range(n):
    for j in range(n-i-1):
        a=distance(x[i],x[i+j+1])
        if a==int((math.sqrt(a)))*int((math.sqrt(a))):
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
import sys
import math

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n, d = map(int, input().split())
    xl = [list(map(int, input().split())) for i in range(n)]

    count = 0
    for i in range(n):
        for j in range(i+1, n):
            sq = math.sqrt(sum([abs(xl[i][k] - xl[j][k])**2 for k in range(d)]))
            if sq == int(sq):
                count += 1

    print(count)

Submission status: Accepted

Solution code:
import numpy as np

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

count = 0

for i in range(n):
  for j in range(i):
    if data[i] != data[j]:
      a = np.array(data[i])
      b = np.array(data[j])
      l = np.linalg.norm(b-a)
      
      if (l.is_integer()):
        count += 1
print(count)

Submission status: Accepted

Solution code:
import math
def dist(x,y):
    return math.sqrt(sum([(s-t)**2 for s,t in zip(x,y) ]) )

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):
    xs = x[i+1:N]
    dists = [dist(x[i], y) for y in xs]
    count += sum([s - int(s) == 0 for s in dists ])
print(count)

Submission status: Accepted

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

ans = 0
for i in range(N):
    a = X[i]
    for b in X[i+1:]:
        u = a - b
        if np.linalg.norm(u).is_integer():
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy

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

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

Submission status: Accepted

Solution code:
import numpy as np


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

    X = np.array(X)
    dist = np.sum((X[:, None] - X[None, :]) ** 2, axis=-1) ** 0.5

    count = 0
    for i in range(N):
        for j in range(i):
            if float(dist[i, j]).is_integer():
                count += 1
    
    print(count)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

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

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

print(answer)

Submission status: Accepted

Solution code:
n,d = map(int, input().split(" "))
count = 0
values = []

for _ in range(n):
    values.append([int(x) for x in list(input().split(" "))])


for i in range(n-1):
    for j in range(i+1,n):
        total = 0
        for k in range(d):
            total += (values[i][k] - values[j][k])**2
        distance = total**(1/2)
        if distance%1 == 0:
            count += 1

print(count)

Submission status: Accepted

Solution code:
import math

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

def dist_int(p0, p1):
    dd = 0
    for i in range(D):
        x = p0[i] - p1[i]
        dd += x*x

    d = math.sqrt(dd)
    return math.ceil(d) == math.floor(d)

cnt = 0
for i in range(N):
    for j in range(N):
        if j >= i:
            continue
        p0 = P[i]
        p1 = P[j]
        if dist_int(p0,p1):
            cnt += 1

print(cnt)

Submission status: Accepted

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

################################################################################

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

    return d

def check(x, y):
    d = dist(x, y)
    rt = int(d**0.5+1e-6)
    return rt*rt == d


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

res = 0
for i in range(n):
    for j in range(i+1, n):
        res += check(pts[i], pts[j])

print(res)

Submission status: Accepted

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

cnt = 0
for i in range(N):
	for j in range(i+1, N):
		il = xlist[i]
		jl = xlist[j]
		total = 0
		for n in range(D):
			total = total + (il[n]-jl[n])**2
		
		if sqrt(total).is_integer():
			cnt = cnt + 1

print(cnt)

Submission status: Accepted

Solution code:

import math


def read_input():
    n, d = map(int, input().split())

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

    return n, d, points


def check_good_distance(p1, p2):
    dist = 0
    for e1, e2 in zip(p1, p2):
        temp = abs(e2 - e1)
        dist += temp ** 2

    dist = math.sqrt(dist)

    if dist == int(dist):
        return True
    else:
        return False


def submit():
    n, d, points = read_input()

    count = 0
    for i, p1 in enumerate(points):
        for p2 in points[i+1:]:
            if check_good_distance(p1, p2):
                count += 1

    print(count)




if __name__ == '__main__':
    submit()

Submission status: Accepted

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

ans = 0
for i in range(N-1):
    for j in range(N-i-1):
        j += i+1
        dis2 = 0
        for t in range(D):
            dis2 += (X[i][t]-X[j][t])**2
        dis = math.sqrt(dis2)
        if dis - math.floor(dis)==0.0:
            ans += 1

print(ans)

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

y = []
a = 1
while (a * a) < 16001:
    y.append(a * a)
    a += 1

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        val = 0
        for k in range(D):
            val += (x[i][k] - x[j][k]) ** 2
        if val in y:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
# coding: utf-8
import math

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

count = 0

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

for i in range(n-1):
    for j in range(i+1, n):
        point_i = points[i]
        point_j = points[j]
        a = ((point_i[k] - point_j[k]) ** 2 for k in range(d))
        distance = math.sqrt(sum(a)) 
        if int(distance) == distance:
            count += 1
print(count)

Submission status: Accepted

Solution code:
import math

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

point_list = []

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

count = 0 

for j in range(N):
    for k in range(j+1,N):
        distance_pow = 0 
        for l in range(D):
            distance_pow += (point_list[j][l] - point_list[k][l]) ** 2
        distance = math.sqrt(distance_pow)
        
        if distance % 1 == 0:
            count += 1

print(count)

Submission status: Accepted

Solution code:
def main():
	import sys
	import numpy as np
	input = sys.stdin.readline
	N, D = list(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):
		for j in range(i+1, N):
			f = np.linalg.norm(X[i] - X[j])
			if f.is_integer():
				count += 1
	print(count)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, D = [int(elem) for elem in input().split()]
coords = [[int(elem) for elem in input().split()] for _ in range(N)]
assert len(coords[0]) == D

def is_squared(num):
    i = 1
    while i * i <= num:
        if i * i == num:
            return True
        i += 1
    return False


num_pairs = 0
for i in range(N):
    c1 = coords[i]
    for j in range(i + 1, N):
        c2 = coords[j]
        sqaured_dist = sum((p1 - p2) ** 2 for p1, p2 in zip(c1, c2))
        if is_squared(sqaured_dist):
            num_pairs += 1
print(num_pairs)

Submission status: Accepted

Solution code:
import math
n,d=map(int,input().split())
x=[]
ans=0
for i in range(n):
    x.append(list(map(int,input().split())))
for i in range(n):
    for j in range(i):
        sum = 0
        for k in range(d):
            sum += (x[i][k]-x[j][k])*(x[i][k]-x[j][k])
        if math.sqrt(sum).is_integer():
            ans+=1
print("{}".format(ans))

Submission status: Accepted

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

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

cnt = 0

for i in range(n):
    for j in range(n):
        if i <= j:
            continue
        s = 0
        for k in range(d):
            s += (abs(li[i][k] - li[j][k]) ** 2)
        else:
            s = str(s**0.5)
            if s[-1] == "0" and s[-2] == ".":
                cnt += 1
        
print(cnt)

Submission status: Accepted

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

e=10**(-10)
count=0
for i in range(N-1):
    for j in range(i+1,N):
        #print(X[i],X[j])
        tmp=0
        for d in range(D):
            tmp+=(X[i][d]-X[j][d])**2
        tmp=tmp**(1/2)

        if (tmp-tmp//1)<e:
            count+=1

print(count)

Submission status: Accepted

Solution code:
import math

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

  ans = 0
for i in range(1,n):
  for j in range(i):
    list1 = x_array[i]
    list2 = x_array[j]
    count = 0
    for k in range(len(list1)):
      count += (list1[k]-list2[k]) ** 2

    if math.sqrt(count) == int(math.sqrt(count)):
      ans += 1

print(ans)

Submission status: Accepted

Solution code:
maxd2 = 40**2*10
intd2 = set()
maxi = int(maxd2**(1/2))+10
for i in range(maxi):
    intd2.add(i**2)


n, d = list(map(int, input().split()))
x = []
for _ in range(n):
    xi = list(map(int, input().split()))
    x.append(xi)
    
cnt = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        distance = sum([(x[i][k]-x[j][k])**2 for k in range(d)])
        if distance in intd2:
            cnt += 1
            
print(cnt//2)

Submission status: Accepted

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

ans=0
for i in range(N):
	for j in range(i+1,N):
		t=0
		for x, y in zip(X[i],X[j]):
			t+=(x-y)**2	

		for h in range(1,10000):
			if t==h**2:
				ans+=1
				break

print ans

Submission status: Accepted

Solution code:
from math import sqrt

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

counter = 0
for i in range(N):
    for j in range(i+1, N):
        dist = 0
        for it in range(D):
            dist += (points[i][it]-points[j][it])**2
        dist = sqrt(dist)

        if dist.is_integer() == True:
            counter += 1

print(counter)