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 itertools
import numpy

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

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

list(itertools.combinations(s,2))

count = 0

for element in itertools.combinations(s, 2):
    #print(element[0])
    #print(element[1])
    a =	numpy.array(element[0])
    b =	numpy.array(element[1])
    u =	b - a
    #print(numpy.linalg.norm(u))
    if(numpy.linalg.norm(u).is_integer() == True):
    	count =	count + 1


print(count)

Submission status: Accepted

Solution code:
# coding=utf-8

###
### for atcorder program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

def get_input():
    N = []
    while True:
        try:
            N.append(input())
            #N.append(int(input()))
            #N.append(float(input()))
        except EOFError:
            break
    return N

def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()

def dist(A, B):
    d = 0
    for i in range(len(A)):
        d += (A[i]-B[i])**2            
    d = d**(1/2)
    return d

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

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

count = 0

for i in range(len(X)):
    for j in range(i+1,len(X)):
        d = dist(X[i],X[j])
        if is_integer(d):
            count += 1
            #print(d)
print(count)

Submission status: Accepted

Solution code:
import numpy as np
from sys import stdin

N,D=[int(x) for x in stdin.readline().rstrip().split()]
data = [stdin.readline().rstrip().split() for _ in range(N)]

ret=0
for i in range(N-1):
    a=[ int(x) for x in data[i]]
    for j in range(i+1,N,1):
        b=[ int(x) for x in data[j]]
        u = np.array(b) - np.array(a)
        c = np.linalg.norm(u)
        de,inte=np.modf(c)
        if de == 0:
            ret+=1
            # print(a,end=" ")
            # print(b)

print(ret,flush=True)

Submission status: Accepted

Solution code:
import math
N,D = map(int,input().split())
lists = []
seisuu = []
cnt = 0
for i in range(N):
    X = list(map(int,input().split()))
    lists.append(X)
for i in range(N):
    for j in range(i+1,N):
        list_A = lists[i]
        list_B = lists[j]
        cnt = 0
        for k in range(D):
            cnt += abs(list_A[k] - list_B[k])**2
        m = float(math.sqrt(cnt))
        if m.is_integer():
         seisuu.append(m)
print(len(seisuu))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

Dot_Num, N_Dimention= (int(i) for i in input().split())
Dot = [[int(i) for i in input().split()] for i in range(Dot_Num)]
count=0

for n in range(0, len(Dot)):
    for j in range(n+1, len(Dot)):
        SUM = math.sqrt(sum(pow(Dot[n][i]-Dot[j][i],2) for i in range(N_Dimention)))
        if SUM.is_integer():
            count+=1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N,D=map(int,input().split())
L=[list(map(int,input().split())) for i in range(N)]
ans=0
for n in range(N):
	for n2 in range(n+1,N):
		tmp=0
		for d in range(D):
			tmp+=abs(L[n][d]-L[n-n2][d])**2
		if math.sqrt(tmp) % 1 == 0:
			ans+=1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
ans = 0
s = 0
n,d = map(int,input().split())
a =[]
for _ in range(n):
  ar = list(map(int,input().split()))
  a.append(ar)
for i in range(n):
  for j in range(i+1,n):
    for k in range(d):
      s += (a[i][k]- a[j][k])**2
    c = float(np.sqrt(s))
    if c.is_integer() == True:
      ans += 1
    s = 0
print(ans)

Submission status: Accepted

Solution code:
N, D = [int(i) for i in input().split()]
X=[]
ans=0
for j in range(N):
    X.append([int(i) for i in input().split()])

for i in range(N):
    for j in range(i+1,N):
        y=X[i]
        z=X[j]
        tmp=0
        for k in range(D):
            tmp += (y[k]-z[k])**2
        tmp2 = tmp ** 0.5
        if tmp2.is_integer():
            ans+=1   
         
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
input_arr = [int(x) for x in input().split()]

