Problem:


Score : 200 points

Problem Statement

There are N points in a D-dimensional space.

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

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

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

Constraints

All values in input are integers.

2 \leq N \leq 10

1 \leq D \leq 10

-20 \leq X_{ij} \leq 20

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

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

3 2
1 2
5 5
-2 8

Sample Output 1

1

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

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

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

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

Sample Input 2

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

Sample Output 2

2

Sample Input 3

5 1
1
2
3
4
5

Sample Output 3

10



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


Sample output:
1

Submission status: Accepted

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


for i in range(n-1):
    for j in range(i+1,n):
        count1 = 0
        for s in range(d):
            count1 += (alllist[i][s]-alllist[j][s])**2
        if math.sqrt(count1) == int(math.sqrt(count1)):
            count += 1
print(count)

Submission status: Accepted

Solution code:
import math
def dist_is_int(x, y):
  d2 = 0
  for i in range(len(x)):
    diff = x[i] - y[i]
    d2 += diff * diff
  
  cand = int(math.sqrt(d2))
  return cand * cand == d2

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

ans = 0
for i in range(n):
  for j in range(i + 1, n):
    if dist_is_int(x_s[i], x_s[j]):
      ans += 1
print(ans)

Submission status: Accepted

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

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

# 探索する
for i in range(len(p_list)):
    for j in range(i+1, len(p_list)):
        dis = 0
        for k in range(d):
            dis += (p_list[i][k] - p_list[j][k]) ** 2
        #print(math.sqrt(dis))
        t_dis = math.sqrt(dis)
        #print(round(t_dis), t_dis, round(t_dis) == t_dis)
        if round(t_dis) == t_dis:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math

def dis(n,x,y):
    distance = 0
    for i in range(len(x)):
        distance += (x[i]-y[i])*(x[i]-y[i])
    # print(distance)
    return math.sqrt(distance)



n,d = [int(i) for i in input().split()]
x = [[int(i) for i in input().split()] for i in range(n)] 
# print(x)
ans = 0
for i in range(n):
    for j in range(i+1,n):
        # print(dis(d,x[i],x[j]))
        # print(dis(d,x[i],x[j]).is_integer())
        if(dis(d,x[i],x[j]).is_integer()):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math
n,d = map(int,input().split())
positions = [list(map(int,input().split())) for _ in range(n)]
ans = 0
for i in range(n):
    for j in range(n):
        pre = 0
        if i == j:
            continue
        for k in range(d):
            pre += abs(positions[j][k]-positions[i][k])**2
            # if i == 0 and j == 2:
                # print(pre)
        pre = math.sqrt(pre)
        if pre % 1 == 0:
            pre = int(pre)
        # print(i,j,pre)
        if isinstance(pre,int):
            ans += 1
