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


## 座標を取り出す
list_mapping = []
for n in range(N):
  mapping = list(map(int,input().split(' ')))
  list_mapping.append(mapping)

  
## 距離を計算
cnt = 0

for m in list_mapping:
  ## 他の全ての座標と計算
  for n in range(N):
    _ = list_mapping[n]
    if m != _:
      dis_2 = [(x - y) ** 2 for (x, y) in zip(m, _)]
      dis = sum(dis_2) ** (1/2)
    else:
      continue
    
    if dis.is_integer():
      cnt += 1
      
print(int(cnt / 2))

Submission status: Accepted

Solution code:
import numpy as np

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

cnt = 0
for n in range(N - 1):
    for n2 in range(n + 1, N):
        if (((X[n] - X[n2]) ** 2).sum() ** 0.5).is_integer():
            cnt += 1

print (cnt)

Submission status: Accepted

Solution code:

import math
import itertools

#math.sqrt(4).is_integer()

#整数になるものの数
ans = 0

cal = []

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

#N行D列の配列
G = []
for i in range(N):
    li = list(map(int,input().split()))
    G.append(li)

#点の数
counter = [i for i in range(N)]
#２点の組み合わせの列挙
comb = itertools.combinations(counter, 2)
#列挙したものをリストにする
li_comb = []
for i in comb:
    li_comb.append(i)


for i in range(len(li_comb)):
    for j in range(D):
        cal.append(pow(G[li_comb[i][0]][j]-G[li_comb[i][1]][j],2))
    if math.sqrt(sum(cal)).is_integer() :
        ans += 1
    cal = []

print(ans)

Submission status: Accepted

Solution code:
n, D = map(int, input().split())
points = [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):
        pre_distance = 0
        for d in range(D):
            pre_distance += (points[i][d] - points[j][d])**2

        distance = pre_distance ** 0.5
        if distance.is_integer():
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
def f(a, b):
  res = 0
  for x, y in zip(a, b):
    res += (x - y) ** 2
  res **= 0.5
  return res.is_integer()
  
N, D = [int(x) for x in input().split()]
XND = ['' for _ in range(N)]
for n in range(N):
  XND[n] = [int(x) for x in input().split()]

res = 0
for a in range(N - 1):
  for b in range(a + 1, N):
    if f(XND[a], XND[b]):
      res += 1
print(res)

Submission status: Accepted

Solution code:
import numpy as np
import itertools

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

count = 0

c = list(itertools.combinations(x,2))
c = np.array(c)
for i in c:
  k = np.linalg.norm(i[0]-i[1])
  #print(i)
  if k.is_integer():
    count +=1

print(count)

Submission status: Accepted

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

x = np.array(input().split(" ") , dtype="int32")
ans = 0
for i in range(N-1):
    x = np.append(x, np.array(input().split(" ") , dtype="int32"))
x = x.reshape(N , D)
for i in range(N):
    for n in range(i+1 , N):
        dist = np.linalg.norm(x[i] - x[n])
        if math.ceil(dist)==math.floor(dist):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import math
inp = [int(v) for v in input().split(' ')]
N = inp[0]
D = inp[1]
data = []
for i in range(N):
    data.append(np.array([float(v) for v in input().split(' ')]))

cnt = 0
for n1 in range(N):
    for n2 in range(n1 + 1, N):
        l = math.sqrt(np.sum((data[n1] - data[n2]) ** 2)) 
        if int(l) == l:
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
x = [[int(i) for i in input().split()] for _ in range(n)]
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        check = 0
        for k in range(d):
            check += (x[i][k]-x[j][k])**2
        if check**.5 == int(check**.5):
            ans +=1
print(ans)

Submission status: Accepted

Solution code:
tmp=input().split()
n=int(tmp[0])
d=int(tmp[1])
xn = [0]*n
num = 0

for i in range(n):
  xn[i] = input().split()
    
for i in range(n):
  for j in range(i+1, n):
    dist = 0
    for k in range(d):
      dist = dist + pow(int(xn[i][k])-int(xn[j][k]), 2)
#    print("test",dist)
#    print(int(pow(int(pow(dist,0.5)), 2)))
    if dist == int(pow(int(pow(dist,0.5)), 2)):
      num += 1