N = input_arr[0]
D = input_arr[1]


point = []

for i in range(N):
    input_num = [int(x) for x in input().split()]
    point.append(input_num)
count = 0

for i in range(N):
    for j in range(i+1,N):
        a = np.array(point[i])
        b = np.array(point[j])
        u = b - a
        distance = (np.linalg.norm(u))
        if distance.is_integer():
            count = count +1
            
print(count)

Submission status: Accepted

Solution code:
import numpy as np

n,d=map(int,input().split())
arr=[]
for i in range(n):
  arr.append(list(map(int,input().split())))
arr =np.array(arr)
ans=0
for i in range(n):
  for j in range(i,n):
    if j!=i:
      k = np.linalg.norm(arr[i]-arr[j],ord=2)
    else:
      k=0.5
    if k==int(k):
      ans +=1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import itertools

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

poi=list(itertools.combinations(ten, 2))

for i in range(len(poi)):
    c=np.array(poi[i][0])
    b=np.array(poi[i][1])
    l = np.linalg.norm(b-c)
    if l%1==0:
        a += 1

print(a)

Submission status: Accepted

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

a = 0

for j in (range(N)):
    for k in (range(N)):
        if j > k:
            dif = 0
            dis = 0
            for n in range(D):
                dif += (E[j][n]-E[k][n])**2
                dis = pow(dif, 0.5)
            if dis.is_integer():
                a += 1

print(a)

Submission status: Accepted

Solution code:
import math

N, D = [int(item) for item in input().split()]
X=[]
res = 0
for i in range(N):
  X.append([int(item) for item in input().split()])
for i in range(N):
  for j in range(i+1, N):
    x1 = X[i]
    x2 = X[j]
    dis = 0
    for d in range(D):
      dis += abs(x1[d]-x2[d])**2
    dis = math.sqrt(dis)
    if int(dis) == float(dis):
      res += 1
print (res)

Submission status: Accepted

Solution code:
import math

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

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

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

print(An)

Submission status: Accepted

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

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

cnt = 0
for p1, p2 in itertools.combinations(points, r=2):
    d = np.linalg.norm(np.array(p1) - p2)
    if d == int(d):
        cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def he(cc):
    aa = 1
    while(cc>aa*aa) :
        aa += 1
    if(cc==aa*aa) :
        return True
    else :
        return False


n,d = map(int,input().split())
a = []
b = []
cnt = 0 
for z in range(n) :
    a.append([int(x) for x in input().split(' ')])


for i in range(n-1) :
    for j in range(i+1,n) :
        c = map(lambda x,y: abs(x-y) * abs(x-y), a[i], a[j])
        # print(str(i) + ' ' + str(j) + ' ' + str(sum(c)))
        if(he(sum(c))) :
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math

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

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

cnt = 0
for i in range(N):
    for j in range(i):
        a = ll[i]
        b = ll[j]
        ans = 0
        for iii in range(D):
            ans += (a[iii] - b[iii]) ** 2
        t = math.sqrt(ans)
        if t == int(t):
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
def sqrt(n):
    m = int(n**.5)
    return 1 if abs(m*m - n) < 1e-6 else 0

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

ans = 0

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

Submission status: Accepted

Solution code:
import numpy as np
n,d = map(int,input().split())
ans=0
g=[]
if d==1:
    for _ in range(n):
        lis = np.array(list(map(int,input().split())))
    ans=n*(n-1)//2
    print(ans)
else:
    for _ in range(n):
        lis = np.array(list(map(int,input().split())))
        for i in range(len(g)):
            u = g[i]-lis
            z=np.linalg.norm(u)
            if z==int(z):
                ans+=1
        g.append(lis)
    print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations as pt
import math

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

data = [[int(_) for _ in input().split()] for i in range(N)]

# print('input')
# print('N:', N)
# print('D:', D)
# print('data:\n', data)

