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 = [[int(x) for x in input().split()] for _ in range(N)]

def issq(n):
    """n is a square number."""
    for i in range(n + 1):
        if i * i == n:
            return True
        if i * i > n:
            return False

def distsq(X, Y):
    return sum((x - y) ** 2 for x, y in zip(X, Y))

n = sum(1 for i in range(len(X))
          for j in range(i + 1, len(X))
          if issq(distsq(X[i], X[j])))

print(n)

Submission status: Accepted

Solution code:
import sys
import math
import numpy as np


def input():
    return sys.stdin.readline().rstrip()


def dist(y, z, d):
    ret = 0.0
    for i in range(d):
        ret += pow(y[i] - z[i], 2)
    return pow(ret, 0.5)


def main():
    n, d = [int(e) for e in input().split()]
    x = [[int(e) for e in input().split()] for _ in range(n)]

    ans = 0
    for i in range(n):
        for j in range(i + 1, n):
            dist_yz = dist(x[i], x[j], d)
            if math.ceil(dist_yz) == math.floor(dist_yz):
                ans += 1
    print(ans)


main()

Submission status: Accepted

Solution code:
import math

def distance(a,b,D):
    sum = 0
    for i in range(D):
        sum += (a[i]-b[i]) ** 2
    tmp = math.sqrt(sum)
    if tmp % 1 == 0:
        return 1
    else:
        return 0 

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

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

for i in range(N-1):
    for j in range(i+1,N):
        #点iと点j間の距離を求める
        count += distance(X[i],X[j],D)

print(count)

Submission status: Accepted

Solution code:
from math import sqrt
N, D = map(int, input().split(' '))
 
coordinate_list = list()
 
# 一行ずつ分解してリストに入れる
for i in range(N):
    coordinate = list(input().split())
    coordinate = list(map(int, coordinate))
    coordinate_list.append(coordinate)
 
def make_dis_list(D, coordinate_list):
    distance_list = list()
    for i, coordinate in enumerate(coordinate_list):
        for j in range(i+1, N):
            distance_list.append(measure_distance(coordinate, coordinate_list[j], D))
    return distance_list
 
def measure_distance(a, b, D):
    square_dist = 0
    for i in range(D):
        square_dist += (a[i] - b[i])**2
    return sqrt(square_dist)
 
def int_counter(nums):
    counter = 0
    for num in nums:
        if int(num) == num: counter += 1
    return counter
 
distance_list = make_dis_list(D, coordinate_list)
print(int_counter(distance_list))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
squares = []
for i in range(0, 16001):
	squares.append(i*i)
N, D = map(int, input().split())
X = []
for i in range(0, N):
	X.append(list(map(int, input().split())))
cnt = 0
for i in range(0, N):
	for j in range(i+1, N):
		sqdist = 0
		for k in range(0, D):
			sqdist += (X[i][k]-X[j][k])**2
		if sqdist in squares:
			cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from math import sqrt
N, D = map(int, input().split())
xs = [list(map(int, input().split())) for i in range(N)]

ans = 0
for i in range(N):
    for j in range(i+1, N):
        dist_sum = sum([ (xs[i][k] - xs[j][k])**2 for k in range(D)])
        dist = sqrt(dist_sum)
        if dist % 1 == 0:
            ans += 1
print(ans)

Submission status: Accepted

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

def culc_dist(dot1, dot2):
    dist = 0
    for i in range(len(dot1)):
        dist += (dot1[i] - dot2[i]) ** 2
    dist = dist ** (0.5)
    return dist

ans = 0

for i in range(n):
    for j in range(i + 1, n):
        dist = culc_dist(dots[i], dots[j])
        if dist.is_integer():
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import itertools
import math

dist = lambda X,Y: math.sqrt(sum((x-y)**2 for x,y in zip(X,Y)))

def solve():
    N, D = [int(s) for s in input().split() if s]
    X = []
    cnt = 0
    for _ in range(N):
        X.append([int(s) for s in input().split() if s])
    for x1,x2 in itertools.combinations(X,2):
        if dist(x1,x2).is_integer():
            cnt+=1
    print(cnt)