print(num)

Submission status: Accepted

Solution code:
import numpy as np

N, D = map(int,input().rstrip().split())
li = [[int(_) for _ in input().rstrip().split()] for __ in range(N)]

count = 0
for i in range(N-1):
    for j in range(i+1, N):
        if np.linalg.norm(np.array(li[i])-np.array(li[j])).is_integer():
            count += 1

print(count)

Submission status: Accepted

Solution code:
import math

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

count = 0
Xs = []
for i in range(n):
  x = [int(x) for x in input().split()]
  
  if i >= 1:
    for x_ in Xs:
      distance = 0
      for j in range(d):
        distance += (x[j] - x_[j]) ** 2
      distance = math.sqrt(distance)
      if distance == int(distance):
        count += 1
  Xs.append(x)
  
print(count)

Submission status: Accepted

Solution code:
import math

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

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

print(c)

Submission status: Accepted

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

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

for i in range(n - 1):
    for j in range(i + 1, n):
        distance = 0
        for k in range(d):
            distance += (x[i][k] - x[j][k]) ** 2
        if (distance ** 0.5).is_integer():
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math

N,D = map(int, raw_input().split())
array = []
num = 0

for i in range(N):
    array.append( map(int, raw_input().split()))

#print N,D,array
for i in range(N):
    for j in range(N):
        if i >= j :
            continue
        else:
            dist = 0
            for d in range(D):
                dist +=  (array[i][d] - array[j][d])*(array[i][d] - array[j][d])
#            print array[i], array[j], math.sqrt(dist)
            if (math.sqrt(dist) % 1) == 0:
                num += 1

print num

Submission status: Accepted

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

ans=0
for i in range(n):
    for j in range(i+1,n):
        val=np.sqrt(np.power(p[i]-p[j], 2).sum())
        if float.is_integer(val):
            ans+=1

print(ans)

Submission status: Accepted

Solution code:
def is_good_num(x):
    i = 1
    while i ** 2 <= x:
        if i ** 2 == x:
            return True
        i += 1
    return False

def main():
    n, d = map(int, input().split())
    x = [[int(x) for x in input().split()] for i in range(n)]
    ans = 0
    for i in range(n):
        for j in range(i + 1, n):
            s = 0
            for k in range(d):
                s += (x[i][k] - x[j][k]) ** 2   
            if is_good_num(s):
                ans += 1
    print(ans)
    
main()

Submission status: Accepted

Solution code:
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):
    for j in range(N):
        if i < j:
            dist=0
            for k in range(D):
                dist += (X[i][k] - X[j][k])**2
            dist = dist ** 0.5
            if round(dist,0) == dist:
                ans += 1
           
print(ans)

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

Submission status: Accepted

Solution code:
import math

n,d = [int(i) for i in input().split()]
main = []
for i in range(n):
  array = [int(i) for i in input().split()]
  main.append(array)
  
cnt = 0

for i in range(n):
  for j in range(i+1,n):
    kyori2 = 0
    for k in range(d):
      kyori2 += (main[i][k]-main[j][k])*(main[i][k]-main[j][k])
      
    kyori = math.sqrt(kyori2)
    if int(kyori)+0.000001 > kyori:
      cnt += 1
      
print(cnt)

Submission status: Accepted

Solution code:
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

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

N,D = II()

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math


def solve(N: int, D: int, X: "List[List[int]]"):
    count = 0
    for i in range(N):
        for j in range(i + 1,N):
            sum = 0
            for k in range(D):
                sum += (X[i][k] - X[j][k]) ** 2
            f = float(math.sqrt(sum))
            if f.is_integer():
                count += 1
    print(count)
    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:
import numpy as np
import math
n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]

narr = np.array(x)
ans = 0

for i in range(n):
    for j in range(i+1, n):
        dis = np.linalg.norm(narr[j] - narr[i])
        if math.ceil(dis) == math.floor(dis):
            ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
X =[]
for i in range(N):
  X.append(list(map(int, input().split())))
ans=0
dist=0
for i in range(N):
  for j in range(N):
    if i < j:
      for k in range(D):
        dist += abs(X[i][k] - X[j][k])**2
      dist = dist**(1/2)
      if round(dist,0) == dist:
        ans += 1
      dist = 0