def dist(p1, p2):
    a = 0
    for i in range(D):
        a += (p1[i] - p2[i]) ** 2
    b = math.sqrt(a)
    return b

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

# exec
num = 0
for comb in pt(range(N), 2):
    # global num
    p1 = data[comb[0]]
    p2 = data[comb[1]]
    a = dist(p1, p2)
    # print(comb[0], comb[1], a)
    if is_integer(a):
        num += 1

print(num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
import itertools

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

X = []

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

X = np.array(X)

cnt = 0
for i, j in itertools.combinations(range(n), 2):
    dist = np.linalg.norm(X[i] - X[j])
    if dist == int(dist):
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math

n, d = map(int, input().split())
a_list = []
result = 0
count = 0
while count < n:
    a_list.append(list(map(int, input().split())))
    count += 1

def calculate_distance(a, b, axis_count):
    hoge = 0
    for i in range(axis_count):
        hoge += abs((a[i] - b[i])**2)
    return math.sqrt(hoge)

for i in range(n):
    for j in range(n-i):
        distance = calculate_distance(a_list[i], a_list[j+i], d)
        if distance != 0 and distance.is_integer():
            result += 1
print(result)

Submission status: Accepted

Solution code:
import math
import itertools

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

points = []
counter = 0
num = []
for i in range(N):
	points.append(list(map(int, input().split())))
	num.append(i)
  
for v in itertools.combinations(num, 2):
	length2 = 0
	i1 = int(v[0])
	i2 = int(v[1])
	for j in range(D):
		length2 += (points[i1][j] - points[i2][j])*(points[i1][j] - points[i2][j])
	length = math.sqrt(length2)
	if(length.is_integer()):
		counter += 1
  
print(counter)

Submission status: Accepted

Solution code:
import numpy as np

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

ans = 0
for i in range(N):
    for j in range(N):
        if(i > j):
            dist = np.linalg.norm(X[i]-X[j])
            if dist.is_integer():
                ans += 1
print(ans)

Submission status: Accepted

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

def calculate_distance(in1, in2):
    list1 = np.array(in1) 
    list2 = np.array(in2) 
    sub_list = list1 - list2
    pow_list = np.power(sub_list, 2)
    sum_number = sum(pow_list)
    distance = math.sqrt(sum_number)

    return distance

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

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

number = 0
for n in range(N):
    for nn in range(n+1, N):
        distance = calculate_distance(X[n], X[nn])
        if distance.is_integer() is True:
            number += 1

print(number)

Submission status: Accepted

Solution code:
import math

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

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

distance = []

for i in range(n):
  for j in range(n):
    di = 0
    for k in range(d):
      di += (x[i][k]-x[j][k])**2
    di = math.sqrt(di)
    if (di == int(di)):
      distance.append(di)

print('{0}'.format(int((len(distance)-n)/2)))

Submission status: Accepted

Solution code:
arg0 = list(map(int, input().split()))

arg_array = []

for i in range(arg0[0]):
  arg = list(map(int, input().split()))
  arg_array.append(arg)

counter = 0
for i in range(arg0[0]):
  for j in range(i+1, arg0[0]):
    distance = 0
    
    for k in range(arg0[1]):
      distance += (arg_array[i][k] - arg_array[j][k]) ** 2
    
    distance = distance ** (1.0/2)
    if distance == int(distance):
      counter += 1

print(counter)

Submission status: Accepted

Solution code:
from sys import stdin

def bisearch(f, n):
    l = 0
    r = n
    fl = f(l)
    fr = f(r)
    while l <= r:
        m = (l + r) // 2
        fm = f(m)
        if fm == n:
            return True
        elif fm > n:
            r = m - 1
            fr = f(r)
        else:
            l = m + 1
            fl = f(l)
    return False

def is_sqrt(n):
    return bisearch(lambda m: m * m, n)

def main():
    N, D = map(int, input().split())
    X = [tuple(map(int, input().split())) for _ in [0] * N]

    ans = 0
    for i in range(N - 1):
        for j in range(i + 1, N):
            n = 0
            for d in range(D):
                n += (X[i][d] - X[j][d]) ** 2
            ans += is_sqrt(n)
    print(ans)

input = lambda: stdin.readline()
main()

Submission status: Accepted

Solution code:
import math
n,d = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(n)]
def cheak(y,z):
    counter = 0
    for i in range(d):
        counter += (y[i]-z[i])**2
    if math.sqrt(counter).is_integer():
        return True
    return False