solve()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
count = 0

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

Submission status: Accepted

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

import sys
import copy
import math

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~

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

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

ans = 0


def isSquared(n):
    return n == math.floor(math.sqrt(n)) ** 2


for i in range(N):
    for j in range(N):
        if i < j:
            ssum = 0
            for k in range(D):
                ssum += (X[i][k] - X[j][k]) ** 2
            ans += isSquared(ssum)


print(ans)

Submission status: Accepted

Solution code:
import operator

N, D = map(int, input().split())
points = []
for n in range(N):
    points.append(tuple(map(int, input().split())))

o = 0
for n in range(N):
    for j in range(n+1, N):
        dist = sum(map(operator.pow, list(map(operator.sub, points[n], points[j])), [2]*D))**(1/2)
        if dist == int(dist):
            o += 1
print(o)

Submission status: Accepted

Solution code:
from itertools import combinations
import numpy as np

# スペース区切りの整数の入力
n, d = map(int, input().split())
vals = [[int(i) for i in input().split()] for _ in range(n)] 

result=0
for i, j in combinations(vals, 2):
    a = np.array(i)
    b = np.array(j)
    dist = (abs(sum((a-b)**2)))**0.5
    if dist.is_integer():
        result+=1
    
# 出力
print("{}".format(result))

Submission status: Accepted

Solution code:
import sys, itertools, collections
sys.setrecursionlimit(10000)

read_ints = lambda: list(map(int, input().split()))
read_int  = lambda: int(input())

SQS = {i * i for i in range(127)}

n, d = read_ints()
p = [read_ints() for _ in range(n)]

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        dist_sq = sum(
            (p[i][k] - p[j][k]) * (p[i][k] - p[j][k])
            for k in range(d)
        )
        if dist_sq in SQS:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
def solve(n, d, x):
    x = np.asarray(x)
    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            y = x[i]
            z = x[j]
            d = np.linalg.norm(y-z)
            if abs(int(d)**2 - d**2) < 1e-5:
                ans += 1
    return ans

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

        if int(Ds**0.5)*int(Ds**0.5) == Ds:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
# ABC133B - Good Distance
import sys
input = sys.stdin.readline

def main():
    N, D = list(map(int, input().rstrip().split()))
    X = tuple(tuple(map(int, input().rstrip().split())) for _ in range(N))
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            r = sum(abs(a - b) ** 2 for a, b in zip(X[i], X[j]))
            if r ** 0.5 == int(r ** 0.5):
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

count = 0
for y, z in itertools.combinations(A, 2):
  d = np.sqrt(((y-z)**2).sum())
  if d == int(d):
    count += 1
print(count)

Submission status: Accepted

Solution code:
from numpy import*
n,*x=[int32(t.split()) for t in open(0)]
print(sum(j==int(j) for i in x for j in map(linalg.norm,i-x))-n[0]>>1)

Submission status: Accepted

Solution code:
def cal(x,y,d):
    res = 0
    for i in range(d):
        res+=(x[i]-y[i])**2
    for i in range(res+1):
        if i*i == res:
            return True
    return False
n, d = map(int, input().split())
ans=0
l = []
for i in range(n):
    a = list(map(int,input().split()))
    l.append(a)
for i in range(n):
    for j in range(i+1,n):
        if (cal(l[i],l[j],d)):
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
from numpy import*
n,*x=[int32(t.split())for t in open(0)]
print(sum(triu([linalg.norm(i-x,2,1)%1==0for i in x],1)))

Submission status: Accepted

Solution code:
from numpy import*
n,*x=[int32(t.split())for t in open(0)]
print(sum(sum(linalg.norm(i-x,2,1)%1==0)for i in x)-n[0]>>1)

Submission status: Accepted

Solution code:
import itertools


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

    count = 0
    for (a, b) in itertools.combinations(x, 2):
        if (sum((pair[0] - pair[1]) ** 2 for pair in zip(a, b)) ** .5).is_integer():
            count += 1
    print(count)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from numpy import*