print(ans//2)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
def goodDistance():
	N, D = map(int, input().split())
	X = [0] * (N + 1)
	for i in range(1, N + 1):
		X[i] =  list(map(int, input().split()))
	count = 0
	# print(X)
	for i in range(1, N + 1):
		for j in range(i + 1, N + 1):
			sum = 0
			for k in range(0, D):
				sum += abs(X[i][k] - X[j][k]) ** 2
				distance = math.sqrt(sum)
			# print(i, j,sum)
			if distance.is_integer():
				count += 1
	print(count)

goodDistance()

Submission status: Accepted

Solution code:
import math

inp_1 = input().split()
n = int(inp_1[0])
d = int(inp_1[1])

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

def kyori(x_list,y_list):
    dim = len(x_list)
    kyori_nibeki = 0
    for i in range(dim):
        kyori_nibeki = kyori_nibeki + (x_list[i] - y_list[i])**2
    return math.sqrt(kyori_nibeki)


count = 0
for i in range(n):
    for j in range(n):
        if j > i:
            kyori_compare = kyori(input_matrix[i],input_matrix[j])
            if kyori_compare ==  math.floor(kyori_compare):
                count = count + 1

print(count)

Submission status: Accepted

Solution code:
import math

N, D = map(int, input().split())
X = [0] * N

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

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

print(ans)

Submission status: Accepted

Solution code:
import math
n,d = list(map(int,input().split()))
x = []
result = 0
def func(i,j):
        pythagoras= 0
        for k in range(d):
                pythagoras += (i[k]-j[k])*(i[k]-j[k])
        if math.sqrt(pythagoras)%1 == 0:
                return True
        else:
                return False

for i in range(n):
        x.append(list(map(int,input().split())))
for i in range(n):
        for j in range(i+1,n):
                if func(x[i],x[j]): 
                        result += 1
print(result)

Submission status: Accepted

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

list = []
for i in range(n):
  a = [int(i) for i in input().split()] 
  list.append(a)
count = 0
for i in range(n):
  for j in range(n):
    if j > i:
      root = 0
      root2 = 0
      for k in range(d):
        tmp = (list[i][k] - list[j][k])*(list[i][k] - list[j][k])
        root = root + tmp
      root3 = math.sqrt(root)
      if root3.is_integer():
           count = count +1
print(count)

Submission status: Accepted

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

def calc(arr1, arr2):
    tmp = 0
    for i, j in zip(arr1, arr2):
        tmp += abs(i - j) ** 2
    if str(tmp ** 0.5).split('.')[1] == '0':
        return 1
    return 0

for i in range(n):
    for j in range(i+1, n):
        ans += calc(x[i], x[j])

print(ans)

Submission status: Accepted

Solution code:
import math

i = list(map(int, input().split(" ")))
n = i[0]
d = i[1]
x = []
total = 0

for x_n in range(n):
    xx = list(map(int, input().split(" ")))
    x.append(xx)

for x_n in range(len(x)):
    a = x[x_n]
    for x_d in range(x_n+1, len(x)):
        b = x[x_d]
        t = [(aa - bb)**2 for aa, bb in zip(a, b)]
        t = math.sqrt(sum(t))
        if t.is_integer():
            total += 1
print(total)

Submission status: Accepted

Solution code:

N,D=map(int,input().split())
x=[]
for i in range(N):
    z=list(map(int,input().split()))
    x.append(z)
count=0
for i in range(N):
    for j in range(N-i-1):
        d=0
        for k in range(D):

            d+=(x[i][k]-x[j+i+1][k])**2
        d=d**(0.5)

        #print(d)
        if d%1==0:
            #print(d,d%1)
            count+=1
print(count)

Submission status: Accepted

Solution code:
import numpy as np

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

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

X=np.array(X)
result=0
for i in range(N-1):
    for j in range(i+1,N):
        diff=X[i]-X[j]
        distance=np.sum(np.square(diff))
        if int(np.sqrt(distance))==np.sqrt(distance):
            result+=1

print(result)

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):
    for j in range(i + 1, N):
        b = []
        for k in range(D):
            b.append((points[i][k] - points[j][k])**2)
        b = sum(b)
        b = math.sqrt(b)
        if int(b) == b:
            count += 1

print(count)

Submission status: Accepted

Solution code:
import math

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

all_d = []

for i in range(N-1):
  for j in range(N-1-i):
    nijo = []
    nijo_sum = 0
    for k in range(D):
      nijo.append((points[i][k]-points[i+j+1][k])**2)
    for k in range(D):
      nijo_sum += nijo[k]
    all_d.append(math.sqrt(nijo_sum))

  
count = 0
for i in range(len(all_d)):
  if (all_d[i]%1) == 0:
    count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, D = list(map(int, input().split()))
X = []
for _ in range(N):
    x = list(map(int, input().split()))
    X.append(x)
ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        s = [xi - xj for xi, xj in zip(X[i], X[j])]
        e = [ss**2 for ss in s]
        t = sum(e)
        for k in range(40*40*D+1):
            if t == k**2:
                ans += 1
                break
print(ans)

Submission status: Accepted

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

count = 0
for j in range(n-1):
    for k in range(n-j-1):
        dis = 0
        for l in range(d):
            dis += abs(x[j][l] - x[j+k+1][l]) ** 2

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

print(count)

Submission status: Accepted

Solution code:
import numpy as np
import itertools

if __name__ == "__main__":
    n = list(map(int, input().split()))
    l = [np.array(list(map(int, input().split()))) for i in range(n[0])]

    n = 0

    for v in itertools.combinations(l, 2):
        #print(v)
        distance = np.linalg.norm((v[0] - v[1]), ord=2)
        #print(distance)
        #print(distance % 1)
        if distance % 1 == 0:
            n += 1

    print(n)