count = 0
for i in range(n):
    for k in range(i+1,n):
        if(cheak(x[i],x[k])):
            count+=1
print(count)

Submission status: Accepted

Solution code:
import math

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

for i in range(N):
    r1 = X[i]
    for j in range(N):
        t = str(i)+str(j)
        if i == j or t in tmp or str(j)+str(i) in tmp:
            continue

        r2 = X[j]
        ls = [(r1[j] - r2[j])**2 for j in range(D)]
        res = math.sqrt(sum(ls))

        if res % 1 == 0:
            count += 1
        tmp.append(t)

print(count)

Submission status: Accepted

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

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

cnt = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        tmp = 0.0
        for k in range(d):
            tmp += pow((x[i][k] - x[j][k]), 2)

        tmp = math.sqrt(tmp)
        cnt += tmp.is_integer()

print(cnt)

Submission status: Accepted

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

pow2 = set()
for i in range(40**2*10):
    pow2.add(i**2)

ans = 0
for i in range(N):
    for j in range(i+1, N):
        xi = X[i]
        xj = X[j]
        sum = 0
        for k in range(D):
            sum += (xi[k] - xj[k])**2
        if sum in pow2:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math

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

ans = 0
for i in range(n):
  ai = a_list[i]
  for j in range(i+1,n):
    aj = a_list[j]
    l = math.sqrt(sum([(x-y)**2 for (x,y) in zip(ai, aj)]))
    if l - round(l) == 0:
      ans += 1

print(ans)

Submission status: Accepted

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

count = 0
m = 0
k = n-1
while m < k:
    for i in range(m,n-1):
        an = 0
        for j in range(d):
            an += abs(ls[m][j] - ls[i+1][j])**2
        if ((math.sqrt(an)).is_integer()) == True:
            count += 1
    m += 1
print(count)

Submission status: Accepted

Solution code:
import math
from collections import deque

# 2つの入力を空白で分割し、数値化
N, D = map(int, input().split())

points = []

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


def distance(x, y):
    dd = 0
    for xy in zip(x,y):
        dd += (xy[0] - xy[1])**2
    return math.sqrt(dd)

q = deque(points)

result = 0
while len(q) != 0:
    left = q.popleft()
    for right in q:
        d = distance(left, right)
        if d.is_integer():
            result += 1
        else:
            pass

print(result)

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())
x = []
for i in range(n):
    x.append([int(j) for j in input().split()])
c = 0
for i in range(n-1):
    for j in range(i+1,n):
        dist = 0
        for a in range(d):
            dist += (x[i][a] - x[j][a]) * (x[i][a] - x[j][a])
        if is_integer(math.sqrt(dist)):
            c += 1
print(c)

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


dis = []
for i in range(n):
    for j in range(n):
        distanse = 0
        for k in range(d):
            distanse += abs(x[i][k]-x[j][k])**2
        dis.append(math.sqrt(distanse))

ans = 0
for i in dis:
    a = i
    if a.is_integer() == True:
        ans += 1
print(int((ans-n)/2))

Submission status: Accepted

Solution code:
import sys
all_data = sys.stdin.readlines()

line1 = [int(a) for a in all_data[0].split()]
points_num = line1[0]
dimensions = line1[1]

data_int = []
for item in all_data[1:points_num + 1]:
    tuple_str = item.split()
    tuple_int = [int(a) for a in tuple_str]
    data_int.append(tuple_int)
    
