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

ans = 0
for i in range(N):
    for j in range(i+1, N):
        t = 0
        for k in range(D):
            t += (P[i][k]-P[j][k])**2
        t = t**(1/2)
        if t.is_integer():
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math
N, D = map(int, input().split())
P = []
ans = 0
for _ in range(N):
  new_p = [int(x) for x in input().split()]
  for p in P:
    dist = math.sqrt(sum([(new_p_i - p_i)**2 for new_p_i, p_i in zip(new_p, p)]))
    if dist.is_integer():
      ans += 1
  P.append(new_p)
print(ans)

Submission status: Accepted

Solution code:
import itertools, math

S = input().split()
N = int(S[0])
D = int(S[1])

X = []

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

count = 0

for p in itertools.combinations(X, 2):
    sum = 0
    for i in range(0, D):
        sum += pow(abs(p[0][i] - p[1][i]), 2)
    if math.modf(math.sqrt(sum))[0] == 0.0:
        count += 1

print(count)

Submission status: Accepted

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

plots = []

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

cnt = 0
    
for i in range(n):
    for j in range(n):
        if i == j:
            break
        dis = 0
        for l in range(d):
            dis += (plots[i][l]-plots[j][l])**2
        
        dis_sqrt = dis**(1/2)
        
        if float.is_integer(dis_sqrt):
            cnt += 1
    
print(cnt)

Submission status: Accepted

Solution code:
import math

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

def compute(point1, point2):
    length = 0
    for item1, item2 in zip(point1, point2):
        length += (item1 - item2) ** 2
    return 1 if int(math.sqrt(length)) ** 2 == length else 0

count = 0
for i in range(N):
    for j in range(i, N):
        if i != j:
            count += compute(inputs[i], inputs[j])

print(count)

Submission status: Accepted

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

x = [[int(i) for i in input().split()] for _ in range(n)]
counter = 0
func = lambda x: x**2
func2 = lambda x,y:x-y

for i, j in enumerate(x[:-1]):
  for k in x[i+1:]:    
    
    norm = sum(list(map(func, list(map(func2, j, k)))))

    if math.sqrt(norm) % 1 == 0:
      counter += 1
      
print(counter)

Submission status: Accepted

Solution code:
import math

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

count = 0
distance = 0

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

Submission status: Accepted

Solution code:
from sys import stdin
from itertools import combinations

readline = stdin.readline


def nl():
    """
    空白区切り行入力を`int iter`に変換
    """
    return map(int, readline().split())


def main():
    n, d = nl()
    res = 0
    xs = [
        tuple(nl())
        for i in range(n)
    ]
    for i, j in combinations(xs, 2):
        c = .0
        for a, b in zip(i, j):
            c += (a - b) ** 2
        c = c ** (1/2)
        if c == int(c):
            res += 1
    print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
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(N):
        dist = 0
        if i == j:
            continue
        for d in range(D):
            dist += ((X[i][d] - X[j][d])**2)
        if dist**0.5 == int(dist**0.5):
            ans += 1