print(ans)

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
x = [list(map(int, input().split())) for number in range(n)]
ans = 0
for a in range(n):
    for b in range(n):
        if a < b:
            distance_element =  [(ai - bi) ** 2 for ai, bi in zip(x[a], x[b])]
            distance = sum(distance_element) ** (1/2)
            if distance - int(distance) == 0:
                ans += 1
            else:
                pass
        else:
            pass
print(ans)

Submission status: Accepted

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

squares=[i**2 for i in range(200)]
ans=0
for i in range(n):
    for j in range(i+1,n):
#        print(i,j)
        dist = sum((x[i][m]-x[j][m])**2 for m in range(d)) 
        if dist in squares: ans+=1
#        print(dist)
print(ans)

Submission status: Accepted

Solution code:
import math

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

flag=0
ANS=0

for i in range(0,N):
    for j in range(i+1,N):
        for k in range(0,D):
            ANS+=(int(x[i][k])-int(x[j][k]))*(int(x[i][k])-int(x[j][k]))
        if math.sqrt(ANS)==int(math.sqrt(ANS)):
            flag+=1
        ANS=0
        
print(flag)

Submission status: Accepted

Solution code:
from sys import stdin
import math

n, d = map(int,input().split())
cnt = 0
x =  [stdin.readline().rstrip().split() for _ in range(n)]
ans = 0
for i in range(n):
	for k in range(i+1,n):
		for j in range(d):
			ans += (int(x[i][j]) - int(x[k][j]))**2

		ans1 = math.sqrt(ans)
		#print(ans)
		if ans1.is_integer() == True: 
			cnt += 1
		ans = 0
print(cnt)

Submission status: Accepted

Solution code:

import math

def calc(before, cur):
    sum = 0
    for x, y in zip(before, cur):
        sum += (x-y) ** 2

    return (1 if math.sqrt(sum) % 1 == 0 else 0)

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

count = 0
for i in range(n-1):
    for j in range(i+1, n):
        count += calc(Xs[i], Xs[j])

print(count)

Submission status: Accepted

Solution code:

import math

def calc(before, cur):
    sum = 0
    for i in range(len(before)):
        sum += ((before[i] - cur[i])**2)

    return (1 if math.sqrt(sum) % 1 == 0 else 0)

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

count = 0
for i in range(n-1):
    for j in range(i+1, n):
        count += calc(Xs[i], Xs[j])

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

counter = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        e = 0
        for xi, xj in zip(X[i], X[j]):
            e += (xj - xi)**2
        e = e**0.5
        counter += 1 if float.is_integer(e) else 0

print(counter)

Submission status: Accepted

Solution code:
import math

# inputList=[]
# for i in range(6):
#     inputNum = input()
#     inputList.append(inputNum)
inputa = input().split()
# inputb = input().split()

a = int(inputa[0])
b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

inputList=[]
for i in range(a):
    inputNum = input().split()
    inputList.append(inputNum)



cnt = 0
for i in range(a):
    for j in range(i+1, a):
        dstnc = 0
        for k in range(b):
            tmpi = inputList[i][k]
            tmpj = inputList[j][k]

            dstnc += math.pow(int(tmpi) - int(tmpj), 2)

        if math.sqrt(dstnc) % 1.0 == 0 :
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math
n,d=map(int,input().split())
arr=[]
for _ in range(n):
	arr.append(list(map(int,input().split())))
def dist2(p,q):
  ans=0
  for i,j in zip(p,q):
    ans+=(i-j)**2
  return ans

ans=0
for i in range(n-1):
  for j in range(i+1,n): 
    d2=dist2(arr[i],arr[j])
    d=int(math.sqrt(d2)+1e-15)
    if d*d==d2: ans+=1
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

cnt = 0
for i, x in enumerate(arr[:-1]):
  for y in arr[i+1:]:
    sum_=sum([(x[k]-y[k])**2 for k in range(d)])**0.5
    if float(sum_).is_integer():
      cnt += 1
print(cnt)

Submission status: Accepted

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

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

import math

ans=[]
for a in range(n):
  for b in range(n):
    x=0
    for c in range(d):
      D=(l[a][c]-l[b][c])**2
      x+=D
    y=math.sqrt(x)
    ans.append(y.is_integer())
      