def dii(coor1, coor2):
    import math
    pyth_sum = 0
    for dimension in range(0, dimensions):
        pyth_sum += (coor1[dimension] - coor2[dimension])**2
    distance = math.sqrt(pyth_sum)
    if distance % 1 == 0:
        return True
    else:
        return False

num_pairs = 0

for idx1, val1 in enumerate(data_int):
    coor1 = val1
    for idx2, val2 in enumerate(data_int[idx1 + 1:]):
        coor2 = val2
        if dii(val1, val2):
            num_pairs += 1

print(num_pairs, end="")

Submission status: Accepted

Solution code:
import math
n,d = map(int,input().split())
lis = []
for i in range(n):
  lis.append(list(map(int,input().split())))
r = 1
res = 0
#print(lis)
for i in range(n):
  for j in range(r,n):
    tmp = 0
    for k in range(d):
      tmp += abs(lis[i][k]-lis[j][k])**2
    rtmp = math.sqrt(tmp)
    #print(rtmp)
    if rtmp.is_integer():
      res += 1
  r+=1
print(res)

Submission status: Accepted

Solution code:
from math import factorial
import itertools
n,d =map(int,input().split())
x=[]
cnt=0
n_lis = [i for i in range(n)]
n_list = list(itertools.combinations(n_lis, 2))
for i in range(n):
    tmp = list(map(int,input().split()))
    x.append(tmp)
    
for index1, index2 in n_list:
    if d != 1:
        dist = 0
        for ind in range(d):
            dist += (x[index1][ind]-x[index2][ind])**2
        if int(dist **(1/2)) == dist **(1/2):
            cnt+=1
    if d == 1:
        cnt = int(factorial(n) / factorial(2) / factorial(n - 2))

print(cnt)

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 i in range(N)] 

def Distanse_int(x,y,D):
    A=0
    for i in range(D):
        A = A + (x[i]-y[i])**2
       
    B = np.sqrt(A)
    if B == int(B):
        return(1)
    else:
        return(0)

count = 0

for i in range(N-1):
    for k in range(i+1,N):
        B = Distanse_int(X[i],X[k],D)
        if B == 1:
            count = count + 1

print(count)

Submission status: Accepted

Solution code:
import math

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

ans = 0

for i in range(N):
    for j in range(N):
        if j <= i:
            continue
        temp = 0
        for k in range(D):
            temp += pow((X[i][k] - X[j][k]), 2)
        
        temp = math.sqrt(temp)
        if temp == math.floor(temp):
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
n,d = map(int,input().split())
def dist(x,y):
  ans = 0
  for i in range(d):
    ans += abs(x[i]-y[i])**2
  ans **= 0.5
  return ans

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

Submission status: Accepted

Solution code:
import numpy

n,d = map(int, input().split())
x = [[int(i) for i in input().split()] for i in range(n)] 
# n=3
# d=2
# x=[[1, 2], [5, 5], [-2, 8]]


cnt=0
for i in range(n):
    for j in range(n-i-1):
#         print(i,j+i+1)
        a = numpy.array(x[i])
        b = numpy.array(x[i+j+1])
        u = b - a
        if numpy.linalg.norm(u).is_integer():
            cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
n , D =map(int,input().split())
import math
 
a = [input().split() for l in range(n)]
count = 0
 
for i in range(n):
  for j in range(n):
    if i == j:
      count += 0
    else:
      x = []
      for c in range(D):
        x.append((int(a[i][c]) - int(a[j][c])) ** 2)
      d = math.sqrt(sum(x))
      d = float(d)
      if d.is_integer():
        count += 1
print(int(count/2))

Submission status: Accepted

Solution code:
import math


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


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

li = []
count = 0

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

