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())
x = []
for _ in range(n):
  xi = list(map(int,input().split()))
  x.append(xi)
def dis(a,b,d):
  s = 0
  for i in range(d):
    s += (a[i] - b[i])**2
  return s
count = 0
for i in range(n-1):
  for j in range(i+1,n):
    e = dis(x[i],x[j],d)
    ed = e**(1/2)
    if (ed - int(ed)) == 0:
      count += 1
print(count)

Submission status: Accepted

Solution code:
import numpy
import itertools

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

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

for xs in itertools.combinations(x,2):
    dist = numpy.linalg.norm(xs[1] - xs[0])

    if dist % 1 == 0 :
        count += 1

print(count)

Submission status: Accepted

Solution code:
#coding:utf-8
from scipy.spatial.distance import pdist
N, D = map(int,input().split())
P = []
for i in range(N):
    P.append(list(map(int,input().split())))
DI = pdist(P)
sm = 0
for d in DI:
    sm += d.is_integer()
print (sm)

Submission status: Accepted

Solution code:
import math

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

array = [[0 for i in range(10)] for j in range(10)]

for i in range(N):
    x = list(map(int, input().split()))
    for j in range(0, D):
        array[i][j] = x[j];
sum_dis = 0
for i in range(0,N-1):
    for j in range(i+1,N):
        dis = 0
        for k in range(D):
            dis += (array[i][k] - array[j][k])**2
        dis = math.sqrt(dis)
        if(dis.is_integer()): sum_dis += 1
print(sum_dis)

Submission status: Accepted

Solution code:
import numpy as np
ND =  list(map(int,input().split()))
Lis = []
for i in range(ND[0]):
    a =list(map(int,input().split()))
    Lis.append(a)
Lisnp = np.array(Lis)
Count = 0
for k in range(ND[0]):
    for g in range(k):
        u = Lisnp[k] - Lisnp[g]
        norm = np.linalg.norm(u)
        if norm.is_integer():
            Count += 1
print(Count)

Submission status: Accepted

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