print(ans//2)

Submission status: Accepted

Solution code:

import math

def sqrtable(x):
	if(x//math.sqrt(x)==math.sqrt(x)):
		return True
	else:
		return False
	

def dist(a,b):
	d=0
	for (i,it) in enumerate(a):
		d+=(it-b[i])*(it-b[i])
	return d

N=int(input().split(" ")[0])
r=[]
for i in range(N):
	r.append(list(map(int,input().split(" "))))
count=0
for i in range(N):
	for j in range(i):
		
		if (sqrtable(dist(r[i],r[j]))==True):
			count+=1
print(count)

Submission status: Accepted

Solution code:
import itertools

N, D = map(int, input().split(' '))
a = [[int(i) for i in input().split(' ')] for _ in range(N)]

count = 0
for i in itertools.combinations(a,2):
    num = 0
    for j in range(len(i[0])):
        num += (i[0][j] - i[1][j])**2

    if num**0.5 == int(num**0.5):
        count += 1

print(count)

Submission status: Accepted

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


def nijou(a,n):
    korelist = 0
    for i in range(0, n-1):
        for j in range(i+1, n ):
            c = [x - y for (x, y) in zip(a[i], a[j])]
            kore = 0
            for u in c:
                kore += u**2
            kore1 = kore ** (1/2)
            if kore1 - int(kore1) == 0:
                korelist += 1
    return print(korelist)

nijou(a,n)

Submission status: Accepted

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

dis=[]
for a in p:
    for b in p:
        n = 0
        for i in range(D):
            n = n + (a[i]-b[i])**2
        if not n==0:
            dis.append(n)
print(len([d for d in dis if int(math.sqrt(d))**2==d])//2)

Submission status: Accepted

Solution code:
import math
def dist(x, y, d):
    sum = 0
    for i in range(d):
        sum += (x[i] - y[i])**2

    return math.sqrt(sum)

N, D = map(int, input().split())
p = []

for k in range(N):
    p.append(list(map(int, input().split())))


cnt = 0
for i in range(N):
    for j in range(i+1, N):
        x = dist(p[i], p[j], D)

        if x == int(x):
            cnt += 1
    
print(cnt)

Submission status: Accepted

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

flag = 0
for y in range(len(x)):
    for z in range(y+1, len(x)):
        distance2 = 0
        for i in range(d):
            distance2 += (x[y][i] - x[z][i]) ** 2
        distance = math.sqrt(distance2)
        distance = float(distance)
        if distance.is_integer():
            flag += 1
print(flag)

Submission status: Accepted

Solution code:
N, D = [int(x) for x in input().split()]
grid = []
for _ in range(N):
    grid.append([int(x) for x in input().split()])
count = 0    
for i in range(N - 1):
    for j in range(i+1, N):
        curr_dist = 0
        for k in range(D):
            curr_dist += (grid[i][k] - grid[j][k]) * (grid[i][k] - grid[j][k])
        for k in range(128):
            if curr_dist == (k * k):
                count += 1
                break
print(count)

Submission status: Accepted

Solution code:
import math


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

ans = 0
for i in range(N):
    for j in range(i+1, N):
        tmp = 0
        for x1, x2 in zip(lst[i], lst[j]):
            tmp += (x1 - x2) ** 2
        val = math.sqrt(tmp)
        if val.is_integer():
        # if val == int(val):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math


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

ans = 0
for i in range(N):
    for j in range(i+1, N):
        tmp = 0
        for x1, x2 in zip(lst[i], lst[j]):
            tmp += (x1 - x2) ** 2
        val = math.sqrt(tmp)
        # if val.is_integer():
        if val == int(val):
            ans += 1
print(ans)

Submission status: Accepted

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

def keisan(l1,l2):
    ret = 0
    for k in range(len(l1)):
        ret += (l1[k]-l2[k])**2
    return sqrt(ret)

P = [list(map(int,input().split())) for k in range(N)]
ans = 0
for k in range(N-1):
    for l in range(k+1,N):
        if keisan(P[k],P[l]) == int(keisan(P[k],P[l])):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from itertools import combinations

def solve(N: int, D: int, X: "List[List[int]]"):
    pairs = combinations(range(N), 2)
    counter = 0
    for p in pairs:
        x1 = X[p[0]]
        x2 = X[p[1]]
        d2 = 0
        for (xx1, xx2) in zip(x1, x2):
            d2 += (xx1 - xx2) ** 2
        if float.is_integer(d2 ** 0.5):
            counter += 1
        
    print(counter)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    X = [ [ int(next(tokens)) for _ in range(D) ] for _ in range(N) ]  # type: "List[List[int]]"
    solve(N, D, X)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
x=[[0]*d]*n
for i in range(n):
  xnow=[int(n) for n in input().split()]
  x[i]=xnow
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    len2=0
    for z in range(d):
        len2+=(x[i][z]-x[j][z])**2
    for c in range(130):
      if c**2==len2:
        ans+=1
        break
      elif c**2>len2:
        break
      else:
        continue
print (ans)

Submission status: Accepted

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

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

ans=0
for i in range(N-1):
    for j in range(i+1,N):
        if distance(P[i],P[j]).is_integer():
            ans+=1

print(ans)

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 X:
    for j in X:
        dist = 0
        for k in range(D):
            dist += (i[k] - j[k])**2
        dist = math.sqrt(dist)
        if dist == int(dist):
            cnt += 1
cnt = (cnt - N)//2
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())))

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

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