n,*x=[int32(t.split())for t in open(0)]
print(sum(j%1==0for i in x for j in map(linalg.norm,i-x))-n[0]>>1)

Submission status: Accepted

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

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

count=0
sum=0
for i in range(n):
    for k in range(i+1,n):
        for j in range(d):
            sum+=int((a[i][j]-a[k][j])*(a[i][j]-a[k][j]))
        for l in range(sum+1):
            if sum==l*l:
                count+=1
        sum=0

print(count)

Submission status: Accepted

Solution code:
from numpy import*
n,*x=[int32(t.split())for t in open(0)]
print(sum(j==int(j)for i in x for j in map(linalg.norm,i-x))-n[0]>>1)

Submission status: Accepted

Solution code:
from subprocess import*
call(('python3','-c',"""
from numpy import*
n,*x=[int32(t.split())for t in open(0)]
print((sum(j==int(j)for i in x for j in map(linalg.norm,i-x))-n[0])//2)
"""))

Submission status: Accepted

Solution code:
import math


def issq(x):
    sx = int(math.sqrt(x))
    return any([
        (sx - 1)**2 == x,
        sx**2 == x,
        (sx + 1)**2 == x,
    ])


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

print([
    issq(sum((v - w)**2 for v, w in zip(X[i], X[j])))
    for i in range(N)
    for j in range(i + 1, N)
].count(True))

Submission status: Accepted

Solution code:
import sys
import numpy as np


def cal(X):
    ret = 0
    for i in range(X.shape[0] - 1):
        for j in range(i + 1, X.shape[0]):
            r = 0
            for k in range(X.shape[1]):
                r += (X[i, k] - X[j, k]) ** 2
            d = np.sqrt(r)
            if d - int(d) < 0.000001:
                ret += 1
    return ret


sin_ = sys.stdin.read()
ain = np.fromstring(sin_, dtype=np.int64, sep=' ')
N = ain[0]
D = ain[1]
X = ain[2:N*D + 2].reshape((N, D))
ans = cal(X)
print(ans)

Submission status: Accepted

Solution code:
N,D = map(int,input().split())
A=[]
C=0
E=0
Z=0
for i in range (1,N+1):
    A.append(i)
for i in range (0,N):
    A[i]=list(map(int,input().split()))
for i in range (0,N-1):
    for j in range(i,N-1):
        for k in range(0,D):
            B=(A[i][k]-A[j+1][k])**2
            C+=B
        Z=C
        C=0
        if (Z**(1/2))%1==0:
            E+=1
print(E)

Submission status: Accepted

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

A = [i ** 2 for i in range(150)]

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

print(ans)

Submission status: Accepted

Solution code:
from numpy import*
n,*x=[int32(t.split())for t in open(0)]
print((sum(j==int(j)for i in x for j in map(linalg.norm,i-x))-n[0])//2)

Submission status: Accepted

Solution code:
# ABC133-B

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,d=LI()
  l=[LI() for _ in range(n)]

  c=0
  for i in range(n):
    for j in range(i+1,n):
      x=l[i]
      y=l[j]

      sm=0
      for k in range(d):
        sm+=(x[k]-y[k])*(x[k]-y[k])

      # print(sm)

      a=math.sqrt(sm)
      if a==int(a) and a*a==sm:
        c+=1

  return c

print(main())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

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

count = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        tmp_kyori = np.linalg.norm(x_list[i] - x_list[j])

        hoge = tmp_kyori % 1

        if hoge == 0:
            count += 1

print(count)

Submission status: Accepted

Solution code:
import math
N=list(map(int,input().split()))
a=['X' for _ in range(int(N[0]))]
A=0
for i in range(int(N[0])):
    a[i]=list(map(int,input().split()))
    for t in range(int(i)):
        if i!=t:
            Y=[]
            for s in range(int(N[1])):
                Y+=[(a[i][s]-a[t][s])**2]
            Z=sum(Y)
            if (math.sqrt(Z))- int(math.sqrt(Z))==0:
                A+=1
        else:
            continue
print(A)

Submission status: Accepted

Solution code:
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n,d=IL()
X=[IL() for i in range(n)]
c=0
for i in range(n-1):
    for j in range(i+1,n):
        dis=0
        for k in range(d):
            dis+=(X[i][k]-X[j][k])**2
        if int(dis**0.5)==dis**0.5:
            c+=1
print(c)

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
cnt=0
X=[[0]*D for _ in range(N)]
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):
        total=0
        for k in range(D):
            total+=(X[i][k]-X[j][k])**2
        if total**0.5==int(total**0.5):
            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):
    r1 = X[i]
    for j in range(N-1, -1, -1):
        if i == j:
            break
        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