if D == 1:
  print(N * (N-1) // 2)
else:
  A = [0] * N
  count = 0
  sei = 0

  for i in range(0,N):
	  A[i] = list(map(int, input().split()))
    
  for p in range(0,N):
      for q in range(0,N):
          sum = 0
    
          for r in range(0,D):
              sum = sum + (A[p][r]-A[q][r]) ** 2
           
          sum = sum ** 0.5 
          sei = int(sum)
        
          if sum != 0 and sum == sei:
              count = count + 1
      
  print(count // 2)

Submission status: Accepted

Solution code:
import sys
import math
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
    
N,D=LI()
MAT=[LI() for i in range(N)]


cnt = 0
for i in range(N):
    for j in range(i+1, N):
        dist = 0
        for k in range(D):
            dist += (MAT[i][k]-MAT[j][k])*(MAT[i][k]-MAT[j][k])
        distrt = math.ceil(math.sqrt(dist))
        if distrt*distrt == dist:
            cnt += 1
print(cnt)

Submission status: Accepted

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

nums=[]

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

#print(nums)

ans=[]

for j in range(n-1):
    for k in range(j+1,n):
        x=abs(np.array(nums[j])-np.array(nums[k]))
        #print(x)
        y=x**2
        #print(y)
        z=np.sqrt(sum(y))
        #print(z)
        ans.append(z)
cnt=0
#print(ans)
for a in ans:
    if a.is_integer():
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import math
N,M = map(int, input().split())
a = []
for i in range(N):
  a.append(input().split())

cnt=0
for i in range(N):
  for j in range(N-i-1):
    s=0
    for k in range(M):
      s += pow((int(a[i][k])-int(a[i+j+1][k])),2)
    c=1
    
    while(True):
      if pow(c,2) == s:
        cnt += 1
        break
      elif pow(c,2) > s:
        break
      c+=1
  
  
print(cnt)

Submission status: Accepted

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

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


count = 0
for i in range(N):
    k = i+1
    while k < N:
        dis = 0
        for j in range(D):
#            print("i,j,k,X[i][j],X[k][j]=",i,j,k,X[i][j],X[k][j])
            test = X[i][j] - X[k][j]
            dis = dis + test*test
#        print("dis,k=",dis,k)
        sqdis = math.sqrt(dis)  
        jud = sqdis.is_integer()
#        print(jud)
        if jud == 1:
#            print(jud)
            count = count + 1
        k = k + 1
print(count)

Submission status: Accepted

Solution code:
import math

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

counter = 0
for n1 in range(N):
    for n2 in range(n1 + 1, N, 1):
        sum = 0
        for d in range(D):
            sum += (X[n1][d] - X[n2][d]) * (X[n1][d] - X[n2][d])
        sum = math.sqrt(sum)
        if sum == int(sum):
            counter += 1
print(counter)

Submission status: Accepted

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

cnt = 0
R = []
for i in range(N):
    for j in range(i+1,N):
        r = 0
        for d in range(D):
            r += (X[i][d] - X[j][d]) ** 2
        for n in range(1,300):
            if r == n ** 2:
                cnt += 1
        R.append(r)

print(cnt)

Submission status: Accepted

Solution code:
def inpl(): return map(int, input().split())
from itertools import accumulate
from bisect import bisect, bisect_left
from collections import Counter
from functools import reduce
from itertools import accumulate
from operator import itemgetter, xor

from sys import setrecursionlimit
setrecursionlimit(10**9)
 
import sys
input = sys.stdin.readline
from collections import Counter
import numpy as np
def inpl(): return list(map(int, input().split()))
N, D = inpl()
S = set([i**2 for i in range(1, 400)])
X = np.array([inpl() for _ in range(N)], dtype=np.int64)

ans = 0
for i in range(N):
    for x in np.power(X - X[i], 2).sum(axis=1):
        if x in S:
            ans += 1
print(ans//2)

Submission status: Accepted

Solution code:
import itertools
import numpy as np
H, W = map(int, input().split())
arr = []
for _ in range(H):
    S = input().split()
    S = [int(s) for s in S]
    arr.append(S)
x = list(itertools.combinations(arr,2))
count = 0
for i in range(len(x)):
    vec_a = np.array(x[i][0])
    vec_b = np.array(x[i][1])
    d = np.linalg.norm(vec_a - vec_b)
    d2 = int(d)
    if d == d2:
        count+=1
print(count)
print()

Submission status: Accepted

Solution code:
import math
N,D = list(map(int,input().split()))
X = []
for i in range(N):
    X.append(list(map(int,input().split())))
c = 0
for i in range(N):
    for j in range(i+1,N):
        sum_d = 0
        for d in range(D):
            sum_d += (X[i][d] - X[j][d])**2
        if math.sqrt(sum_d) == int(math.sqrt(sum_d)):
            c += 1
print(c)

Submission status: Accepted

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

List = []

for _ in range(n):
  r = list(map(int,input().split()))
  List.append(r)
  
Answers = []

for i in range(n):
  for j in range(n-i-1):
    Lsquare = 0
    for k in range(d):
      Lsquare += (List[i][k]-List[i+j+1][k])**2
    Answers.append(Lsquare**0.5)

Answer = []
for s in Answers:
  if s.is_integer()==True:
    Answer.append(s)

print(len(Answer))

Submission status: Accepted

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

A=[[int(a) for a in input().split()]for a in range(N)]

def int_test(a,n):
    if a.is_integer():
        n+=1

n=0


for i in range(0,N):

    if i != N:
        for j in range(i+1,N):
            sq=0.0
            for k in range(0,D):
                sq=sq+(A[i][k]-A[j][k])**2

            sq2=math.sqrt(sq)
            #print(i,j,k,sq2)
            if sq2.is_integer():
                n+=1

print(n)

Submission status: Accepted

Solution code:
#入力
n, d = map(int, input().split())
point = [[int(i) for i in input().split()] for j in range(n)]
#点1から計算する
m = 0
for i in range(n):
	for j in range(i+1,n):
		a = 0
		for k in range(d):
			a += (point[i][k]-point[j][k])**2
		b = a**(1/2)
		if b.is_integer():
			m += 1
print(m)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import itertools
import numpy as np

n,d = map(int, input().split())
x = np.asarray([list(map(int, input().split())) for i in range(n)])
c = 0
for v in itertools.combinations(x, 2):
  if np.linalg.norm(v[0] - v[1]).is_integer():
    c += 1
print(c)

Submission status: Accepted

Solution code:
def euclid(A, B):
    c2 = 0
    for a,b in zip(A,B):
        c2 += (a-b)**2
    return c2**0.5

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):
        c = euclid(X[i], X[j])
        if c.is_integer():
            cnt += 1
print(cnt)

Submission status: Accepted

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

for a in range(n):
    for b in range(a+1,n):
        for c in range(d):
            total+= (x[a][c]-x[b][c])**2
        result=math.sqrt(total)
        if(result.is_integer()):
            num+=1

        total=0
print(num)

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
import math
X = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    X.append(array)
var = 0
for i in range(N-1):
  for k in range(N-1-i):
    s = 0
    for j in range(D):      
      s = s + (X[i+1+k][j] - X[i][j])*(X[i+1+k][j] - X[i][j])
    if math.sqrt(s) - (int(math.sqrt(s))) ==0:
      var = var+1
print(var)

Submission status: Accepted

Solution code:
import math

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

count = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        r = 0
        for n in range(D):
            r += (xList[i][n] - xList[j][n]) ** 2
        if (math.sqrt(r) % 1 == 0):
            count += 1

print(count)

Submission status: Accepted

Solution code:
import math


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


count = 0

for j in range(ND[0]):

    for u in range(ND[0]):
        if j == u:
            continue
        else:
            SUM = 0

            for b in range(ND[1]):
                SUM += pow(X[j][b] - X[u][b],2)

            SQ = math.sqrt(SUM)

            if SQ.is_integer():
                count+=1
            else:
                continue

print(int(count/2))

Submission status: Accepted

Solution code:
#!python
import math
import itertools

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

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

for i in itertools.combinations(ipt, 2):
    dist_b = 0
    for j in range(d):
        dist_b += pow(abs(i[0][j] - i[1][j]), 2)
    
    if math.floor(math.sqrt(dist_b)) == math.ceil(math.sqrt(dist_b)):
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math

n,d=map(int,input().split())
x={}
for a in range(0,n):
    x[a]=list(map(int,input().split()))
cou=0
for i in range(0,n):
    for j in range(i+1,n):
        s=0
        for b in range(0,d):
            s=s+(x[i][b]-x[j][b])**2
        if math.sqrt(s).is_integer()==True:
           cou=cou+1
print(cou)

Submission status: Accepted

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

vc = []

def isqrt(n):
    x = n
    y = (x + 1) // 2
    while y < x:
        x = y
        y = (x + n // x) // 2
    return x

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

cc = 0
for k, i in enumerate(vc):
    if len(vc) < 2:
        break
    for v in vc[k+1:]:
        summ = 0
        for (x, y) in zip(i, v):
            summ += abs(x - y) ** 2


        if isqrt(summ) == math.sqrt(summ):
            cc += 1


print(cc)

Submission status: Accepted

Solution code:
import itertools
n,d = map(int,input().split())
li = [list(map(int,input().split())) for i in range(n)]
nnn = [i for i in range(n)]
cnt = 0
for i,j in itertools.combinations(nnn,2):
  dis = 0
  for di in range(d):
    dis += (li[i][di]-li[j][di])**2
  if int(dis**(1/2))**2 == dis:
    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import sys
from math import sqrt

def solve(N, D, X):
    def dist(ys, zs):
        sum = 0
        for d in range(D):
            sum += (ys[d] - zs[d])**2
        return sqrt(sum)
    count = 0
    for i in range(N):
        for j in range(i+1, N):
            d = dist(X[i], X[j])
            if d.is_integer():
                count += 1
    print(count)


def main():
    N, D = map(int, input().split())
    X = [ []]  * N
    for y in range(N):
        X[y] = list(map(int, input().split()))
    solve(N, D, X)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math

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

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

cnt = 0
for i in range(N-1):
  
  for j in range(i+1,N):
    tmp = 0
    for m in range(D):
      tmp = tmp + (A[i][m]-A[j][m])**2
    if (math.sqrt(tmp)).is_integer():
      cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math, itertools

def calc_dict(D, p_list):
    sqrt_in = 0
    for i in range(0, D):
        sqrt_in += abs( p_list[0][i] - p_list[1][i] )**2
    return math.sqrt( sqrt_in )

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

X_list = []
for i in range(0, N):
    X_list.append(list(X[i]))

points_list = list(itertools.combinations(X_list,2))

int_count = 0
for i in range(0, len(points_list)):
    dist = calc_dict(D, points_list[i])
    if( dist.is_integer() ):
        int_count += 1

print(int_count)

Submission status: Accepted

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

nums=[input().split()for i in range(N)]
sum=0
for i in range(N):
    for j in range(D):
        nums[i][j]=int(nums[i][j])
#print(nums)

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

cout=0

for i in range(N-1):
    for j in range(i+1,N):
           for k in range(D):
               sum+=(nums[i][k]-nums[j][k])*(nums[i][k]-nums[j][k])

           sum=math.sqrt(sum)
          

           if is_integer_num(sum)==True:
                cout+=1
                sum=0
           else:
                sum=0

print(cout)

Submission status: Accepted

Solution code:
from math import sqrt
N, D = map(int, input().split())
X = []
ans = 0
for _ in range(N):
    x = [int(s) for s in input().split()]
    X.append(x)
for i in range(N - 1):
    for j in range(i + 1, N):
        dist = 0
        for d in range(D):
            dist += (X[i][d] - X[j][d]) ** 2
        sqdist = round(sqrt(dist))
        if sqdist ** 2 == dist:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math

def norm(x, y):
    result = 0
    for i in range(len(x)):
        result += (x[i] - y[i]) * (x[i] - y[i])
    result = math.sqrt(result)
    return result

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

result = 0
for i in range(0, n-1):
    for j in range(i+1, n):
        if norm(x[i], x[j]).is_integer():
            result += 1

print(result)

Submission status: Accepted

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

points=[]

counts=0

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


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

print(counts)

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

count = 0
while X:
  Xt = X.pop()
  for Xi in X:
    if np.linalg.norm(Xt-Xi).is_integer():
      count += 1
    
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 v in itertools.combinations(X, 2):
  f = 0
  for w in range(D):
    f += (v[0][w]-v[1][w])**2
  f = f ** 0.5  
  if f.is_integer():
    cnt += 1
    
print(cnt)

Submission status: Accepted

Solution code:
import math
import itertools
N,D = map(int, input().split())
X = []
count = 0
for i in range(N):
    a1 = list(map(int, input().split()))
    X.append(a1)
p3 = 0   
a2 = list(itertools.combinations(range(N),2))

for i,e in a2:
    for j in range(D):
        p = X[i][j]
        p1 = X[e][j]
        p3 += pow(p-p1,2)
    p4 = math.sqrt(p3)
    if p4.is_integer():
        count += 1
    p3 = 0
print(count)

Submission status: Accepted

Solution code:
import math

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

def check(a,b):
    distance = 0
    for x,y in zip(a,b):
        distance += (x - y) ** 2
    return math.floor(math.sqrt(distance)) == math.sqrt(distance)

ans = 0

for i in range(N):
    for j in range(i+1,N):
        ans += check(ab[i],ab[j])

print(ans)

Submission status: Accepted

Solution code:
N, D = (int(item) for item in input().split())

import numpy as np

def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()
      
grid = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    grid.append(array)

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

Submission status: Accepted

Solution code:
import numpy as np

points, dimention = map(int, input().split())
count = 0

coordinate = []
for i in range(points):
  coordinate.append(input())

for s in range(points-1):
  point1 = np.array([int(i) for i in coordinate[s].split()])
  for t in range(s+1, points):
    point2 = np.array([int(i) for i in coordinate[t].split()])
    distance = np.sqrt(np.sum((point1 - point2) * (point1 - point2)))
    if distance.is_integer():
      count += 1
print(count)

Submission status: Accepted

Solution code:
import math
import itertools


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


for n in range(N):
    l = input().split()
    X[n] = [0]*D
    for d in range(D):
        X[n][d] = int(l[d])


count = 0
for y, z in itertools.combinations(X, 2):
    d = math.sqrt(sum(pow(y[i] - z[i], 2) for i in range(D)))
    if d.is_integer():
        count += 1

print(count)

Submission status: Accepted

Solution code:
import numpy as np

n,d=list(map(int, input().split()))
lst=[]
for i in range(n):
    lst.append(list(map(int, input().split())))
answer=0
for i in range(n):
    for j in range(n):
        if i==j:
            continue
        if i>=j:
            continue
        a=np.array(lst[i])
        b=np.array(lst[j])
        c=a-b
        d=np.linalg.norm(c)
        if d.is_integer():
            answer+=1
print(answer)

Submission status: Accepted

Solution code:
import math

# li[0]N,li[1]D
a = input().split()
li = [int(i) for i in a]

#行列
b = [input().split() for i in range(li[0])]
lis = [[int(j) for j in i] for i in b]


an = [[(lis[i][j]-lis[k][j])**2 for j in range(li[1])] for i in range(0,len(lis)-1) for k in range(i+1,len(lis))]
ann = [math.sqrt(sum(i)) for i in an] 
ans = [i for i in ann if (i.is_integer())]
print(len(ans))

Submission status: Accepted

Solution code:
import math
import itertools

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

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

for i in itertools.combinations(X_list,2):
	distance = 0
	for j in range(len(i[0])):
		distance += abs(i[0][j]-i[1][j])**2
	if math.sqrt(distance) % 1 == 0:
		count += 1 
print(count)

Submission status: Accepted

Solution code:
import numpy as np
N,D = map(int,input().rstrip().split(' '))
X = []
for i in range(N):
    X.append(list(map(int,input().rstrip().split(' '))))
r = []
for i in range(N):
    for j in range(i+1,N):
        ran = 0
        for l in range(D):
            ran += abs(X[i][l] - X[j][l]) **2
        r.append(ran)
r = [i for i in np.sqrt(r) if i % 1 == 0]
print(len(r))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
def main():
    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 k in range(N-1-i):
            K = 0
            KK = 0
            for j in range(D):
                K += ((X[i][j])-(X[N-1-k][j]))**2
            KK = K**0.5
            if isinstance(KK,int) or KK.is_integer():
                count += 1
    print(count)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

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

cnt = 0
for i in range(n - 1):
  for j in range(i+1, n):
    hoge = 0
    for num in range(d):
      hoge = hoge + pow(abs(x[i][num] - x[j][num]),2)
    if(hoge == pow(int(math.sqrt(hoge)), 2)):
       cnt = cnt + 1
print(cnt)

Submission status: Accepted

Solution code:
import math #math.sqrt(x)

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 q in range(n):
        sumv = 0
        if i == q:
            continue
        for j in range(d):
            sumv += (x[i][j] - x[q][j]) ** 2

        if math.sqrt(sumv).is_integer() == True:
            ans += 1

print(round(ans/2))

Submission status: Accepted

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

A = [[0 for x in range(D)]for y in range(N)]
for i in range(N):
  A[i] = [int(x) for x in sys.stdin.readline().split()]

B=[]
x=-126
while x**2 <= 16000:
  B.append(x**2)
  x+=1
count = 0
for i in range(N-1):
  for j in range(i+1,N):
    y = 0
    for k in range(D):
      y += (A[j][k]-A[i][k])**2

    if y in B:
      count+=1
print(count)

Submission status: Accepted

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

Y = []
i=0
n=0
for j in X[i:]:
    for k in X[i+1:]:
        m=0
        for l in range(D):
            m=m+(j[l]-k[l])**2
        o=math.sqrt(m)
        if o.is_integer()==True:
            n+=1

    i+=1

print(n)

Submission status: Accepted

Solution code:
import math
N,D=map(int,input().split())
X=[]
cnt=0
def distance(x,y):
    d2=[]
    for k in range(D):
        d2.append((X[x][k]-X[y][k])**2)
    return math.sqrt(sum(d2))
for i in range(N):
    X.append(list(map(int,input().split())))
for j in range(N-1):
        for l in range(j+1,N,):
            if float.is_integer(distance(j,l)):
                cnt+=1 
print(cnt)

Submission status: Accepted

Solution code:
from math import sqrt

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

def issqrt(k):
  a = int(sqrt(k))
  if (k == a**2) or (k == (a+1)**2):
    return True
  else:
    return False
  
def distance(p1, p2):
  h = 0
  for i in range(d):
    h += (p1[i] - p2[i])**2
  return h
  
def solve():
  ans = 0
  for i in range(n):
    for j in range(i+1, n):
      dis = distance(points[i], points[j])
      ans += issqrt(dis)
  return ans

print(solve())

Submission status: Accepted

Solution code:
import math

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

    count = 0
    for i in range(n):
        if i == n: break
        for j in range(i+1, n):
            #Xi, Xj = np.array(X[i]), np.array(X[j])
            #diff = Xj - Xi
            #dist = np.linalg.norm(diff)

            dis = get_distance(X[i], X[j], d)
            if dis.is_integer(): count += 1
            #print('distance:', dis)
    print(count)

def get_distance(P1, P2, d):
    s = 0
    for i in range(d):
        s += (P2[i] - P1[i])**2
    return math.sqrt(s)

main()

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)]
square=[i**2 for i in range(127)]
# print(square)
x=np.array(x)
# print(x)
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        # print(x[i],x[j],np.sum((x[i]-x[j])**2))
        if np.sum((x[i]-x[j])**2) in square:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
import math

n,d = map(int,input().split())
x=[]
for i in range(n):
    x.append(list(map(int,input().split())))
    
ans = 0
for i in range(n):
    for m in range(i+1,n):
        temp = 0
        for l in range(d):
            temp += (x[i][l]-x[m][l])**2
            
        temp **= 0.5

        if temp%1==0:
            ans += 1
        
print(ans)

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
table=[input().split() for i in range(N)]
k=0
	
for i in range(N):
	for j in range(N):
		if ((sum((int(table[i][l])-int(table[j][l]))**2 for l in range(D))**0.5).is_integer())==True:
			k=k+1
		
print(int((k-N)/2))

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
x_list = [[int(x) for x in input().split()] for _ in range(n)]
power_list = [i**2 for i in range(200)]
ans = 0

for l in range(~-n):
  for r in range(-~l, n):
    if int(sum([(y-z)**2 for y, z in zip(x_list[l], x_list[r])])) in power_list:
      ans += 1

print(ans)

Submission status: Accepted

Solution code:
from scipy.spatial.distance import euclidean as e

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

ans = 0

for i in range(n):
    for j in range (i+1, n):
        if e( l[i], l[j] ).is_integer(): 
            ans += 1
        
print(ans)

Submission status: Accepted

Solution code:
import math
N,D=map(int,input().split())
a=[]
c=0
for i in range(1,N+1):
    g=list(map(int,input().split()))
    a.append(g)
for i in range(N):
    for k in range(1,N-i):
        dis=0
        for j in range(D):
            z=a[i][j]-a[i+k][j]
            dis=dis+z*z
        dis=math.sqrt(dis)
        b=int(dis)-dis
        if b==0:
            c=c+1
print(c)

Submission status: Accepted

Solution code:
import numpy as np
from collections import defaultdict
from itertools import combinations

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

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

res = 0
for i, j in combinations(range(N),2):
  dist = 0
  for d in range(D):
    delta = X[i][d] - X[j][d]
    dist += delta**2

  if np.sqrt(dist) == int(np.sqrt(dist)):
    res += 1

print(res)

Submission status: Accepted

Solution code:
import numpy as np
N, D = map(int, input().split(' '))
def parse_list(hoge):
  result = list(map(int, input().split(' ')))
  return np.array(result)
points = list(map(parse_list, range(N)))


def calc_dist(points, i , j ):
    result = np.linalg.norm(points[i] - points[j], ord=2)
    return result

res_cnt = 0
for i in range(N):
    for _j in range(N-i-1):
        j = _j + i + 1
        res = calc_dist(points, i, j )
        if float.is_integer(res):
            res_cnt += 1
print(res_cnt)

Submission status: Accepted

Solution code:
import numpy as np

s = input().split()
N = int(s[0])
D = int(s[1])
X=np.empty((0,D),int)
count=0
# X=[[]*int(s[1])]*int(s[0])
for i in range(0,N):
    s = input().split()
    X=np.append(X,np.array([s],dtype='int16'),axis=0)

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

print(count)

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
x = [None for k in range(N)]
for k in range(N):
  a = list(map(int, input().split()))
  x[k] = a
ans = 0
for n in range(N):
  for p in range(n):
    wa = 0
    for d in range(D):
      wa += (x[n][d] - x[p][d])**2
    t = wa ** 0.5
    if wa == int(t) **2:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math


def distance(N, D, X):
    distance_list = list()

    for n in range(N - 1):
        for i in range(n + 1, N):
            tmp = 0
            for d in range(D):
                tmp += (abs(X[n][d] - X[i][d])) ** 2
            distance_list.append(math.sqrt(tmp))

    return distance_list


def main():

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

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

    distance_list = distance(N, D, X)

    ans = 0

    for i in distance_list:
        if i.is_integer():
            ans += 1

    print(ans)

    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
p=list(map(int,input().split()))
data_list = [ list(map(int,input().split(" "))) for i in range(p[0])]
cnt = 0
l = 0
for i in range(p[0]-1):
    for j in range(i+1,p[0]):
        for k in range(p[1]):
            l += pow(abs(data_list[i][k] - data_list[j][k]),2)
        l = pow(l,1/2)
        cnt += 1 if l.is_integer() else 0
        l = 0
print(cnt)