Problem:


Score : 200 points

Problem Statement

There are N points in a D-dimensional space.

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

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

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

Constraints

All values in input are integers.

2 \leq N \leq 10

1 \leq D \leq 10

-20 \leq X_{ij} \leq 20

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

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

3 2
1 2
5 5
-2 8

Sample Output 1

1

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

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

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

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

Sample Input 2

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

Sample Output 2

2

Sample Input 3

5 1
1
2
3
4
5

Sample Output 3

10



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


Sample output:
1

Submission status: Accepted

Solution code:
import numpy as np
import numpy.linalg as la
import math


def BC133_B():
    n, d = map(int, input().split())
    l = []
    for i in range(n):
        l.append(np.array(list(map(int, input().split()))))
    a = 0
    for i in range(n):
        for j in range(i):
            d = la.norm(l[i] - l[j])
            if int(d + 0.5)**2 == d**2: a += 1
    print(a)


BC133_B()

Submission status: Accepted

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

def dis(xa, xb):
  dis_ = 0
  for a, b in zip(xa, xb):
    dis_ += (a - b) ** 2
  dis_ = dis_ ** 0.5
  return dis_

cnt = 0
for i in range(n):
  for j in range(i+1, n):
    d = dis(x[i], x[j])
    if d % 1.0 == 0:
      cnt += 1
print(cnt)

Submission status: Accepted

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

def distance(a,b):
	total = 0
	for i in range(len(a)):
		total += (a[i] - b[i])**2	
	return np.sqrt(total)

ans = 0				
for i in range(n-1):
	for j in range(i+1,n):
		if distance(points[i],points[j]) == int(distance(points[i],points[j])):
			ans += 1
			
print(ans)

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):
        distance=0
        for k in range(d):
            distance=distance+(x[i][k]-x[j][k])**2
        root_distance=int(distance**(1/2))
        if abs(distance-root_distance*root_distance)<10**(-6):
            ans=ans+1
print((ans-n)//2)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
x=[]
for i in range(n):
	p=list(map(int,input().split()))
	x.append(p)
heihoukon=[]
for i in range(200):
	heihoukon.append(i**2)
ans=0
for a in range(n):
	for b in range(n):
		cnt=0
		for c in range(d):
			cnt+=(x[a-1][c]-x[b-1][c])**2
		if cnt in heihoukon and a!=b:
			ans+=1
print(ans//2)

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
X = []
for _ in range(N):
    X.append([int(x) for x in input().split()])
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 float.is_integer(dist ** (1/2)):
            count += 1
print(count)

Submission status: Accepted

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

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

import math
def calc_distance(arr1, arr2):
    total = 0
    for x, y in zip(arr1, arr2):
        total += (x - y) ** 2
    return math.sqrt(total)

ans = 0
for i in range(len(point_list)):
    for j in range(i + 1, len(point_list)):
        ans += calc_distance(point_list[i], point_list[j]).is_integer()
        
print(ans)

Submission status: Accepted

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

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

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        tmp = 0
        for x, y in zip(coord[i], coord[j]):
            tmp += (x - y) ** 2
        if (tmp ** 0.5).is_integer():
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

def main():
    num, d = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(num)]
    ans = 0
    for i in range(num):
        for j in range(i + 1, num):
            a = data[i]
            b = data[j]
            kari = 0
            for k in range(d):
                kari += (a[k] - b[k]) ** 2
            kari_s = int(kari ** 0.5)
            if kari == kari_s ** 2:
                ans += 1
    print(ans)






if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------
N, D = map(int, input().split())		# 5 7 2

A=[]

for _ in range(N):
	a =        list( map(int, input().split()) )	# 1 2 3 4 5 ...
	A.append(a)


def calc(X,Y):
	a = 0
	for k in range(D):
		a += (X[k]-Y[k])**2
	
	a = a**(1/2)
	return (a == int(a))
	

ans=0
for i in range(N-1):
	for j in range(i+1,N):
		X = A[i]
		Y = A[j]
		
		if calc(X,Y):
			ans +=1
			#p("i,j", i,j)

print(ans)

Submission status: Accepted

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

def calcdistance(point1,point2):
    total = 0
    for i in range(len(point1)):
        total += (point1[i]-point2[i])**2
    return total**(0.5)
    
points = []
for i in range(N):
    points.append(list(map(int, input().split())))

ans = 0
for i in range(N):
    for j in range(i,N):
        if i == j:
            continue
        else:
            distance = calcdistance(points[i],points[j])
            if distance.is_integer():
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
data = []
ans = 0
for i in range(n):
    lista=[int(l) for l in input().split()]
    data.append(lista)
    for j in range(i):
        dist = 0
        for _ in range(d):
            dist += (data[i][_]-data[j][_])**2
        dist = dist**(1/2)
        if dist == int(dist):
            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)]

