Problem:


Score : 200 points

Problem Statement

There are N points in a D-dimensional space.

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

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

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

Constraints

All values in input are integers.

2 \leq N \leq 10

1 \leq D \leq 10

-20 \leq X_{ij} \leq 20

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

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

3 2
1 2
5 5
-2 8

Sample Output 1

1

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

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

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

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

Sample Input 2

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

Sample Output 2

2

Sample Input 3

5 1
1
2
3
4
5

Sample Output 3

10



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


Sample output:
1

Submission status: Accepted

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


def isSq(n):
    i = 0
    while i*i <= n:
        if i*i == n:
            return True
        i+=1


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

c = 0
for i in range(n-1):
    for j in range(i+1, n):
        d = sqDist(x[i], x[j])
        if isSq(d):
            c += 1

print(c)

Submission status: Accepted

Solution code:
import numpy as np
N, D = map(int, input().split())
X=np.empty((0,D),int)
for i in range(N):
    X=np.append(X, np.array([list(map(int, input().split()))]),axis=0)
ans=0
for i in range(N):
    for j in range(i+1,N):
        
        diff=X[j]-X[i]
        d=np.linalg.norm(diff)
        #print(X[i],X[j],diff)
        if d.is_integer():
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
import math

x, y = input().split()
N = int(x)
D = int(y)

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

answer = 0
for i in range(N):
    for j in range(N - i):
        res = 0.0
        tmpj = N - j - 1
        if i == tmpj:
            continue
        for d in range(D):
            res += (X[i][d] - X[tmpj][d]) ** 2
        res = math.sqrt(res)
        if res.is_integer():
            answer += 1
print(answer)

Submission status: Accepted

Solution code:
import os, sys, re, math

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

def isInt(n):
    base = 1
    while base ** 2 <= n:
        if base ** 2 == n:
            return True
        base += 1
    return False

cnt = 0
for i in range(N-1):
    for j in range(i+1,N):
        dist = 0
        for d in range(D):
            dist += (x[i][d] - x[j][d]) ** 2
        if isInt(dist):
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import numpy

N, D = map(int, input().split())
X = numpy.array([list(map(int, input().split())) for _ in range(N)])
print(len([i for i, x in enumerate(X) for y in X[i + 1:] if numpy.linalg.norm(x - y).is_integer()]))

Submission status: Accepted

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

import math

count = 0
for x in range(len(arX)):
    xp = arX[x]
    for y in range(x, len(arX)):
        if x == y:
            continue
        
        yp = arX[y]
        
        powSum = 0
        for d in range(D):
            powSum += (xp[d] - yp[d]) ** 2
        
        #print(x, y, sqPowSum)
            
        sqPowSum = math.sqrt(powSum)
        if sqPowSum == int(sqPowSum):
            count += 1

print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
ND=input().split()
ND[0]=int(ND[0])
ND[1]=int(ND[1])
ls=[]
for i in range(ND[0]):
    ls.append(input().split())
    for j in range(ND[1]):
        ls[i][j]=int(ls[i][j])

ans=0

for i in range(ND[0]):
    X=ND[0]-1-i
    for j in range(X):
        nijo=0
        for k in range(ND[1]):
            nijo+=int((ls[i][k]-ls[i+j+1][k])**2)
        root=nijo**0.5
        if root.is_integer():
            ans+=1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

# 入力行N，列D
N, D = map(int, input().split())
points = [list(map(int, input().split())) for i in range(N)]

def calc_distance(p1, p2):
    sum = 0
    for i in range(len(p1)):
        sum += (p1[i] - p2[i]) ** 2
    return np.sqrt(sum)

count = 0
for i, point in enumerate(points):
    for point2 in points[i + 1:]:
        outp = calc_distance(point, point2)
        if outp.is_integer():
            count += 1

print(count)

Submission status: Accepted

Solution code:
n = list(map(int, input().rstrip().split(" ")))
ans = 0
coor = []
for a in range(n[0]):
  coor.append(list(map(int, input().rstrip().split(" "))))
  
def dis(a,b):
  ans = 0
  for i in range(len(a)):
    ans += (a[i] - b[i])**2
  return ans**0.5
  