for i in range(N - 1):
    for j in range(i + 1, N):
        target = 0
        if D != 1:
            for k in range(D):
                target += (li[i][k] - li[j][k]) ** 2
            if is_integer_num(math.sqrt(target)):
                count += 1
        else:
            target += (li[i][0] - li[j][0]) ** 2
            if is_integer_num(math.sqrt(target)):
                count += 1


print(count)

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
X = []
for _ in range(N):
    X.append([int(x) for x in input().split()])
ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        s = sum((X[i][d] - X[j][d])**2 for d in range(D))
        if any(i**2 == s for i in range(1000)):
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
from math import modf
N, D=map(int,input().split())
lis = []
for i in range(N):
   li = list(map(int,input().split()))	
   lis.append(li)
res = 0
ans = 0
for i in range (N):
   for j in range(i+1,N):
      for k in range(D):
         a = lis[i][k]-lis[j][k]
         res += a ** 2
      b = res ** 0.5
      decimal, integer = modf(b)
      if (decimal == 0):
         ans += 1
      res = 0
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    data = []
    n,d = map(int,input().split())
    for _ in range(n):
        x = list(map(int,input().split()))
        data.append(x)
    square =[]
    for i in range(1,200):
        square.append(i*i)
    ans=0
    for i in range(n):
        for j in range(i+1,n):
            k = [abs(l-m)**2 for l,m in zip(data[i],data[j]) ]
            s=sum(k)
            if s in square:
                ans = ans + 1

    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import math

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

tmp = []

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

cnt = 0

for i in range(len(tmp)):
    for j in range(len(tmp))[i+1:]:
        y = 0
        for k in range(D):
            y += abs(tmp[i][k] - tmp[j][k]) ** 2


        if math.sqrt(y).is_integer():
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math
n, d = list(map(int, input().split()))
a = [[0]*d]*n
ans = []
temp = 0
count = 0
for i in range(n):
    a[i] = list(map(int, input().split()))

for i in range(n):
    for j in range(i+1, n):
        for k in range(d):
            temp += (a[i][k]-a[j][k])*(a[i][k]-a[j][k])
        ans.append(math.sqrt(temp))
        temp = 0
for i in range(len(ans)):
    if ans[i]%1 == 0:
        count+=1
print(count)

Submission status: Accepted

Solution code:
import math
import itertools
n,d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
listA = list(itertools.combinations(x, 2))
a = 0
b = 0
for j in range(len(listA)):
    for k in range(d):
        a = a+(listA[j][0][k]-listA[j][1][k])**2
    if a**(0.5)==int(a**(0.5)):
        b = b+1
    a = 0
print(b)

Submission status: Accepted

Solution code:
from sys import stdin
import math

n, d = map(int, input().split())
data = [stdin.readline().rstrip().split() for _ in range(n)]


count = 0
fig = 0

for i in range(n):

        for j in range(n):

                if i == j:
                        pass
                elif i > j:
                        pass
                else:
                        fig = 0
                        res = 0

                        for h in range(d):
                                fig += abs(int(data[i][h]) - int(data[j][h])) **2
                        res = math.sqrt(fig)
                        #print(res)
                        if res%1 == 0:
                                count +=1



print(count)
#print(data)

Submission status: Accepted

Solution code:
import math
import itertools

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

coordinate = []
for i in range(N):
  coordinate.append(list(map(int, input().split())))
  
cnt = 0
c_list = list(itertools.combinations(coordinate, 2))

for i in range(len(c_list)):
  combined = [(x - y)**2 for (x, y) in zip(c_list[i][0], c_list[i][1])]
  combined = math.sqrt(sum(combined))
  if combined.is_integer():
    cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math

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

a = [i**2 for i in range(300)]
n = 1
t = 0
for i in range(N):
    k = i + n
    for j in range(k, N):
        count = 0
        for l in range(D):
            count += (x[i][l] - x[j][l]) ** 2
        n += 1
        if count in a:
            t += 1
    n = 1

print(t)