Submission status: Accepted

Solution code:
import sys
inputs = sys.stdin.readlines()
N, D = map(int, inputs[0].split())
x_list = []
for x in inputs[1:]:
    x_list.append(list(map(int, x.split())))
    
from itertools import combinations
from math import sqrt, floor
count = 0
for i, j in combinations(range(N), 2):
    s = 0
    for k in range(D):
        s += (x_list[i][k] - x_list[j][k]) ** 2
    if floor(sqrt(s)) ** 2 == s:
        count += 1
        
print(count)

Submission status: Accepted

Solution code:
import math

n, d = tuple([int(s) for s in input().split()])
x = [[0]*d for i in range(n)]

for i in range(n):
    x_t = [int(s) for s in input().split()]
    x[i] = x_t

cnt_fit = 0

for i in range(n-1):
    for j in range(i+1, n):
        sumd = 0
        for k in range(d):
            sumd += (x[i][k] - x[j][k]) ** 2
        sumd = math.sqrt(sumd)
        if sumd - int(sumd) == 0.0:
            cnt_fit += 1

print(cnt_fit)

Submission status: Accepted

Solution code:
import numpy as np

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

X = [0] * N

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

ok = 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 = np.sqrt(sum)
        if sum.is_integer() == True:
            ok += 1

print(ok)

Submission status: Accepted

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

line=[]
count=0

for i in range(n):
    line.append(list(map(int,input().split( ))))
    # print(line[i])
    if i>=1:
        for j in range(i):
            # print(float(np.linalg.norm(np.array(line[i])-np.array(line[j])))
            if float(np.linalg.norm(np.array(line[i])-np.array(line[j]))).is_integer():
                count+=1

print(count)

Submission status: Accepted

Solution code:
import math

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

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

print(ans)

Submission status: Accepted

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n, d = readmi()
t = []
for i in range(n):
    k = readl()
    t.append(k)
count = 0
b = defaultdict(lambda:defaultdict(int))
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        if b[i][j] == 1:
            continue
        b[i][j] = 1
        b[j][i] = 1
        p = 0
        for k in range(d):
            p += abs(t[i][k] - t[j][k]) ** 2
        if float.is_integer(math.sqrt(p)):
            count += 1
print(count)

Submission status: Accepted

Solution code:
n, d = map(int, input().split(' '))
a = [list(map(int,input().split(' '))) for i in range(n)]
res = 0
for i in range(n-1):
    for j in range(i+1, n):
        count = 0
        for k in range(d):
            count += (a[i][k]-a[j][k])**2
        count = count**(1/2)
        if (count.is_integer()) is True:
            res += 1
print(res)

Submission status: Accepted

Solution code:
def sqrtjudge(n):
    m = int(pow(n,0.5))
    return 1 if abs(m*m - n) < 1e-6 else 0

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

for i in range(n):
    for j in range(i+1,n):
        ans += sqrtjudge(sum(pow(x[i][k]-x[j][k],2) for k in range(d)))

print(ans)

Submission status: Accepted

Solution code:
import sys
import math


def input():
    return sys.stdin.readline()[:-1]


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

    for a in range(0, n-1):
        for c in range(a+1, n):
            s = 0
            for b in range(d):
                s += abs(x[a][b]-x[c][b])**2
            if math.floor(math.sqrt(s)) == math.sqrt(s):
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

import sys
import math
#from pprint import pprint
import numpy as np
def myinput_int():
    return list(map(int, input().split()))

N,D = myinput_int()

X=[]
for i in range(N) :
    X.append(myinput_int())

X = np.asarray(X)

counter=0
for i in range(N) :
    for j in range(i+1, N) :
        if np.sqrt(np.sum((X[i]-X[j])**2)).is_integer()==True:
            counter+=1

print(counter)

Submission status: Accepted

Solution code:
from math import sqrt

n, d = map(int, input().split())
x = []
for _ in range(n):
    x.append(list(map(int, input().split())))
ans = 0
for i in range(n):
    for j in range(n):
        if i != j:
            t = 0
            for a, b in zip(x[i], x[j]):
                t += abs(a - b)**2
            if sqrt(t) == int(sqrt(t)):
                ans += 1