Submission status: Accepted

Solution code:
import math
N,D=map(int, input().split())
x=[[''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 t in range(i+1,N):
    sum=0
    for j in range(D):
      sum=sum+(x[i][j]-x[t][j])**2
    d=math.sqrt(sum)
    if d.is_integer():
      count=count+1
print(count)

Submission status: Accepted

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

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

cnt = 0

for i in range(n):
    for j in range(i+1, n):
        tmp = 0
        for k in range(d):
            tmp += (line[i][k] - line[j][k]) ** 2
        if (tmp ** (1/2)) % 1 == 0:
            cnt += 1

print(cnt)

Submission status: Accepted

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

Xs = [n for n in range(N)]

for n in range(N):
    Xs[n] = [int(x) for x in input().split()]

count = 0
for i in range(N):
    for j in range(i+1,N):
        temp = 0
        for d in range(D):
            temp += (Xs[i][d] - Xs[j][d])**2
        temp = temp ** (1/2)
        if temp % 1 ==0:
            count+=1

print(count)

Submission status: Accepted

Solution code:
import math
N, D = (int(i) for i in input().split())
protList = []
intCounter = 0
for i in range(N):
    oneProt = list(int(i) for i in input().split())
    protList.append(oneProt)

for i in range(len(protList)):
    for j in range(i + 1, len(protList)):
        sqSum = 0
        for k in range(len(protList[i])):
            sqSum += (protList[i][k] - protList[j][k]) ** 2 
        if math.sqrt(sqSum).is_integer():
            intCounter += 1
            
print(intCounter)

Submission status: Accepted

Solution code:
import math

n, m = [int(w) for w in input().split()]
points = []


for i in range(n):
    points.append([int(w) for w in input().split()])

count = 0

for i in range(n):
    for j in range(i + 1, n):
        dist = sum([(x1 - y1) ** 2 for x1, y1 in zip(points[i], points[j])])
        dist = math.sqrt(dist)
        # print(dist)
        if dist.is_integer():
            count += 1


print(count)

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

Solution code:
import sys
import numpy as np
import math

if sys.platform =='ios':
    sys.stdin=open('input133b.txt')

#+++++

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

for i in range(n):
	for k in range(i+1,n):
		num = 0
		for j in range(d):
			num += pow(abs(anums[i][j] - anums[k][j]),2)

		sq = math.sqrt(num)
		if sq.is_integer():
			count += 1

print(count)

Submission status: Accepted

Solution code:
import sys
import numpy as np
import math

if sys.platform =='ios':
    sys.stdin=open('input133b.txt')

#+++++

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

for i in range(n):
	for k in range(n - i -1):
		num = 0
		for j in range(d):
			num += pow(abs(anums[i][j] - anums[i + k + 1][j]),2)

		sq = math.sqrt(num)
		if sq.is_integer():
			count += 1

print(count)

Submission status: Accepted

Solution code:
import numpy as np

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

res = 0
for i in range(N):
  for j in range(i+1,N):
    dist = np.sqrt(sum((points[i] - points[j])**2))
    if dist - int(dist) == 0:
        res += 1
print(res)

Submission status: Accepted

Solution code:
from math import sqrt
from itertools import combinations

N,D = map(int,input().split())
def dist(x,y):
  d=0
  for i in range(D):
    d += (x[i]-y[i])**2
  return d
X = [list(map(int,input().split())) for i in range(N)]

ans=0
for i,j in combinations(range(N),2):
  d = dist(X[i],X[j])
  if d == round(sqrt(d))**2:
    ans+=1

print(ans)

Submission status: Accepted

Solution code:
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))

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

cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        r = [(a - b) ** 2 for a, b in zip(X[i], X[j])]
        # print("i:{},j:{}, sqrt(r):{}".format(i, j, math.sqrt(sum(r))))
        r = math.sqrt(sum(r))
        if float.is_integer(r):
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math

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

count = 0  
for i in range(len(l)):
    for j in range(i+1, len(l)):
        l1 = l[i]
        l2 = l[j]
        s = 0
        for k in range(d):
            s += (l1[k] - l2[k])**2
        if math.sqrt(s) == int(math.sqrt(s)):
            count += 1
            
print(count)

Submission status: Accepted

Solution code:
import itertools
import numpy as np
import copy

num = list(map(int,input().split()))
plase = []
count = 0

for i in range(num[0]):
    num_list = list(map(int,input().split()))
    plase.append(num_list)

result = list(itertools.combinations(plase, 2))

for i,j in result:
    s=0
    for k in range(num[1]):
        s += (i[k]-j[k])**2
    s_2=copy.deepcopy(int(np.sqrt(s)))
    if np.sqrt(s) == s_2:
        count+=1
        
print(count)

Submission status: Accepted

Solution code:
import math

N,D = list(map(int, input().split()))
X = []
for i in range(N):
    X.append(list(map(int, input().split())))
#print(X)
c = 0
for i in range(N):
    for j in range(i+1, N):
        #print(i,j)
        a = math.sqrt(sum([(X[i][k]-X[j][k])**2 for k in range(D)]))
        #print(a, float(int(a)))
        if a-float(int(a))==0:
            c+=1
            
print(c)

Submission status: Accepted

Solution code:
def main04():
    data = input().split()
    heilist = []
    for i in range(200):
        kari = (i+1)*(i+1)
        heilist.append(kari)
    nd = []
    dislist = []
    resultnum = 0
    for i in range(2):
        nd.append(int(data[i]))
    for i in range(nd[0]):
        kari = input().split()
        karilist = []
        for j in range(nd[1]):
            karilist.append(int(kari[j]))
        dislist.append(karilist)
    for i in range(0,nd[0]-1,1):
        for j in range(i+1,nd[0],1):
            heihou = 0
            for k in range(nd[1]):
                heihou = heihou + (dislist[i][k] - dislist[j][k]) * (dislist[i][k] - dislist[j][k])
            for k in range(200):
                if heihou == heilist[k]:
                    resultnum = resultnum + 1
                    break
    print(resultnum)

if __name__ == "__main__":
    main04()

Submission status: Accepted

Solution code:
import numpy as np
n,d = map(int, input().split())
l=[]
for i in range(n):
  l.append(list(map(int, input().split())))
count = 0
for i in range(n):
  for j in range(i+1,n):
    distance_a = 0
    for k in range(d):
      distance_k= l[i][k]-l[j][k]
      distance_a +=distance_k**2
    distance = np.sqrt(distance_a)
    distance_int =int(distance)
    if distance == distance_int:
      count += 1
print(count)

Submission status: Accepted

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

count = 0
for i in range(N):
    for j in range(i + 1, N):
        dist_sq = sum((x - y) ** 2 for x, y in zip(X[i], X[j]))
        d = int(dist_sq ** 0.5)
        if dist_sq in (d ** 2, (d + 1) ** 2):
            count += 1
print(count)

Submission status: Accepted

Solution code:
import math

N, D = [int(i) for i in(input().split(' '))]
in_list = []
for i in range(N):
    l = [int(i) for i in (input().split(' '))]
    in_list.append(l)