print(count)

Submission status: Accepted

Solution code:
import math

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

# 2次元リストの用意
X = []

# 2次元リストに格納
for i in range(N):
    X.append([int(i) for i in input().split()])

# print(X)
ans = 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
        
        sq = math.sqrt(total)
        if sq  == int(sq): ans += 1


print('{}'.format(ans))

Submission status: Accepted

Solution code:
import math
N, D = map(int, input().split())
X = []
ans = 0
for i in range(N):
	x = list(map(int, input().split()))
	X.append(x)
	for j in range(i):
		l = 0
		for k in range(D):
			l += (X[j][k] - x[k]) ** 2
		r = math.sqrt(l)
		if l - math.floor(r) ** 2 == 0:
			ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
import math

input = sys.stdin.readline

n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        t = 0
        for l in range(d):
            y = x[i][l]
            z = x[j][l]
            t += (y - z) ** 2
        if math.sqrt(t).is_integer():
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations as comb
import math
n, d = map(int, input().split())
zahyo_list = []
for l in range(n):
    zahyo = list(map(int, input().split()))
    zahyo_list.append(zahyo)

comb_list = list(comb(zahyo_list, 2))

count = 0
for p in comb_list:
    y_zahyo = p[0]
    z_zahyo = p[1]
    hs = 0
    for q in range(d):
        hs += abs(y_zahyo[q]-z_zahyo[q])**2

    if math.sqrt(hs).is_integer():
        count += 1
print(count)

Submission status: Accepted

Solution code:
import math

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

# 2次元リストの用意
X =  [[0 for i in range(D)] for j in range(N)]

# 2次元リストに格納
for i in range(N):
    tmp = [int(j) for j in input().split()]
    for k in range(len(tmp)):
        X[i][k] = tmp[k]

# print(X)
ans = 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
        
        sq = math.sqrt(total)
        if sq  == int(sq): ans += 1


print('{}'.format(ans))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from itertools import combinations


def answer(l):
    results = [np.linalg.norm(np.array(i) - np.array(j))for i, j in combinations(l, 2)]
    return sum(float.is_integer(i) for i in results)


n, d = map(int, input().split())
coodinates = [[int(x) for x in input().split()] for _ in range(n)]
print(answer(coodinates))

Submission status: Accepted

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

x = []

for i in range(n): 
    x.append(input().split())

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import numpy as np
from itertools import combinations


def answer(l):
    results = []
    for i, j in combinations(l, 2):
        v_a = np.array(i)
        v_b = np.array(j)
        results.append(np.linalg.norm(v_a - v_b))
    return sum(float.is_integer(i) for i in results)


n, d = map(int, input().split())
coodinates = [[int(x) for x in input().split()] for _ in range(n)]
print(answer(coodinates))

Submission status: Accepted

Solution code:
from math import sqrt

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

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

count = 0
for i in range(N):
    for j in range(i+1, N):
        dist = 0
        for d in range(D):
            dist += (X[i][d] - X[j][d])**2
        droot = sqrt(float(dist))
        if droot.is_integer():
            count += 1

print(count)

Submission status: Accepted

Solution code:
N,D = map(int, input().split())
X = [[int(i) for i in input().split()] for i in range(N)]
ans = 0
def dis2(x,y):
    T = []
    for i in range(len(x)):
        T.append((x[i]-y[i])**2)
    return sum(T)