print(ans//2)

Submission status: Accepted

Solution code:
from math import sqrt
a,b=input().split()
a=int(a)
b=int(b)
ll=[]
ans=0
for i in range(a):
  x=input().split()
  x=[int(i) for i in x]
  ll.append(x)
for i in ll:
  s=0
  for j in ll:
    if i==j:
      s=1
      continue
    elif s==0:
      continue
    x=0
    for k in range(b):
      x+=(i[k]-j[k])**2
    if sqrt(x)%1==0:
      ans+=1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

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

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

#print(listA)
#[[1, 2, 2, 3, 1], [4, 5, 3, 4, 1, 2, 3, 4], [2, 3, 5, 6, 0, 2]]


cnt = 0

for i in range(N):
	for j in range(N):
		if i!=j and i < j: 
			dist = 0
			for k in range(D):
				dist += (listA[i][k] - listA[j][k])**2
			#print(np.sqrt(dist))
			if np.sqrt(dist).is_integer()==1:
				cnt += 1


print(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())))
count = 0
for i in range(N):
    for j in range(i+1, N):
        cnt = 0
        for k in range(D):
            cnt += abs(x[i][k] - x[j][k]) ** 2
        ans = math.sqrt(cnt)
        if ans.is_integer():
            count += 1
print(count)

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):
        nor = math.sqrt(sum([(x[i][k]-x[j][k])**2 for k in range(d)]))
        
        if nor.is_integer():
#            print(nor)
            ans+=1

print(ans)

Submission status: Accepted

Solution code:
from math import floor,ceil
n,d=map(int,input().split())
P=[list(map(int,input().split())) for _ in range(n)]
def judge(A,B):
    d=len(A)
    s=0
    for i in range(d):
        s+=(A[i]-B[i])**2
    s=s**0.5
    return floor(s)==ceil(s)
ans=0
for i in range(n):
    for j in range(i+1,n):
        ans+=judge(P[i],P[j])
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        tmp = np.sum((X[i] - X[j]) ** 2)
        if tmp % np.sqrt(tmp) == 0.0:
            ans += 1
print(ans)

Submission status: Accepted

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

ten = []

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

count = 0
for i in range(N):
    s = 0
    for j in range(i+1, N):
        for k in range(D):
            ss = ten[i][k]-ten[j][k]
            if ss < 0: ss = -ss

            s2 = pow(ss, 2)

            s += s2

        ans = math.sqrt(s)
        if ans.is_integer()==True:
            count += 1
        s = 0

print(count)

Submission status: Accepted

Solution code:
import itertools

n,d=map(int,input().split())
x=[]
for i in range(n):
    x.append(list(map(int,input().split())))
cnt=0
for k in itertools.combinations(x,2):
    tmp=0
    for m in range(d):
        tmp+=(k[0][m]-k[1][m])**2
    for l in range(200):
        if l**2==tmp:
            cnt+=1
            break
        else:
            pass
print(cnt)

Submission status: Accepted

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


import itertools,math
dis = []
for x in itertools.combinations(x_list_kai,2):
    distance = 0
    for dim in range(0,d):
        result  = 0
        for y in x:
            if result == 0:
                result = y[dim]
            else:
                result -= y[dim]
            
        result  = result **2
        distance += result
    dis.append(math.sqrt(distance))
    
counter = 0
for i in dis:
    if i.is_integer() == True:
        counter += 1
print(counter)

Submission status: Accepted

Solution code:
N, D = map(int,input().split())
listA = []
for i in range(N):
    listA.append(list(map(int,input().split())))
import numpy
a = 0
for i in range(N - 1):
    for j in range(i+1):
        b = numpy.linalg.norm((numpy.array(listA[i+1])-numpy.array(listA[j])))
        if b-int(b) == 0:
            a += 1
print(a)

Submission status: Accepted

Solution code:
from enum import Enum
from queue import Queue
import collections
import numpy as np


import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

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(i+1,N):
        dist=0
        for k in range(D):
            dist += abs(X[i][k]-X[j][k])**2
        dist = np.sqrt(dist)
        if dist.is_integer():
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

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

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

Submission status: Accepted

Solution code:
from math import sqrt