for a in range(len(coor)):
  for b in range(0,a):
    if coor[a]!=coor[b]:
      if dis(coor[a], coor[b]).is_integer():
        ans += 1
print(ans)

Submission status: Accepted

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

import sys
import math

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
        tokens = lines[0].split(" ")
        n = int(tokens[0])
        d = int(tokens[1])
        for i in range(n):
            lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
        tokens = lines[0].split(" ")
        n = int(tokens[0])
        d = int(tokens[1])

    xs = []
    for i in range(1, n+1):
        tokens = lines[i].split(" ")
        xs.append([int(e) for e in tokens])

    return (n, d, xs)


def solve(n, d, xs):

    count = 0
    for i in range(n-1):
        for j in range(i+1, n):
            a = xs[i]
            b = xs[j]
            sum = 0
            for k in range(d):
                sum = sum + (a[k] - b[k])**2
            
            distance = math.sqrt(sum)

            if distance.is_integer():
                count = count + 1

    return count


def main():
    # 出力

    print("%s" % solve(*parse_input()))

#    solve(*parse_input())

if __name__ == '__main__':

    main()

Submission status: Accepted

Solution code:
N, D = (int(x) for x in input().split())
X = [None]*N
sq_list = [x**2 for x in range(40*D+1)]
def is_distance_sq(x: list, y: list) -> bool:
    distance_sq = sum([(x[i]-y[i])**2 for i in range(D)])
    return distance_sq in sq_list

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

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        if is_distance_sq(X[i], X[j]):
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
N,D=(int(x) for x in input().split())
data_list=[]

for i in range(N):
    row=[]
    data=input().split()
    for j in data:
        row.append(int(j))
    data_list.append(row)

count=0
for i in range(N-1):
    for j in range(i+1,N):
        a=data_list[i]
        b=data_list[j]
        square=0
        for k in range(D):
            square+=(a[k]-b[k])**2
        index=1
        while (True):
            if(index*index>square):
                break
            elif(index*index==square):
                count+=1
                break
            else:
                index+=1

print(count)

Submission status: Accepted

Solution code:
import numpy as np

n, d = list(map(int, input().split()))
xxx = [np.array(list(map(int, input().split()))) for _ in range(n)]
ans = 0
for i, x in enumerate(xxx):
    for y in xxx[i + 1:]:
        a = np.linalg.norm(x - y)
        if abs(a - int(a)) < 0.00001:
            ans += 1
print(ans)

Submission status: Accepted

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

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

count = 0
for i in range(n):
    for j in range(i+1, n):
        a = X[i]
        b = X[j]
        dist = math.sqrt(sum([(a-b)**2 for a, b in zip(a,b)]))
        if dist == int(dist):
            count += 1
print(count)

Submission status: Accepted

Solution code:
N, D = [int(x) for x in input().split(' ')]

points = []
for _ in range(N):
  X = [int(x) for x in input().split(' ')]
  points.append(X)
  
def distance(x, y):
  d = 0
  for i in range(D):
    d += (x[i] - y[i]) ** 2
  return d ** 0.5

ans = 0
from itertools import combinations
for a, b in combinations(points, 2):
  if distance(a, b).is_integer():
    ans += 1
      
print(ans)

Submission status: Accepted

Solution code:
n,d = map(int,input().split())
zahyo = []
count = 0
for i in range(n):
    zahyo.append(list(map(int,input().split())))
for a in range(n):
    for b in range(n):
        if a<=b:
            break
        else:
            p = 0
            for i in range(d):
                p += (zahyo[a][i]-zahyo[b][i])**2
            if p**0.5 == int(p**0.5):
                count += 1
print(count)

Submission status: Accepted

Solution code:
import numpy as np

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

count = 0
for i in range(N):
  for j in range(i+1, N):
    d = np.linalg.norm(X[i] - X[j])
    if np.round(d) == d:
      count += 1
print(count)

Submission status: Accepted

Solution code:
from itertools import combinations

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

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

ans = 0
for x1, x2 in combinations(xs, 2):
    s = sum(((y - z) ** 2 for y, z in zip(x1, x2)))
    if (int(s ** 0.5)) == s ** 0.5:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N,D = map(int,input().split())