ans=(ans.count(True)-n)//2
print(ans)

Submission status: Accepted

Solution code:
import math
#numpy使った方がよかったか
N,D=input().split()
N,D=int(N),int(D)
X=[]

for i in range(N):
    X1=input().split()
    #print(X[i])
    X2=[]
    for j in range(D):
        X2.append(int(X1[j]))
    X.append(X2)
    
c=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
        if abs(math.sqrt(d)-int(math.sqrt(d))) <0.0001:
            c+=1

print(c)

Submission status: Accepted

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

ans = 0
for idx1,el1 in enumerate(x):
    for idx2, el2 in enumerate(x):
        dis = 0
        if idx1 < idx2:
            for i in range(d):
                dis += (el1[i] - el2[i])**2
            if math.sqrt(dis).is_integer():
                ans += 1
print(ans)

Submission status: Accepted

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

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

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

# output
print(ans)

Submission status: Accepted

Solution code:
import math
num,digit=map(int,input().split())
dot=[list(map(int,input().split())) for _ in range(num)]
count=0
for i in range(num):
    for j in range(i+1,num):
        distance=0
        for a,b in zip(dot[i],dot[j]):
            distance+=(a-b)**2
        if distance==math.floor(math.sqrt(distance))**2:
            count+=1
print(count)

Submission status: Accepted

Solution code:
import math
N,D = map(int,input().split())
s = []
cnt = 0
for i in range(N):
    s.append(list(map(int,input().split())))
for i in range(N-1):
    for j in range(i+1,N):
        sub = 0
        dis = 0
        for k in range(D):
            sub += math.pow(abs(s[i][k] -s[j][k]),2)
            
        dis = math.sqrt(sub)
        if dis.is_integer():
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
x = []
cnt = 0
sum = 0
for _ in range(n):
    tmp = list(map(int, input().split()))
    x.append(tmp)

for i in range(n):
    for j in range(i + 1, n):
        sum = 0
        for k in range(d):
            sum += (x[i][k] - x[j][k]) ** 2
        distance = sum ** 0.5
        if distance.is_integer():
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math

n, d = map(int, input().split())
x = []
cnt = 0
sum = 0
for _ in range(n):
    tmp = list(map(int, input().split()))
    x.append(tmp)

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

print(cnt)

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
x = []
cnt = 0
sum = 0
for _ in range(n):
    tmp = list(map(int, input().split()))
    x.append(tmp)

for i in range(n):
    for j in range(i + 1, n):
        sum = 0
        l = 1
        for k in range(d):
            sum += (x[i][k] - x[j][k]) ** 2
        while (l ** 2 <= sum):
            if l ** 2 == sum:
                cnt += 1
            l += 1

print(cnt)

Submission status: Accepted

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

x = []
for i in range(n):
    x.append(list(map(int,input().split())))
    
mc=(list(itertools.combinations(range(n), 2)))

count = 0 
for i in mc:
    ans2=0
    for j in range(d):
        ans2+= abs(x[i[1]][j] - x[i[0]][j])**2
    ans = math.sqrt(ans2)
    if ans.is_integer():
        count+=1

print(count)

Submission status: Accepted

Solution code:
from math import sqrt
def dist(l1,l2):
  return sqrt(sum([abs((n1-n2)**2) for n1,n2 in zip(l1,l2)]))
n,d = map(int,input().split())
ll = [list(map(int,input().split())) for _ in [0]*n]
ans = 0
for i in range(n):
  for j in range(i+1,n):
    if dist(ll[i],ll[j]) == int(dist(ll[i],ll[j])):
      ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, D = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(N)]
c = 0
for i in range(N - 1):
  for j in range(i+1, N):
    c += (sum((a-b)**2 for a,b in zip(x[i], x[j])) ** 0.5).is_integer()
print(c)

Submission status: Accepted

Solution code:
import math

def calc_dist(point1, point2):
  total = 0
  for x1, x2 in zip(point1, point2):
    total += (x1-x2)*(x1-x2)
  return math.sqrt(total)

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

ans = 0
for i  in range(0,N-1):
  for j in range(i+1,N):
    dist = calc_dist(points[i], points[j])
    if float(int(dist)) == dist:
      ans += 1    
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np