count=0
for i in range(N):
    for k in range(i+1,N):
        num = 0
        for j in range(D):
            ab = abs(in_list[i][j]-in_list[k][j])
            num += pow(ab,2)
            if j==D-1:
                if int(math.sqrt(num))==math.sqrt(num):
                    count += 1
print(count)

Submission status: Accepted

Solution code:
def dist(a, b):
  res = 0
  for i in range(D):
    res += (a[i] - b[i]) ** 2
  res = res ** 0.5
  return res

N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
ans = 0
for i in range(N - 1):
  for j in range(i +1, N):
    if dist(X[i], X[j]).is_integer():
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math

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

def calc_dist(A,B):
  n=0
  for (a, b) in zip(A,B):
    n+=(a-b)**2
  return math.sqrt(n)

N,D=map(int, input().split())
mylist=list(list(map(int, input().split())) for n in range(N))
count=0
for i in range(N-1):
  for j in range(i+1,N):
    dist=calc_dist(mylist[i],mylist[j])
    if is_int_num(dist):
      count+=1
print(count)

Submission status: Accepted

Solution code:
import numpy as np

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

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

for j in range(N):
    for k in range(j+1, N):
        cnt += (1 if np.linalg.norm(X[j] - X[k]).is_integer() else 0)        

print(cnt)

Submission status: Accepted

Solution code:
import math
n,d = map(int,input().split())
x = []
for i in range(0,n):
    x.append(list(map(int,input().split())))
def f(a,b):
    s = 0
    for l in range(0,d):
        s+=(a[l]-b[l])**2
    return math.sqrt(s)
count = 0
for j in range(0,n):
    for k in range(0,n):
        if not (j==k):
            if f(x[j],x[k])%1==0:
                count = count + 1

print(int(count/2))

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

print(cnt)

Submission status: Accepted

Solution code:
import math
import numpy as np

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

x = np.zeros([n, d])

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

cnt = 0

for i in range(n):
    for j in range(i+1, n):
        xx = (x[i] - x[j]) ** 2
        dist = math.sqrt(xx.sum())
        if dist % 1 == 0:
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import itertools
import math

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

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

all_comb = list(itertools.combinations_with_replacement(all_point, 2))
for comb in all_comb:
    if comb[0] != comb[1]:
        distance = math.sqrt(sum([(x - y)**2 for x, y in zip(comb[0], comb[1])]))
        if distance == int(distance):
            count = count + 1

print(count)

Submission status: Accepted

Solution code:
import math

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

    count = 0
    for d1 in range(N):
        d2_init = d1+1
        for d2 in range(d2_init, N):
            distance = dist(data[d1], data[d2])
            # print(distance)
            if distance == int(distance):
                count = count + 1

    print(count)
        
    return

def dist(a_list, b_list):
    total = 0.0
    for a,b in zip(a_list, b_list):
        total = total + pow((a-b),2)
    total = math.sqrt(total)
    return total

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import math

n,d = map(int,input().split())
#xy = [list(map(float,input().split())) for i in range(n)]
xy = []
for i in range(n):
  xy.append(list(map(float,input().split())))
count = 0
for i in range(n):
  for j in range(i+1,n):
    dis=0
    for k in range(d):
      dis += (xy[i][k]-xy[j][k])**2
    dis = math.sqrt(dis)
    if dis.is_integer():
      count +=1
      
print(count)

Submission status: Accepted

Solution code:
import math as m
n, d=map(int, input().split())
a=[]
p=[]
q=[]
for _ in range(n):
	a.append(list(map(int, input().split())))
for i in range(n):
	k=i+1
	while k<n:
		x=0
		for j in range(d):
			x+=(a[i][j]-a[k][j])**2
		x=m.sqrt(x)
		p.append(x)
		q.append(int(x))
		k+=1
x=0
for i in range(len(p)):
	if p[i]==q[i]:
		x+=1
print(x)

Submission status: Accepted