X = [list(map(int,input().split())) for l in range(N)]
import numpy as np
X = np.array(X)
ans = 0
for i in range(N):
    for j in range(i,N):
        if(i!=j):
            dis = np.sqrt(sum((X[i] - X[j])**2))
            if(dis.is_integer()):
                ans += 1
                
print(ans)

Submission status: Accepted

Solution code:



N,D = map(int,input().split())
A=[]
for i in range(N):
    b = list(map(int,input().split()))
    A.append(b)
counter = 0
for i in range(N):
    for j in range((i+1),N):
        n = 0
        for k in range(D):
            n += (A[i][k]-A[j][k])**2
        n = n**0.5
        if n.is_integer() ==True:
            counter += 1

print(counter)

Submission status: Accepted

Solution code:
import numpy as np

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

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

ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        euc = np.linalg.norm(X_list[i] - X_list[j])
        if euc.is_integer():
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
n, m = (int(_) for _ in input().split())
l = [list(int(_) for _ in input().split()) for i in range(n)]

res = 0
for i in range(n):
    for ii in range(i+1,n):
        if (sum([(l[i][x]-l[ii][x])**2 for x in range(m)])**(1/2))%1==0:
            res += 1

print(res)

Submission status: Accepted

Solution code:
import numpy as np

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

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

count = 0
for i in X:
    for j in X:
        if (np.sqrt(sum((i-j)**2))%1 == 0) == True:
            count += 1