ok = {}
for i in range(401):
    ok[i**2] = True

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

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
l=[[] for i in range(n)]
for i in range(n):
  l[i]=list(map(int,input().split()))
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    c=0
    for h in range(d):
      c+=(l[i][h]-l[j][h])**2
    if (int(c**(1/2)))**2==c:
      ans+=1
print(ans)

Submission status: Accepted

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

def isSqrt(n):
    m = 0
    while m * m <= n:
        if m * m == n:
            return True
        m += 1
    return False

ret = 0
for p1 in range(n - 1):
    for p2 in range(p1 + 1, n):
        dist = 0
        for i in range(dimen):
            dist += abs(a[p1][i] - a[p2][i]) ** 2
        if isSqrt(dist):
            ret += 1
print(ret)

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):
  for j in range(i+1, N):
    dst = 0
    for d in range(D):
      dst += (x[i][d] - x[j][d])**2
    dst = dst ** 0.5
    if int(dst) == dst:
      ans += 1

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations
import math

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

seq = combinations(xs, 2)
count = 0
for xs in seq:
    sum = 0
    for a, b in zip(xs[0], xs[1]):
        sum += abs(a - b)**2

    sum2 = int(math.sqrt(sum))**2
    if sum == sum2:
        count += 1

print(count)

Submission status: Accepted

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


main()

Submission status: Accepted

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

l = []

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

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

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
n,d=map(int,input().split())
x=[]
ans=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):
        tmp=0
        for k in range(d):
            tmp+=(x[i][k]-x[j][k])**2
        if tmp**(1/2)%1==0:
            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)]

ans = 0
for i,Y in enumerate(X[:-1]):
	for j,Z in enumerate(X[i+1:]):
		res = 0
		for y,z in zip(Y,Z):
			res += (y-z)**2
		if res**0.5%1 == 0:
			ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math

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

def kyori(ys, zs):
    result = 0
    for y, z in zip(ys, zs):
        result += (y - z) ** 2
    return math.sqrt(result)
    
cnt = 0
for i in range(0, n):
    for j in range(i+1, n):
        res = kyori(xs[i], xs[j])
        if res == int(res):
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np

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

cnt = 0
for i in range(len(dl)):
    for j in range(len(dl)):
        if i ==j:
            break
        if np.linalg.norm(np.array(dl[i])-np.array(dl[j])).is_integer():
            cnt +=1
            
print(cnt)

Submission status: Accepted

Solution code:
n,d = map(int, input().split(' '))
dot = [list(map(int, input().split(' '))) for i in range(n)]
def dist(Y, Z):
  temp = 0
  for y,z in zip(Y,Z):
    temp += abs(y-z)**2
  return temp**0.5

ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    ret = dist(dot[i], dot[j])
    if int(ret) == ret:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
x = []
for i in range(n):
  xi = list(map(int, input().split()))
  x.append(xi)
#print(x)  
ans = 0  
for i in range(n):
  for j in range(i+1,n):
    dij = sum([(x[i][_] - x[j][_])**2 for _ in range(d)])**(1/2)
    if dij % 1 == 0:
      ans +=1
      
print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n,d=MAP()
    x = [LIST() for _ in range(n)]
    comb=combinations(range(n),2)
    ct=0
    for r in comb:
        #print(r)
        dis=0
        for i in range(d):
            dis+=(x[r[0]][i]-x[r[1]][i])**2

        if int(sqrt(dis)) == sqrt(dis):
            ct+=1

    print(ct)






if  __name__=='__main__':
    main()

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 xi in range(len(x)):
  for xj in range(xi+1,len(x)):
    dists = [(x[xi][k]-x[xj][k])**2 for k in range(d)]          
    dist = math.sqrt(sum(dists))
    #print(dists,dist)
    if dist.is_integer():
      count+=1
print(count)

Submission status: Accepted

Solution code:
N,D = map(int,input().split())
X_list = []
for i in range(N):
    X_list.append(list(map(int,input().split())))
def try_square_root_naive(n):
    m = int(n**.5)
    return True if abs(m*m - n) < 1e-6 else None