n, d = map(int, input().split())
x = []
cnt = 0
for i 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):
        dist = sqrt(sum([(x1-x2)**2 for (x1, x2) in zip(x[i], x[j])]))
        if dist.is_integer():
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math


def distance(X, Y):
    d = 0
    for x, y in zip(X, Y):
        d += (x - y)**2
    return math.sqrt(d)


str = input()

N, D = map(int, str.split(" "))

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

X = list(map(list, X))

count = 0
for i in range(N):
    for j in range(i + 1, N):
        d = distance(X[i], X[j])
        if d.is_integer():
            count += 1

print(count)

Submission status: Accepted

Solution code:
import math

def judge_d(a,b):
    ans = 0
    for i, j in zip(a, b):
        ans += (i-j)**2

    if math.sqrt(ans).is_integer():
        return 1
    else:
        return 0



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

for i,v in enumerate(x):
    # print(i)
    if n-i >1:
        for j in range(i+1,n):
            # print(i,j)
            ans += judge_d(x[i],x[j])

print(ans)

Submission status: Accepted

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

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

x = [[0]*d for _ in range(n)]
for i in range(n):
    temp = list(map(int, input().split()))
    for j in range(d):
        x[i][j] = temp[j]
ans = 0
cnt = 0
for i in range(n):
    for j in range(i+1, n):
        temp = 0
        for k in range(d):
            temp += abs(x[i][k] - x[j][k])**2
        temp = math.sqrt(temp)
        if temp == int(temp):
            cnt += 1
print(cnt)

Submission status: Accepted

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


#nums = [[0 for _ in range(d)] for _ in range(n)]
nums = []

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

ans = 0
tmp = 0
for i in range(n-1):

    for j in range(i+1, n):
        tmp = 0
        for k in range(d):
            tmp += (nums[i][k] - nums[j][k])**2


        #print((tmp))
        if math.sqrt(tmp).is_integer():
            
            ans += 1

                

print(ans)

Submission status: Accepted

Solution code:
import math

def is_int(s):
  if s.is_integer():
  	return int(s)
  else:
  	s

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

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

for i in range(n):
	for j in range(i+1,n):
		sum = 0
		for k in range(d):
			sum+=(A[i][k]-A[j][k])**2
		q=is_int(math.sqrt(sum))
		# print(math.sqrt(sum))
		# print(q)
		if isinstance(q, int):
			ans+=1
print(ans)

Submission status: Accepted

Solution code:
import math
N,D=map(int,input().split())
A=[]
count=0
total=0
L=0
for i in range(N):
    B=list(map(int,input().split()))
    A.append(B)
#print(A)
for i in range(N):
    for k in range(i+1,N):
        for j in range(D):
            total +=(A[i][j]-A[k][j])*(A[i][j]-A[k][j])
        #print(total)
        L=math.floor(math.sqrt(total))
        #print(L)
        #print(math.sqrt(total))
        if math.sqrt(total)==L:
            count +=1
        total=0
print(count)

Submission status: Accepted

Solution code:
import math
N,D = map(int,input().split(" "))
c = 0
def ds(one,two):
    temp = 0
    for i in range(D):
        temp += abs(one[i] - two[i])**2
    return math.sqrt(temp)

list = []
for i in range(N):
    X = input().split(" ")
    X = [int(i) for i in X]
    list.append(X)
#print(list)
dist_mt = []
for i in range(N):
    temp = []
    for j in range(N):
        if i == j:
            el = 0
        else:
            el = ds(list[i],list[j]) 
        temp.append(el)     
    dist_mt.append(temp)
#print(dist_mt)
for i in range(N):
    for j in range(N):
        if i != j and dist_mt[i][j].is_integer() == True:
            c += 1
print(int(c/2))

Submission status: Accepted

Solution code:
import numpy as np

N, D = map(int, input().split())
xlist = np.array([tuple(map(int, input().split())) for i in range(N)])

from scipy.spatial import distance
smm = distance.cdist(xlist, xlist)

c = 0
for i in smm.flatten():
  if i != 0 and i.is_integer():
  	c += 1

print(int(c/2))

Submission status: Accepted

Solution code:
import math
import numpy as np