print((count-N)//2)

Submission status: Accepted

Solution code:
import math
n,d = map(int,input().split())
ls = [[int(i) for i in input().split()] for i in range(n)]
count = 0
for i in range(1,n):
    for j in range(i):
        check = 0
        for k in range(d):
            check += (abs(ls[i][k] - ls[j][k]))**2
        check = math.sqrt(check)
        if check - int(check) == 0:
            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

for i in range(N):
    for j in range(N):
        if i != j:
            tmp = 0.0
            for k in range(D):
                tmp += (abs(X[i][k]-X[j][k]))**2
            if (tmp**0.5).is_integer():
                ans += 1
print(ans//2)

Submission status: Accepted

Solution code:
import math

n, d = map(int, input().split())
points = [0] * n
for i in range(n):
    x = [int(x) for x in input().split()]
    points[i] = x
    
count = 0
for i in range(n-1):
    for j in range(i+1, n):
        dist = 0
        for k in range(d):
            dist += (points[i][k] - points[j][k])**2
        ans = math.sqrt(dist)
        if ans.is_integer():
                count += 1
                
print(count)

Submission status: Accepted

Solution code:
from math import sqrt

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

def calc_dist(y_s, z_s):
    yz_s = [[y_s[i], z_s[i]] for i in range(d)]

    distance = 0
    for y, z in yz_s:
        distance += abs(y - z) ** 2
    distance = sqrt(distance)
    return distance

cnt = 0
for i in range(n):
    for j in range(i+1, n):
        dist = calc_dist(x_s[i], x_s[j])
        if dist % 1 == 0:
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
import math

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

x = []
for iN in range(n):
    x.append(np.array(list(map(int, input().split(' ')))))

count = 0
# 全通り試す
for iFirst in range(n - 1):
    for iSecond in range(iFirst + 1, n):
        # 距離が整数なら
        if math.sqrt(np.sum(np.power(x[iFirst] - x[iSecond], 2))).is_integer():
            # カウントする
            count += 1
# 結果出力
print(count)

Submission status: Accepted

Solution code:
from math import sqrt

num = input().split()
number, dim = int(num[0]), int(num[1])
dots = [input().split() for i in range(number)]

tmp = []
count = 0

for i in range(len(dots)):
  for j in range(i+1,len(dots)):
    ans = [(int(dots[i][k])-int(dots[j][k]))**2 for k in range(dim)]
    tmp.append(sqrt(sum(ans)))
    
for item in tmp:
  if item-int(item)==0:
    count += 1
    
print(count)

Submission status: Accepted

Solution code:
import sys
import math

N, D = map(int, sys.stdin.readline().split())
X = []

for i in range(N):
    temp = list(map(int, sys.stdin.readline().split()))
    X.append(temp)


count = 0
for i in range(N):
    for j in range(i, N):
        if i == j:
            continue
        else:
            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():
                count += 1
print(count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 133 abc b
# input
import numpy as np
n, d = map(int, input().split())
x = []
counter = 0
for i in range(n):
    x.append(list(map(int, input().split())))
temp = np.array(x)
all_diffs = np.expand_dims(temp, axis=1) - np.expand_dims(temp, axis=0)
degree_distance = np.sqrt(np.sum(all_diffs ** 2, axis=-1))
for i in range(n):
    for j in range(n):
        if degree_distance[i][j].is_integer() == True:
            counter += 1
# output
print(int((counter-n)/2))

Submission status: Accepted

Solution code:
import math

N, D = [int(x) for x in input().split()]

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

dis = []
for i in range(0, N):
    for j in range(i + 1, N):
        tmp = 0

        for a in range(0, D):
            tmp = tmp + (Data[i][a] - Data[j][a]) ** 2
        tmp = math.sqrt(tmp)
        if tmp.is_integer():
            dis.append(tmp)

print(len(dis))

Submission status: Accepted

Solution code:
# coding: utf-8
import numpy as np
n, d = map(int, input().split())
cnt = 0
X = []
for i in range(n):
    x = list(map(int, input().split()))
    X.append(x[:])
X = np.array(X)
for i in range(n):
    X_tmp = X[:]
    X_tmp -= X[i]
    for i in range(n):
        x = X_tmp[i]
        x_sq = x**2
        x_sq = np.sqrt(sum(x_sq))
        if x_sq % 1 == 0:
            cnt += 1
print((cnt-n)//2)

Submission status: Accepted

Solution code:
import math

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

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

print(cnt)

Submission status: Accepted

Solution code:
import math

n, d = map(int, input().split())
count = 0
nums = []

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

for i in range(len(nums)):
    for j in range(i+1, len(nums)):
        total = 0
        for a, b in zip(nums[i],nums[j]):
            total += abs(a - b) ** 2
        if math.sqrt(total).is_integer():
            count += 1

print(count)

Submission status: Accepted

Solution code:
import math
n,d=map(int,input().split())
x=[input().split() for i in range(n)]
ans=0
for i in range(n):
        for h in range(i):
                a=0
                for j in range(d):
                        a+=(int(x[i][j])-int(x[h][j]))**2
                a=math.sqrt(a)
  
                if float.is_integer(a)==True:
                        ans+=1
print(ans)

Submission status: Accepted

Solution code:
import math
N,D = map(int,input().split(' '))
l = [list(map(int,input().split())) for _ in range(N)]
ans = 0
for i in range(N):
    for ii in range(i+1,N):
        d = 0
        for j in range(D):
            d += (l[i][j] - l[ii][j])**2
        k = math.sqrt(d)
        if k==0:
            continue
        if k==int(k):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:

import numpy as np
from functools import reduce
from math import sqrt

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

xnd = []
for _ in range(n):
    xi = list (map(int,input().split()))
    xnd.append(np.array( xi) )

#print(xnd)

#print(xnd[0] - xnd[1])


ans = 0
for i in range(n):
    for j in range(i+1,n):
        
        t = map(lambda x: x**2, xnd[i]-xnd[j])
        
        sum_sq = reduce( lambda x,y: x+y, t )
#        print(sum_sq)
        dist = float(np.sqrt(sum_sq))    
#        print(dist)
        ans += 1 if float.is_integer(dist) else 0

print(ans)

Submission status: Accepted

Solution code:
import math

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

N, D = [int(i) for i in input().split()]
X = [[int(i) for i in input().split()] for m in range(N)]
X = np.array(X)
l = 0

for i in range(N):
  for j in range(i+1, N):
    if sum((X[i] - X[j])**2)**0.5 % 1 == 0:
      l += 1

print(l)

Submission status: Accepted

Solution code:
import numpy as np

point_num, dim_num = map(int, input().split())

points = []
for i in range(point_num):
    points.append(np.array(list(map(int, input().split()))))

ans = 0
for i in range(point_num):
    for j in range(i+1, point_num):
        dist = np.linalg.norm(points[i] - points[j])
        if(dist == int(dist)):
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
def main():
	N, D = map(int, input().split())
	X = [0]*N
	for i in range(N):
		X[i] = list(map(int, input().split()))
	ans = 0
	for i in range(N):
		for j in range(i+1, N):
			this_len = 0
			for k in range(D):
				cur = X[i][k]-X[j][k]
				this_len += cur*cur
			sqrt = int(this_len**0.5)
			if this_len == sqrt*sqrt:
				ans += 1
	print(ans)


if __name__ == '__main__':
	main()

Submission status: Accepted

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

ans = 0
tmp = 0

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

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
import math
N, D = [int(x) for x in input().split()]
xs = []
for i in range(N):
  xs.append([int(x) for x in input().split()])
count = 0
for i in range(N):
  for j in range(N):
    if i < j:
      a1 = xs[i]
      a2 = xs[j]
      a3 = [a1[k] - a2[k] for k in range(len(a1))]
      a3 = math.sqrt(sum([i ** 2 for i in a3]))
      if a3 == int(a3):
        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)]
p=0
def c(i,j):
  global x
  s=0
  for k in range(d):
    s+=(x[i][k]-x[j][k])**2
  if (s**(1/2)).is_integer()==True:
    return 1
  else:
    return 0
for i in range(n):
  for j in range(i+1,n):
    p+=c(i,j)
print(p)

Submission status: Accepted

Solution code:
import math
n, d = map(int , input().split())
points = []
for x in range(n):
    points.append(list(map(int, input().split())))
#print(points)
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        a = 0
        for k in range(d):
            a = a + abs(pow(points[i][k] - points[j][k], 2))
        a = math.sqrt(a)
        floatX, intX = math.modf(a)
        #print(floatX)
        if floatX == 0.0:
            ans = ans + 1
        #print("(i, j, a) = ({}, {}, {})".format(i, j, a))
print(ans)

Submission status: Accepted

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

ans=0

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

Submission status: Accepted

Solution code:
import math

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

X = N*[None]

def distance(y,z):
    s = 0
    for i in range(D):
        s+=(X[y][i]-X[z][i])**2
    return s


for i in range(N):
    x_t = [int(i) for i in input().split()]
    X[i] = x_t
ans = 0
for i in range(N):
    for j in range(i+1,N):
        a = distance(i,j)
        k = math.sqrt(a)
        if k==int(k):
            ans +=1
print(ans)

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[i] = list(map(int,input().split()))


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

Submission status: Accepted

Solution code:
N,D = map(int,input().split())
def dist(p1,p2,d):
    g = 0
    for i in range(d):
        g += abs(p1[i]-p2[i])**2
    g2 = int(g**(0.5))
    return g**(0.5) == g2

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

c = 0
for i in range(N):
    for j in range(N):
        if i < j:
            if dist(p[i],p[j],D):
                c += 1
print(c)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from math import sqrt
from itertools import combinations

def dist(y, z):
  return sqrt(sum([(yi - zi)**2 for yi, zi in zip(y, z)]))

def is_int(num):
  return num == int(num)


n, d = map(int, input().split())
x = [None]*n

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


cnt = 0
for i, j in combinations(range(n), 2):
  if is_int(dist(x[i], x[j])):
    cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math
n,d =  map(int,input().split()) 	
x=[]
cnt =0
for _ in range(n):
    tmp = list(map(int,input().split()))
    x.append(tmp)
for i in range(n-1):
    for j in range(i+1,n):
        r = 0
        for k in range(d):
            r += (x[i][k]-x[j][k])**2
        r = math.sqrt(r)
        if r % 1 == 0:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import math

N, D = [int(_) for _ in input().split()]
X = [[int(_) for _ in input().split()] for __ in range(N)]
cnt = 0

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys;
import string;
sys.setrecursionlimit(20000) # 再起呼び出しの最大数をセット

import copy
import math
import itertools

from functools import lru_cache
#@lru_cache(maxsize = None)

PPP = 1000000007

# 整数の入力
#n = int(input())

# スペース区切りの整数の入力
#a = [int(x) for x in input().split()]
n, d = map(int, input().split())
#print("sp", n, k, file=sys.stderr)
#p, q, r = map(int, input().split())
#s = [int(x) for x in input().split()]
#t = [int(x) for x in input().split()]

# 改行区切りの整数の入力
a = []
for x in range(n):
#  a.append(int(input()))
  a.append([int(x) for x in input().split()])
#p = [int(x) for x in input().split()]
#a.sort()
#print(l, file=sys.stderr)

# 文字列の入力
#s = input()

# 出力
#print("{} {}".format(a+b+c, s))
#a.sort()
#print(set(a), file=sys.stderr)
#print(len(set(a)))

#cache = dict()

import re
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
  
def count(c):
  r = b // c - (a - 1) // c;
  print(c, r, file=sys.stderr)
  return r

def doit():
  res = 0
  for x in range(n):
    for y in range(x+1, n):
      s = 0
      for p in range(d):
        print(a[x][p], a[y][p], file=sys.stderr), 
        s += (a[x][p] - a[y][p]) ** 2
      print(s, math.sqrt(s), file=sys.stderr)
      if math.sqrt(s) % 1 == 0:
        res += 1
  return res

#print(doit([0] * 4))
#doit(s)
#print(doit())
try:
  print(doit())
except Exception as e:
  print("e", e, file=sys.stderr)

Submission status: Accepted

Solution code:
import math

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

res = 0
for i in range(n-1):
    for j in range(i+1,n):
        sumdiff = 0
        for k in range(d):
            sumdiff += (l[i][k]-l[j][k])**2
        else:
            if math.sqrt(sumdiff) == math.sqrt(sumdiff)//1:
                res += 1
else:
    print(res)

Submission status: Accepted

Solution code:
import math

def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()
      
N, D = map(int, input().split())
lst = []
for i in range(N):
  lst.append(list(map(int, input().split())))
sum = 0
for i in range(N-1):
  for j in range(i+1, N):
    ans = 0
    for k in range(D):
      ans += (lst[i][k] - lst[j][k])**2
    if(is_integer(math.sqrt(ans))):
      sum +=1
print(sum)

Submission status: Accepted

Solution code:
import numpy as np
import math
N,D = map(int,input().split())
X = []
count = 0
for i in range(N):
    X.append(np.array(list(map(int,input().split()))))
for i in range(N):
    for j in range(i,N-1):
        tmp = np.linalg.norm(X[i] -X[j+1])
        if tmp - math.floor(tmp) == 0:
            count += 1
print(count)

Submission status: Accepted

Solution code:
import math
N,D=map(int,input().split())
List=[[int(i) for i in input().split()] for j in range(N)]
c = 0
for i in range(N):
    for k in range(N):
        sum = 0
        for j in range(D):
            sum += (List[i][j]-List[k][j])**2
       
        ssum = math.sqrt(sum)
        
        if ssum - int(ssum) <0.000000001:
            c += 1
print(int((c-N)/2))

Submission status: Accepted

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

count = 0
for i in range(N):
    for j in range(i+1, N):
        rr = 0
        for d in range(D):
            rr += (X[i][d] - X[j][d])**2

        r = math.sqrt(rr)
        if float(int(r)) == r:
            count+=1

print(count)

Submission status: Accepted

Solution code:
import numpy as np

N,D = map(int,input().split())
X = np.empty((N,D))
for i in range(N):
    X[i]=np.array(list(map(int,input().split())))
c = 0
for i in range(N):
    for j in range(i,N):
        calc = np.linalg.norm(X[i]-X[j])
        if calc.is_integer() and not calc == 0:
            c+=1
print(c)

Submission status: Accepted

Solution code:
import sys
import numpy as np

DList = []
N, D = map(int,sys.stdin.readline().split())
for i in range(N):
  DList.append(list(map(int,sys.stdin.readline().split())))
DList = np.array(DList);

counter=0
for i in range(N):
  for j in range(N):
    if i < j:
      dis = np.linalg.norm(DList[i] - DList[j])
      if dis.is_integer():
        counter+=1
print(counter)

Submission status: Accepted

Solution code:
import numpy as np

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

X = []
ans = 0

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

np_X = np.array(X)


for i in range(1, N):
    for k in range(i,N):
        a = np_X[(i-1),:] - np_X[k,:]
        ad = 0
        for j in a:
            ad += j**2
        if np.sqrt(ad) - int(np.sqrt(ad)) == 0:
            ans += 1

print(ans)