Solution code:
import math
def dis(x,i,j,d):
    count = 0
    for y in range(d):
        count = count + (x[i][y] - x[j][y])**2
    m = math.sqrt(count)
    if m - int(m) == 0:
        return 1
    else:
        return 0
n,d = map(int,input().split())
x = []
for i in range(n):
    x1 = list(map(int,input().split()))
    x.append(x1)
count1 = 0
for i in range(n):
    for j in range(i+1,n):
        count1 = count1 + dis(x,i,j,d)
print(count1)

Submission status: Accepted

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

cnt = 0
for a, b in combinations(X, 2):
    dist = 0
    for i in range(D):
        dist += (a[i] - b[i]) ** 2
    if dist ** 0.5 % 1 == 0:
        cnt += 1
print(cnt)

Submission status: Accepted

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

count = 0

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

print(count)

Submission status: Accepted

Solution code:
from itertools import combinations
import numpy as np

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

ans = 0
for y, z in combinations(x, 2):
    d = np.linalg.norm(y - z)
    if int(d) == d:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

N, D = map(int, input().split())
X = [ list(map(int,input().split())) for i in range(N)]
sum = 0
count = 0
for i in range(N):
  for j in range(i+1,N):
    d = 0
    sum = 0
    for k in range(D):
      sum += (X[i][k] - X[j][k])**2
    d = np.sqrt(sum)
    if d // 1 == d:
      count +=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

my_list = []
N, D = map(int, input().split())
for i in range(N):
    my_list.append(list(map(int, input().split())))
count = 0
for k in range(N-1):
	for i in range(k+1,N):
		sum = 0
		for j in range(D):
			sum =sum + ((int(my_list[i][j])-int(my_list[k][j]))**2)
		dist = math.sqrt(sum)
		if dist == int(dist):
			count = count+1
print (count)

Submission status: Accepted

Solution code:
import numpy as np
n, d = (int(x) for x in input().split())
ls = []
for i in range(n):
    ls.append([int(x) for x in input().split()])
ls = np.array(ls)
count = 0
for i in range(n):
    for j in range(i+1, n):
        dist = np.sqrt(sum(np.square(ls[i] - ls[j])))
        if dist.is_integer():
            count = count + 1
print(count)

Submission status: Accepted

Solution code:
#!/usr/bin.env python

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

x = []

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

c = 0
for i,j in enumerate(x):
    for a,b in enumerate(x[i+1:]):
        dis = 0
        for m,n in enumerate(j):
            dis += (j[m] - b[m])**2
        dis = dis ** (1/2)
        if dis.is_integer() == True:
            c += 1

print(c)

Submission status: Accepted

Solution code:
# b.py
n,d = map(int,input().split())
lis = [list(map(int,input().split())) for x in range(n)]
ans = 0
for xli in range(n-1):
    for yli in range(xli,n):
        le = 0
        for x,y in zip(lis[xli],lis[yli]):
            le += (y-x) **2
        #print(xli,yli,'xli','yli')
        #print((le**0.5)//1,le**0.5,le**0.5==(le**0.5)//1 and xli != yli,'root')
        if le**0.5 == (le**0.5)//1 and xli != yli:
             ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math
def calcCordinate(cordiOne, cordiTwo):
  res = 0
  for i in range(len(cordiOne)):
    res += (cordiOne[i] - cordiTwo[i])**2
  return math.sqrt(res)
    
    

n,d = map(int, input().split())
cordinate = [[int(i) for i in input().split()] for j in range(n)]
res = 0
for i in range(n-1):
  for j in range(i+1,n):
    if calcCordinate(cordinate[i],cordinate[j]).is_integer():
      res += 1
      
print(res)

Submission status: Accepted

Solution code:
import math

def distance(a, b):
  square_dist = 0
  for i in range(len(a)):
    square_dist += (a[i] - b[i]) * (a[i] - b[i])
  return math.sqrt(square_dist)

n, d = map(int, input().split(" "))
points = []

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

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