N, D = map(int, input().split())
p = [[int(i) for i in input().split()] for i in range(N)]
X = np.array(p)
count = 0
for i in range(N):
    j = i + 1
    while(j < N):
        test = X[i] - X[j]
        dist = math.sqrt(sum(test * test))
        if(dist.is_integer()):
            count += 1
        j += 1
print(count)

Submission status: Accepted

Solution code:
import math

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

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

for i in range(n):
    for j in range(i+1, n):
        r2 = 0
        for k in range(d):
            r2 =  r2 + (x[i][k] - x[j][k])**2

        r = math.sqrt(r2)
        ans += r.is_integer()

print(ans)

Submission status: Accepted

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

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

x = np.array(X)
print(sum([np.linalg.norm(x[i]-x[j]).is_integer() for i in range(N-1) for j in range(i+1,N)]))

Submission status: Accepted

Solution code:
s = input().split()
N = int(s[0])
D = int(s[1])
Vector = []
for i in range(N):
    s = input().split()
    Vector.append(list(map(int,s)))

def distance(vec1,vec2,D):
    ans = 0
    for i in range(D):
        ans = ans + abs(vec1[i]- vec2[i]) * abs(vec1[i] - vec2[i])
    return ans
count = 0
for i in range(N):
    for j in range(i,N):
        dis = distance(Vector[i],Vector[j],D)
        dis = dis**0.5
        if i == j:
            continue
        if abs(dis- int(dis)) < 0.000000000001:
            count = count + 1

print(count)

Submission status: Accepted

Solution code:
def main():
    import sys
    import math
    input = sys.stdin.readline
 
    n, d = [int(i) for i in input().split()]
    
    table = [[int(i) for i in input().split()] for n in range(n)]
 
    count = 0
    
    for i in range(n):
        for j in range(i+1, n):
            temp = 0
            for x in range(d):
                temp += (table[i][x] - table[j][x]) ** 2
          
            rt = math.sqrt(temp)
            if rt.is_integer():
                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)]

def dist(y,z):
	summ = 0
	for i in range(d):
		summ += (y[i]-z[i])**2
	return summ**(1/2)
	
ans_list = []
for ii in range(n):
	for jj in range(n):
		if ii < jj:
			dis = dist(x[ii],x[jj])
			if dis.is_integer():
				ans_list.append(dis)
print(len(ans_list))

Submission status: Accepted

Solution code:
import itertools
import math

N, D = [int(x) for x in input().strip().split()]
if D == 1:
    print(int(N*(N-1)/2))
else:
    points = []
    for data in range(N):
        points.append([int(x) for x in input().strip().split()])

    result = 0
    for p1,p2 in itertools.combinations(points, 2):
        distance = 0
        for y,z in zip(p1,p2):
            distance += (y - z) ** 2
        
        distance = math.sqrt(distance)
        if distance.is_integer(): result += 1    
    print(result)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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(i + 1, n):
        d2 = 0
        for k in range(d):
            d2 += (x[i][k] - x[j][k])**2
        dist = int(d2**0.5)
        if dist * dist == d2:
            ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import numpy as np


if __name__ == '__main__':
    n,d  = list(map(int, input().split(" ")))

    coord_list = []
    count = 0
    for i in range(n):
        new_coord = list(map(int, input().split(" ")))
        if coord_list != None:
            for coord in coord_list:
                norm = np.linalg.norm(np.array(coord) - np.array(new_coord))
                if float.is_integer(norm) == True:
                    count += 1
            coord_list.append(new_coord)
        else:
            coord_list = [new_coord]
    print(count)

Submission status: Accepted

Solution code:
import sys
p = [[int(t) for t in r.split(' ')] for r in sys.stdin.read().split('\n') if r != '']
N, D = p[0]
count = 0
for i in range(1, N):
    for j in range(i + 1, N + 1):
        s = sum(map(lambda t: (t[0]-t[1])**2, [i for i in zip(p[i], p[j])]))
        if int(s**0.5)**2 == s:
            count += 1
print(count)

Submission status: Accepted

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

from math import sqrt

res = 0
for i in range(n-1):
    for j in range(i+1, n):
        r2 = sum([(points[i][k]-points[j][k])**2 for k in range(d)])
        if r2 == int(sqrt(r2))**2:
            res += 1
print(res)