for i in range(N):
    for j in range(i+1,N):
        R = dis2(X[i],X[j])
        for k in range(R+1):
            if k**2 == R:
                ans +=1
print(ans)

Submission status: Accepted

Solution code:
import math
def distance(l1, l2):
  l = [0] * len(l1)
  for i in range(len(l)):
    l[i] = (l1[i] - l2[i]) ** 2
  s = sum(l)
  return math.sqrt(s), int(math.sqrt(s))
n,d=map(int, input().split())
l = []

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

c = 0  
for i in range(n):
  for j in range(i+1, n):
    sq, insq = distance(l[i], l[j])
    if sq-insq == 0:
      c +=1
      
print(c)

Submission status: Accepted

Solution code:
import numpy as np
N, D = [int(i) for i in input().split()]
Positions = np.array([[int(i) for i in input().split()] for j in range(N)])
ans = 0
for i, x in enumerate(Positions):
    for y in Positions[i + 1:]:
        if np.linalg.norm(x - y).is_integer():
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N, D = map(int, input().split())
Xs = []
while True:
  Xs.append(list(map(int, input().split())))
  if len(Xs) == N:
    break
result = []
tmp = []
for x in Xs:
  tmp.append(x)
  for n in range(N):
    if Xs[n] in tmp:
      l = np.linalg.norm(np.array(x) - np.array(Xs[n]))
      if l.is_integer() and l > 0:
        result.append(l)
print(int(len(result)))

Submission status: Accepted

Solution code:
import numpy as np
N, D = map(int, input().split())
Xs = []
while True:
  Xs.append(list(map(int, input().split())))
  if len(Xs) == N:
    break
result = []
Xi = 1
tmp = []
for x in Xs:
  tmp.append(x)
  for n in range(N):
    if Xs[n] in tmp:
      l = np.linalg.norm(np.array(x) - np.array(Xs[n]))
      if l.is_integer() and l > 0:
        result.append(l)
print(int(len(result)))

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)]
ans = 0
for i in range(n):
    for j in range(i+1, n):
        s = 0
        for xi, xj in zip(x[i], x[j]):
            s += (xi - xj)**2
        if math.sqrt(s) % 1 == 0:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
from math import *
N,D = map(int,input().split())
lst = [[int(kk) for kk in input().split()] for aa in range(N)]
tot = 0
c = 0

for a in range(1,N):
    for b in range(a):
        c = 0
        for i in range(D):
            c += (lst[a][i] - lst[b][i])**2
        if sqrt(c) == int(sqrt(c)):
            tot += 1
print(tot)

Submission status: Accepted

Solution code:
import numpy as np
N,D = (int(i) for i in input().split()) 
e = [[int(i) for i in input().split()] for i in range(N)] 

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

Submission status: Accepted

Solution code:
import math
N, D = map(int, input().split())
a = []
for i in range(N):
  b = map(int, input().split())
  a += b
res = 0
for i in range(N-1):
  j = i + 1
  while(j < N):
    x = []
    y = []
    for k in range(D):
      x.append(a[i * D + k])
      y.append(a[j * D + k])
    tmp = 0
    for k in range(D):
      tmp += (x[k] - y[k]) ** 2
    if tmp == int(tmp ** 0.5) * int(tmp ** 0.5):
      res += 1
    j += 1
print(res)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

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

d = []
for c in itertools.combinations(X, 2):
    d.append(np.linalg.norm(c[1] - c[0]))

print(len([True for x in d if x.is_integer()]))

Submission status: Accepted

Solution code:
import numpy as np
import types
N, D = map(int, input().split())
Xs = []
while True:
  Xs.append(list(map(int, input().split())))
  if len(Xs) == N:
    break
result = []
Xi = 1
tmp = []
for x in Xs:
  tmp.append(x)
  for n in range(N):
    if Xs[n] in tmp:
      l = np.linalg.norm(np.array(x)-np.array(Xs[n]))
      if l.is_integer() and l>0:
        result.append(l)
print(int(len(result)))

Submission status: Accepted