cnt = 0
for i in range(N-1):
    for j in range(i+1,N):
        L = 0
        for d in range(D):
            L += (X_list[i][d]-X_list[j][d])**2
        if try_square_root_naive(L):
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from math import sqrt
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
def distance(x1, x2):
    ans = 0
    for d1, d2 in zip(x1, x2):
        ans += (d1 - d2) ** 2
    return float(sqrt(ans)).is_integer()

res = 0

for i in range(n):
    for j in range(n):
        if j == i:
            continue
        if distance(x[i], x[j]):
            res += 1

print(res // 2)

Submission status: Accepted

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

flg = 0
for i in range(N):
    for j in range(i, N):
        if i==j:
            continue
        d = 0
        for k in range(D):
            d += pow((X[i][k] - X[j][k]), 2)
        if pow(d, 0.5).is_integer():
            flg += 1
print(flg)

Submission status: Accepted

Solution code:
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

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

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

cnt = 0

for i in range(N):
    for j in range(i+1, N):
        dist = 0.0
        for k in range(D):
            dist += abs(X[i][k] - X[j][k]) * abs(X[i][k] - X[j][k])
        dist = math.sqrt(dist)

        if dist.is_integer():
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
# coding: utf-8
import time
import re
import math
import fractions

def main():
    N,D=map(int,input().split())
    points=[]
    for a in range(N):
        points.append(list(map(int,input().split())))
        count=0
    for a in range(N):
        for b in range(a+1,N):
            if getD(points[a],points[b])%1==0:
                count+=1
    print(count)
def getD(xarr,yarr):
    d=0
    for a in range(len(xarr)):
        d+=(xarr[a]-yarr[a])**2
    return math.sqrt(d)
start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#N=int(input())

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
X = []
for _ in range(n):
    l = list(map(int, input().split()))
    X.append(l)
mat = [[0 for _ in range(n)] for _ in range(n)]
import numpy as np
def f(a,b):
    return sum([(i-j)**2 for i, j in zip(a, b)])
for i in range(n):
    for j in range(i+1, n):
        mat[i][j] = np.sqrt(f(X[i], X[j]))
ans = 0
for i in range(n):
    for j in range(i+1, n):
        if mat[i][j].is_integer():
            ans +=1
print(ans)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
L=[]
ans=0
for _ in range(n):L.append(list(map(int,input().split())))
for i in range(n):
    for j in range(n):
        if i==j:pass
        else:
            p=0
            for k in range(d):p+=(L[i][k]-L[j][k])**2
            if p**0.5==int(p**0.5):ans+=1
print(ans//2)

Submission status: Accepted

Solution code:
import numpy as np
import math

n,d=list(map(int, input().split()))
x = []
for i in range(n):
    x.append(list(map(int, input().split())))
xn =np.asarray(x)
cnt = 0
for i in range(n):
    for j in range(i+1,n):
        t = xn[i,:] - xn[j,:]
        t2 = np.square(t)
        t3 = np.sum(t2)
        if (np.sqrt(t3)).is_integer():
            cnt += 1
            
print(cnt)

Submission status: Accepted

Solution code:

import math

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

space = []
count = 0

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

for i in range(N):
    for j in range(i+1, N):
        if i != j:
            num = 0
            for k in range(D):
                num += (space[i][k] - space[j][k])**2
            num = math.sqrt(num)
            if int(num) - num == 0:
                count += 1

print(count)

Submission status: Accepted

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

x = np.zeros((n,d))

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

count = 0
for i in range(0,n-1):
    for j in range(i+1,n):
        d = np.linalg.norm(x[i,:]-x[j,:])
        if d == int(d):
            count += 1

print(count)

Submission status: Accepted

Solution code:
from sys import exit
import math

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

Xs = []

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

count = 0

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

print(count)

Submission status: Accepted

Solution code:
#B問題
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(N-i-1):
        J=i+j+1
        dist = 0
        for k in range(D):
            dist+=(X[i][k]-X[J][k])**2
        flag = 0
        for d in range(dist):
            if (dist/(d+1)) == d+1:
                flag = 1
        if flag == 1:
            count+=1
print(count)

Submission status: Accepted

Solution code:
def dst(Xi, Xj):
  S = 0
  for i in range(len(Xi)):
    S += (Xi[i] - Xj[i]) ** 2
  return S

def isz(X):
  c = 0
  while c ** 2 < X:
    c += 1
  if c ** 2 == X:
    return True
  else:
    return False


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

for i in range(N):
  for j in range(i, N):
    if i != j and isz(dst(X[i], X[j])):
      s += 1
print(s)

Submission status: Accepted

Solution code:
# coding: utf-8
n, d = list(map(int, input().split()))
x = []
for i in range(n):
    _x = list(map(int, input().split()))
    x.append(_x)
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        dist = 0
        for k in range(d):
            dist += (x[i][k] - x[j][k]) ** 2
        _r = dist**0.5
        if int(_r) == _r:
            ans += 1
print(ans)

Submission status: Accepted

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

def distance(x,y,d):
    inner=0
    for i in range(d):
        inner+=(x[i]-y[i])**2
    return math.sqrt(inner)

ans=0
for i in ls:
    for j in ls:
        if distance(i,j,d).is_integer() and distance(i,j,d)!=0:
            ans+=1

print(int(ans/2))

Submission status: Accepted

Solution code:
import math

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

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

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

        if norm == int(norm):
            count += 1
print(count)

Submission status: Accepted

Solution code:
import itertools, math

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

for p_1, p_2 in itertools.combinations(points, 2):
    dist = 0
    for i in range(d):
        dist += (p_1[i] - p_2[i]) ** 2
    if math.sqrt(dist).is_integer():
        count += 1
        
print(count)

Submission status: Accepted

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

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

for i in range(n):
    for j in range(i+1, n):
        ans = 0
        for k in range(d):
            ans += (input[i][k] - input[j][k])**2
        ans = ans**(1/2)
        if is_integer_num(ans):
            count += 1
print(count)

Submission status: Accepted

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

import itertools
cnt = 0

for x, y in list(itertools.combinations(X, 2)):
    dist = 0
    for i in range(D):
        dist += (x[i]-y[i])**2
    if (dist**0.5)%1==0:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import math
n,d = map(int,input().split())
x = []
for _ in range(n):
  x.append(list(map(int,input().split())))
score = 0
for i in range(n):
  for j in range(n):
    tmp = 0
    for dd in range(d):
      tmp += ( x[i][dd] - x[j][dd] ) ** 2
    sq = math.floor(tmp ** (1/2))
    if tmp == sq ** 2:
      score += 1
print((score-n)//2)

Submission status: Accepted

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

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

seisuuninaru = {i**2 for i in range(128)}

cnt = 0
for i in range(N):
    for j in range(i):
        kyori = 0
        for k in range(len(points[i])):
            kyori += (points[i][k] - points[j][k]) ** 2
        if kyori in seisuuninaru:
            cnt += 1

print(cnt)

Submission status: Accepted

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

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

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

print(count)

Submission status: Accepted

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

def squares(a,b):
    return (a-b)**2

count = 0
for i in range(n):
    for j in range(i+1,n):
        total = 0
        for x in range(d):
            total = total + squares(x_list[i][x],x_list[j][x])
        if ((total)**(1/2)).is_integer():
            count = count +1

print(count)

Submission status: Accepted

Solution code:
import numpy as np

words = lambda t : list(map(t, input().split()))
n,d = words(int)

a = []
for i in range(n):
    k = words(int)
    a.append(k)

def dist(x,y):
    ttl = 0
    for x1,y1 in zip(x,y):
        ttl += (abs(x1 - y1))**2
    return np.sqrt(ttl)

ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        ds = dist(a[i], a[j])
        #print(i, j, a[i], a[j], ds)
        if ds == round(ds):
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math
        
def func(A, B):
    tmp = 0
    for a, b in zip(A,B):
        tmp += (a- b)**2
        
    return math.sqrt(tmp)
N, D = list(map(int, input().split(" ")))

X = []
cnt = 0
for _ in range(N):
      X.append(list(map(int, input().split(" "))))

for i in range(N-1):
    for j in range(i+1,N):
        ans = func(X[i], X[j])
        if ans % 1 == 0:
            cnt += 1
            
print(cnt)

Submission status: Accepted

Solution code:
import math
n, m = map(int, input().split())
temp = []
a = []
for i in range(n):
    temp = []
    temp = input().split()
    a.append(temp)
ans = 0
for i in range(n):
    for j in range(i+1, n):
        res = 0
        for k in range(m):
            res += abs(int(a[j][k]) - int(a[i][k]))*abs(int(a[j][k]) - int(a[i][k]))
        res2 = math.sqrt(res)
        if int(res2) == res2:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

X = np.array(X)

cnt = 0
for i in range(N):
    for j in range(i,N):
        if i != j:
            distance = np.sqrt(np.power(X[i]-X[j], 2).sum())
            if distance.is_integer():
                cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math

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

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

print(cnt)

Submission status: Accepted

Solution code:
import math
N, D = map(int, input().split())  # D次元空間にN個の点

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

ans = 0

for i in range(N):
    for j in range(i+1, N):
        distance = sum([(a-b)**2 for a, b in zip(zahyo[i], zahyo[j])])
        distance = distance ** (1/2)
        if distance == math.ceil(distance):
            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)]

cnt = 0
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        a = 0
        for k in range(D):
            a += (X[i][k] - X[j][k]) ** 2
        a = a ** 0.5
        if int(a) == a:
            cnt += 1

print(cnt // 2)

Submission status: Accepted

Solution code:
import math

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

def dist(x, y):
    tmp = 0.0
    for i in range(d):
        tmp += (x[i] - y[i]) ** 2
    return math.sqrt(tmp)


count = 0
for i, elm in enumerate(points):
    for j in range(i+1, n):
        if dist(elm, points[j]).is_integer():
            count += 1

print(count)

Submission status: Accepted

Solution code:
# 最初に入れておくとinputが早くなる
import sys
input = sys.stdin.readline

# スタック最大数をセット
sys.setrecursionlimit(10**6)


def kyori(l1, l2):
    goukei = 0
    for i in range(len(l1)):
        goukei += (l1[i] - l2[i]) ** 2
    return goukei**0.5


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

ans = 0
for i in range(n):
    for j in range(i+1, n):
        if (kyori(x[i], x[j]).is_integer()):
            #print(i, j, kyori(x[i], x[j]).is_integer())
            ans += 1
print(ans)

Submission status: Accepted

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

n=0
for i in range(N):
    for j in range(i+1, N):
        d2 = 0
        for k in range(D):
            diff = X[i][k]-X[j][k]
            d2 += diff * diff
        if int(d2**0.5)	* int(d2**0.5) == d2:
            n+=1

print(n)

Submission status: Accepted

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

import math

cnt = 0

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

Submission status: Accepted

Solution code:
N, D = [int(x) for x in input().split()]
x_list = [[int(x) for x in input().split()] for _ in range(N)]
sq = [n*n for n in range(1000)]
cnt = 0
for i, xi in enumerate(x_list):
    for xj in x_list[i+1:]:
        dist = sum([(y-z)*(y-z) for y, z in zip(xi, xj)])
        cnt += (dist in sq)
print(cnt)

Submission status: Accepted

Solution code:
from sys import stdin
N, D = [int(x) for x in stdin.readline().rstrip().split()]
X = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]

cnt = 0
for j in range(N):
    for k in range(j, N):
        dis = 0
        for d in range(D):
            dis += (X[j][d] - X[k][d]) ** 2
        if dis > 0 and (dis ** 0.5) % 1 == 0:
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
N, D = [int(nd) for nd in input().split()]
X = []
for n in range(N):
  X.append([int(x) for x in input().split()])
  
ans = 0
for i in range(0, N-1):
  for j in range(i+1, N):
    d_ij = 0
    for d in range(D):
      d_ij += (X[i][d] - X[j][d]) ** 2
    d_ij = (d_ij) ** (1/2)
    if d_ij == int(d_ij):
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math

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

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

dbl = []
for i in range(1,1000):
        dbl.append(i**2)

ans = 0
for idx,val in enumerate(X):
        for idx2, val2 in enumerate(X):
                if idx == idx2:
                        continue
                elif idx < idx2:
                        break
                tmp = 0
                for d in range(D):
                        tmp += abs(val[d] - val2[d]) ** 2
                if tmp in dbl:
                        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
#print(X)
ans = 0
for i in range(len(X)):
    for j in range(i+1, len(X)):
        summ = 0
        #print(i, j)
        for d in range(D):
            summ += (X[i][d] - X[j][d])**2
        dist = math.sqrt(summ)
        #print(dist)
        if dist - int(dist) == 0:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math

def get_distance(point_A, point_B) :
    s = 0
    for i in range(len(point_A)) :
        s += pow(abs(point_A[i] - point_B[i]),2)
    
    return math.sqrt(s)


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

count = 0
for i in range(N) :
    for k in range(i,N) :
        if (i == k) :
            continue
        
        d = get_distance(points[i], points[k])
        # print(d)
        if (float.is_integer(d)) :
            count += 1
        
print(count)

Submission status: Accepted

Solution code:
N, D = map(int, input().split()) # 横に2個
X = []
c = 0
for _ in range(N):
    Xi = list(map(int, input().split())) # １行に別れてるとき
    for x in X:
        dis = 0
        for i in range(D):
            dis += (x[i] - Xi[i])**2
        for k in range(200):
            if dis == k**2:
                c += 1
    X.append(Xi)

print(c)