def isint(x):
    return np.equal(np.mod(x, 1), 0)


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

    vecs = np.array(vecs)
    # print(vecs)
    v1 = np.tile(vecs, (1, n))
    v2 = np.tile(vecs.reshape(1, n * d), (n, 1))
    # print(v1)
    # print(v2)
    dists = v1 - v2
    # print(dists)
    dists = dists.reshape([-1, d])
    # print(dists)
    dists = np.linalg.norm(dists, axis=1)
    # print(dists)
    score = (np.count_nonzero(isint(dists)) - n) // 2
    print(score)


main()

Submission status: Accepted

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

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

Submission status: Accepted

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

def func(n, d, x):
    count = 0
    terms = 0.0
    index = [i for i in range(n)]
    for i, k in itertools.combinations(index, 2):
        for j in range(d):        
            j_term = abs(x[i][j]-x[k][j])
            j_term **= 2      
            terms += j_term
        terms **= 0.5
        if terms.is_integer():
            count += 1
        terms = 0.0
    print(count)
    pass


def main():
    n,d = [int(i) for i in input().split()] 
    x = [[0]*d for i in range(n)]
    #x = []
    for i in range(n):
        xd = [int(j) for j in input().split()] 
        x[i] = xd
    #for _ in range(n):
    #    xd = [int(i) for i in input().split()] 
    #    x.
    func(n, d, x)
    
# main関数呼び出し
if __name__ == "__main__":
    main()

Submission status: Accepted

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

for i in range(N):
    for j in range(i+1,N):
        tmp=0
        for k in range(D):
            tmp+=(dot[i][k]-dot[j][k])**2
        tmp=math.sqrt(tmp)
        if(float.is_integer(tmp)==True):sum+=1

print(sum)

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        s = pow(sum([(X[i][k] - X[j][k])**2 for k in range(d)]), 1/2)
        if s.is_integer():
            ans +=1
print(ans)

Submission status: Accepted

Solution code:
import math

def distance(l1,l2):
    d2 = 0
    for i in range(len(l1)):
        l = l1[i] - l2[i]
        d2 += l ** 2
    return d2

def issqrt(num):
    cand = int(math.sqrt(num))
    if (cand + 1) ** 2 == num:
        return True
    if cand ** 2 == num:
        return True
    if (cand - 1) ** 2 == num:
        return True
    return False


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

count = 0
for i in range( N - 1):
    for j in range( i+1, N):
        d = distance( cord[i],cord[j])
        #print( "({} {}) => {} {}".format(i,j,d,math.sqrt(d)))
        if issqrt( d ):
            count += 1

print( count )

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

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

count = 0

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

print(count)

Submission status: Accepted

Solution code:
import math

cnt = 0

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

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

Submission status: Accepted

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

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

def dist(al,bl,d):
  total=0
  for i in range(d) :
    total += (al[i]-bl[i])**2
    
  return math.sqrt(total)

#print(dist([5,5],[1,2],2))
count=0
for i in range(n):
  for j in range(n):
    if i<= j :
      continue
    di=dist(li[i],li[j],d)
    if di.is_integer() :
      count+=1
print(count)

Submission status: Accepted

Solution code:
from math import sqrt

def dist(x1, x2):
    l = 0
    for i in range(len(x1)):
        l += (x1[i]- x2[i])**2
    return sqrt(l)

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):
        d = dist(X[i], X[j])
        if int(d) == d:
            ans += 1
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)

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

print(cnt)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

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

Submission status: Accepted

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

r = []
for i in range(N-1): # 点を動かす
    for j in range(i+1, N): # もう片方の点を動かす
        r0 = 0
        for k in range(D): # 座標の成分を動かす
            r0 += (X[i][k] - X[j][k]) ** 2
        r1 = r0 **0.5
        r.append(r1)
count = 0
for i in range(len(r)):
    if r[i].is_integer():
        count += 1
    else:
        pass
print(count)

Submission status: Accepted

Solution code:
import numpy as np

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

X = np.array(X)
ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        dis = np.linalg.norm(X[i] - X[j])
        if int(dis)==dis:
            ans += 1
print(ans)