Solution code:
import math
def isPerfect(a):
  x1=math.floor(math.sqrt(a))
  if((x1*x1)==a):
    return True
  return False
n,d=map(int,input().split())
mat=[]
for _ in range(n):
  l=list(map(int,input().split()))
  mat.append(l)
c=0
for i in range(n):
  l1=mat[i]
  for j in range(i+1,n):
    l2=mat[j]
    sm=0
    for k in range(len(l2)):
      x=abs(l2[k]-l1[k])
      sm=sm+(x*x)
    if(isPerfect(sm)):
        c+=1
print(c)

Submission status: Accepted

Solution code:
import math
dlst = []

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

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

count=0
distance = 0

for i in range(N-1):
    for m in range(i+1,N):
        distance = 0
        for j in range(D):
            distance += (dlst[i][j] - dlst[m][j])**2
        judge=math.sqrt(distance)
        if judge.is_integer():
            count += 1
print(count)

Submission status: Accepted

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

for i in range(n):
  b=list(map(int,input().split()))
  a.append(b)
for i in range(n-1):
  for j in range(i+1,n):
    cnt=1
    dist=0
    for k in range(d):
      dist+=(a[i][k]-a[j][k])**2
    while cnt**2<=dist:
      if cnt**2==dist:
        ans+=1
      cnt+=1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np


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


for i in range(n,0,-1):
    for j in range(i-1,0,-1):
        a=np.array(X[i-1])
        b=np.array(X[j-1])
        u=b-a
        u=np.linalg.norm(u)
        if(int(u)==u):
            cnt+=1

        
print(cnt)

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
import numpy as np
import types
N, D = map(int, input().split())
Xs = []
while True:
  Xs.append(list(map(int, input().split())))
  if len(Xs) == N:
    break
result = []
Xi = 1
for x in Xs:
  for d in range(N):
    a = np.array(x)
    b = np.array(Xs[d])
    l = np.linalg.norm(a-b)
    if l.is_integer() and l>0:
      result.append(l)
print(int(len(list(result))/2))

Submission status: Accepted

Solution code:
import math
N,D=map(int,input().split())
X=[list(map(int,input().split())) for _ in range(N)]
def d(x,y):
    kyori=0
    for a,b in zip(x,y):
        kyori+=abs(a-b)**2
    return kyori
ans=0
for i in range(N-1):
    for j in range(i+1,N):
        if math.sqrt(d(X[i],X[j])).is_integer():
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import math

buf=input().split(" ")

N=int(buf[0])
D=int(buf[1])

arr = np.empty((0,D), int)

for i in range(N):
  buf=input().split(" ")
  buf = [int(s) for s in buf]

  arr=np.append(arr, [buf], axis=0)
  

buf=0
c=0

for i in range(N):
  for j in range(N):
    if i<j:
      for k in range(D):
        buf=abs((arr[i,k]-arr[j,k])*(arr[i,k]-arr[j,k]))+buf
      buf=math.sqrt(buf)
      if buf.is_integer() == True:
        c=c+1
      buf=0
          
print(c)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
x=[[0]*1]*n
for i in range(n):
    x[i]=list(map(int,input().split()))
#print(x)
ans=0
for k in range(n):
    for t in range(k+1,n):
        dis=0
        for kai in range(d):
            dis+=(x[k][kai]-x[t][kai])**2
        #print(dis**(1/2))
        if(dis**(1/2)%1==0.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 i in range(N)]
ans = 0
for i in range(N):
    for j in range(i+1, N):
        s = 0
        for xi, xj in zip(X[i], X[j]):
            s += (xi - xj)**2
        # print(math.sqrt(s) % 1)
        if math.sqrt(s) % 1 == 0:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
X = []
for i in range(N):
    X.append([int(i) for i in input().split()])
ans = 0
def d(a, b):
    num = 0
    for x, y in zip(a, b):
        num += (x-y)**2
    return num**(1/2)

for i in range(N-1):
    for j in range(i+1, N):
        a = d(X[i], X[j])
        if a == int(a):
            ans += 1
print(ans)