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 math
n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]

count = 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
        dis = math.sqrt(dis)
        if dis.is_integer():
            count += 1

print(count)

Submission status: Accepted

Solution code:
N, d = map(int, input().split())
P = [list(map(int,input().split())) for i in range(N)]

import numpy as np
p1 = np.array(P)
tmp_index = np.arange(p1.shape[0])
xx, yy = np.meshgrid(tmp_index, tmp_index)
distances = np.linalg.norm(p1[xx]-p1[yy], axis=2)
results = np.reshape(np.tril(distances), (1, N**2))


a = 0
for i in range(0, N**2):
  if(results[0][i]!=0 and results[0][i] == np.int64(results[0][i])):
    a += 1
print(a)

Submission status: Accepted

Solution code:
#n=int(input())
n,d=map(int,input().split())
#l=list(map(int,input().split()))
xl=[list(map(int,input().split())) for i in range(n)]

ans=0
import math
for i in range(n):
    for j in range(n):
        if i>=j:
	        continue
        total=0
        for k in range(d):
            total+=(xl[i][k]-xl[j][k])**2
        total=math.sqrt(total)
        if total==int(total):
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
from math import sqrt
n,d=map(int,input().split())
xs=[tuple(map(int,input().split())) for _ in range(n)]
ans=0
for i in range(n-1):
    xi=xs.pop()    
    for xj in xs:
        o=sqrt(sum((y-z)**2 for y,z in zip(xi,xj)))
        ans += o//1==o
print(ans)

Submission status: Accepted

Solution code:
from math import sqrt
n, d = map(int, input().split())
xs = [tuple(map(int, input().split())) for _ in range(n)][::-1]

ans = 0

for i in range(n-1):
    xi = xs.pop()
    
    for xj in xs:
        o2 = [(y-z)**2 for y,z in zip(xi, xj)]
        o = sqrt(sum(o2))
        
        if o//1 == o:
            ans += 1

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np

N, D = [int(i) for i in input().split()]
X = np.zeros((N,D))
for i in range(N):
    X[i] = [int(i) for i in input().split()]
    
count_dummy=0
for i in range(N):
    for j in range(i+1,N):
        dist = (np.sum((X[i] - X[j])**2))**0.5
        if dist.is_integer():
            count_dummy+=1
            
print(count_dummy)

Submission status: Accepted

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

ans = 0
for i in range(N):
  for j in range(i+1, N):
    dist_sq = 0
    for x, y in zip(X[i], X[j]):
      dist_sq += (x - y) ** 2

    dist = dist_sq ** 0.5
    #print(i, j, dist)

    if dist - int(dist) == 0:
      ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math
#import numpy


def readints():
    return list(map(int, input().split()))


n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
# print(x)
a = 0
for i in range(0, n-1):
    for j in range(i+1, n):
        sum = 0
        for k in range(d):
            #print(i, j, k)
            sum += ((x[i][k]-x[j][k])**2)
        sum = sum**0.5
        # print(sum)

        if sum == int(sum):
            a += 1

print(a)

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

Submission status: Accepted

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

for j in range(N):
  for k in range(j+1,N):
    tmp=sum([(X[j][l]-X[k][l])**2 for l in range(D)])
    if tmp in [y**2 for y in range(130)]:
      c +=1
print(c)

Submission status: Accepted

Solution code:
# coding: utf-8
import math

(n,d) = [int(i) for i in input().rstrip().split(" ")]

point_list = [[int(i) for i in input().rstrip().split(" ")] for j in range(n)]

ans = 0
for i in range(n):
    for j in range(i+1,n):
       temp = sum([pow(point_list[i][k] - point_list[j][k],2) for k in range(d)])
       sq = int(math.sqrt(temp))
       if sq * sq == temp:
           ans += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools
N,D=map(int,input().split())
zahyo=[]

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False
for _ in range(N):
    x=list(map(int,input().split()))
    zahyo.append(x)    
cnt=0
for y in itertools.combinations(zahyo,2):
    
    kyori=[(i-j)**2 for i,j in zip(y[0],y[1])]
    soukyori=(sum(kyori))**(1/2)
    if is_integer_num(soukyori):
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
from itertools import combinations
N, D = map(int, input().split())
X = []
for _ in range(N):
  X += list(map(int, input().split()))
cnt = 0
for i, j in combinations(range(N),2):
  d = 0
  for k in range(D):
    d += (X[i*D + k] - X[j*D + k])**2
  if int(d**0.5)**2 == d: cnt += 1
print(cnt)

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):
		ans += (sum((a-b)**2 for a,b in zip(x[i],x[j]))**0.5).is_integer()
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 accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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

N, D = MAP()
X = [LIST() for _ in range(N)]

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

com = list(combinations(X, 2))

pare = 0
for x in com:
	dis = 0
	for i in range(len(x[0])):
		dis += (x[0][i] - x[1][i])**2
	dis = sqrt(dis)
	if is_integer_num(dis):
		pare += 1

print(pare)

Submission status: Accepted

Solution code:
from itertools import combinations

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

def dist(x1, x2):
    return sum((xx1 - xx2) ** 2 for xx1, xx2 in zip(x1, x2))

def is_acceptable(d):
    dd = round(d ** 0.5)
    return dd ** 2 == d

print(sum(is_acceptable(dist(x1, x2)) for x1, x2 in combinations(X, 2)))

Submission status: Accepted

Solution code:
import sys
read=sys.stdin.buffer.readline

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

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

Submission status: Accepted

Solution code:
import sys
import numpy as np

n, d, *x = map(int, sys.stdin.read().split())
x = np.array(x, dtype=np.int64).reshape(n, d)

def main():
    cnt = 0
    for i in range(n-1):
        for j in range(i+1, n):
            dist = np.sqrt(((x[i] - x[j]) ** 2).sum())
            if dist == int(dist):
                cnt += 1
    
    return cnt
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# https://atcoder.jp/contests/abc133/tasks/abc133_b

import itertools
n, d = [int(x) for x in input().split()]
x = []
cnt = 0
for _ in range(n):
    x.append([int(x) for x in input().split()])
for a, b in itertools.combinations(x, 2):
    d = sum([(x1 - x2)**2 for x1, x2 in zip(a, b)])**0.5
    if d.is_integer():
        cnt += 1
print(cnt)

Submission status: Accepted

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

total_d = 0
count=0
for i in range(N-1):
    for k in range(i+1,N):
        for j in range(D):
            d = abs(X[i][j]-X[k][j])
            total_d += d**2
            #print(d)
        #print(d,total_d)
        if (total_d**(1/2)).is_integer():
            count+=1
            total_d = 0
        else:
            total_d = 0
        
print(count)

Submission status: Accepted

Solution code:
import math
n,d=map(int,input().split())
a=[[int(i) for i in input().split()] for l in range(n)]
c=0
for i in range(n):
    for j in range(i+1,n):
        sum=0
        for x,y in zip(a[i],a[j]):
            sum+=(abs(x-y))**2
        if math.sqrt(sum)%1==0:c+=1
print(c)

Submission status: Accepted

Solution code:
# #!/usr/bin/env python3
# # -*- coding: utf-8 -*-

from itertools import combinations


def main():
    N, D = map(int, input().split())
    X = [list(map(int, input().split()))for _ in range(N)]
    count = 0
    for a, b in combinations(X, 2):
        tmp = 0
        for d in range(D):
            tmp += abs(a[d] - b[d])**2
        if (tmp**0.5).is_integer():
            count += 1
    print(count)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

def is_square(n):
    res=n**0.5
    return res.is_integer()

cnt = 0
for i in range(n):
    for j in range(i+1,n):
        dist = 0
        for k in range(d):
            #i行目とj行目
            dist += (dis[i][k]-dis[j][k])**2
        if is_square(dist) == True: cnt+=1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n-1):
    
    for j in range(i,n-1):
        x = 0
        for k in range(d):
            x += (lis[i][k]-lis[j+1][k])**2
        
        if x**0.5 % 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)]

import math
ans = 0
for i in range(N):
    X1 = X[i]
    for X2 in X[i+1:]:
        if math.sqrt(sum([(x1-x2)**2 for x1, x2 in zip(X1, X2)])).is_integer():
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

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

ans = 0
for a, b in combinations(d, 2):
    dist = sum(abs(i-j)**2 for i,j in zip(a, b))
    for i in range(1, int(dist**0.5)+1):
        if i**2==dist:
            ans += 1
            break
    
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 - 1):
    for j in range(i + 1, n):
        tmp = 0
        for k in range(d):
            tmp += (x[i][k] - x[j][k]) ** 2
        dis = tmp ** (1 / 2)
        if dis.is_integer():
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N,D = [int(i) for i in input().split()]
X = [0]*N
for i in range(N):
    X[i] = [int(i) for i in input().split()]
count = 0
for i in range(N-1):
    for j in range(i+1,N):
        ans = 0
        for k in range(D):
            ans += (X[i][k] - X[j][k]) ** 2
        ans = ans ** (1/2)
        if ans.is_integer():
            count+=1
print(count)

Submission status: Accepted

Solution code:
n,d = map(int,input().split())
x = []
for i in range(n):
    xi = [int(i) for i in input().split()]
    x.append(xi)
count = 0
ans = 0
for i in range(n-1):
    for l in range(i+1,n):
        ans = 0
        for j in range(d):
            ans += (x[i][j]-x[l][j])**2

        ans = ans **(1/2)
        if ans == int(ans):
            count += 1
print(count)

Submission status: Accepted

Solution code:
import math
import numpy as np

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

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

def cal_distance(a, b):
    distance = np.sqrt(np.sum((a - b) ** 2))
    return (distance)

for i in range(N):
    
    for j in range(i + 1, N):
        
        dis = cal_distance(X[i], X[j])
        if (math.floor(dis) == dis):
            ctr += 1

print(ctr)

Submission status: Accepted

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

index = 0
count = 0
for x in X:
    for y in X[index+1:]:
        dist = sum([(x[i]-y[i])**2 for i in range(D)])**(1/2)
        if dist == int(dist):
            count += 1
    index += 1

print(count)

Submission status: Accepted

Solution code:
import math

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

count=0

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

print(count)

Submission status: Accepted

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

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 math
n, d = map(int, input().split())
x = []
for _ in range(n):
    x.append(list(map(int, input().split())))

def is_int(x1, x2):
    dist = 0
    for i, j in zip(x1, x2):
        dist += (i-j)**2
    if round(math.sqrt(dist))**2==dist:
        return True
    else:
        return False

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        if is_int(x[i], x[j]):
            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)]
ans=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():
      ans+=1
print(ans)

Submission status: Accepted

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

n_sq = {n*n for n in range(400*100+1)}

def is_gooddist(ta,tb):
	dist_sq = sum((y-z)*(y-z) for y,z in zip(ta,tb))
	return dist_sq in n_sq

def main():
	N,D=map(int,input().split())
	mX=[tuple(map(int,input().split())) for _ in [0,]*N]
	
	res = 0
	for i in range(N-1):
		tI = mX[i]
		for j in range(i+1,N):
			tJ = mX[j]
			res += is_gooddist(tI,tJ)
	print(res)

main()

Submission status: Accepted

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

def f(x,y):
  cal=0
  for i in range(d):
    cal+=abs(x[i]-y[i])**2
  return cal**0.5

for i in range(n-1):
  for j in range(i+1,n):
    if f(a[i],a[j]).is_integer()==True:cnt+=1

print(cnt)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from math import sqrt
N, D = map(int, input().split())
X_list = [input().split() for i in range(N)]
cnt = 0
for x in range(N-1):
    d = 0
    tmp = 0
    for y in range(x+1, N):
        d = 0
        tmp = 0
        while d < D:
            x_d = int(X_list[x][d])
            y_d = int(X_list[y][d])
            tmp += (x_d - y_d) ** 2
            d += 1
        if sqrt(tmp).is_integer():
            cnt += 1

print(cnt)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import itertools
import math


n, dimension = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(n)]
l = list(itertools.combinations(X, 2))
num = len(l)
ans = 0
for i in range(num):
    dist = 0
    for d in range(dimension):
        dist += (l[i][0][d] - l[i][1][d]) ** 2
    dist = math.sqrt(dist)
    if dist.is_integer():
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
from itertools import combinations

N, D = map(int, input().split())
X = [np.array(input().split(), dtype=np.int64) for _ in range(N)]

ans = 0
for x, y in combinations(X, 2):
  d = pow((x-y), 2).sum()
  if (d**0.5).is_integer():
    ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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):
        distance2=0
        for k in range(D):
            distance2+=(X[i][k]-X[j][k])**2
        distance=(distance2)**0.5
        if distance%1==0:
            ans+=1

print(ans)

Submission status: Accepted

Solution code:
import math

n, d = map(int, input().split())
x = [[0] * d for _ in range(n)]
for i in range(n):
    line = input().split()
    for li in enumerate(line):
        x[i][li[0]] = int(line[li[0]])

ans = 0

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

Submission status: Accepted

Solution code:
import numpy as np
n,d=map(int,input().split())
x=[]
ans=0
for _ in range(n):
    *r,=map(int,input().split())
    x.append(r)
x=np.array(x)
for i in range(1,n):
    for j in range(i):
        d=x[i]-x[j]
        d2=d*d
        y=np.sqrt(sum(d2))
        if y.is_integer():
            ans += 1
print(ans)

Submission status: Accepted

Solution code:

import numpy as np
n,d=map(int,input().split())
L=[]
ans=0
for i in range(n):
    A=list(map(int,input().split()))
    L.append(A)
P=np.array(L)
for i in range(n):
    for j in range(i,n):
        if np.linalg.norm(P[i]-P[j])>0 and np.linalg.norm(P[i] - P[j])%1==0:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
import math
n,d = map(int,input().split())
cnt = 0
x = []
for i in range(n):
    a = list(map(int,input().split()))
    x.append(a)
for i in range(n):
    for j in range(i):
        dis = 0
        for k in range(d):
            dis += (x[i][k]-x[j][k])**2
        dis = math.sqrt(dis)
        if dis.is_integer():
            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 i in range(N)]
ans = 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
        dis = sqrt(dis)
        if (dis % 1 == 0): ans += 1
print(ans)

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

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

print(count)

Submission status: Accepted

Solution code:
import math
import itertools
n, d = map(int, input().split())
ary = []
for i in range(n):
	x = list(map(int, input().split()))
	ary.append(x)
c = 0
for j,k in itertools.combinations(ary,2):
	s = 0
	for l in range(d):
		s += (j[l]-k[l])**2
	ss = math.sqrt(s)
	if ss.is_integer():
		c += 1
print (c)

Submission status: Accepted

Solution code:
import numpy as np

N,D = list(map(int,input().split()))
x = [list(map(int,input().split())) for _ in range(N)]
l = np.array(x)

def d(x):
  cnt = 0
  for i in range(len(x)):
    for p2 in l[i+1:]:
      p1 = x[i]
      d = np.linalg.norm(p1-p2)
      if d - int(d) == 0:
        cnt += 1
  return cnt
    
print(d(x))

Submission status: Accepted

Solution code:
import itertools
N,D=map(int,input().split())
X=[list(map(int,input().split())) for i in range(N)]
cmb=list(itertools.combinations(range(N),2))
ans=int(0)
for j in range(len(cmb)):
  xdis=0
  for k in range(D):
    xdis+=(X[cmb[j][0]][k]-X[cmb[j][1]][k])**2
  xdis=xdis**0.5
  if xdis-int(xdis)==0:
    ans+=1 
  else:
    ans+=0
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n,d = get_nums_l()

points = [ list(map(int, s.split(" "))) for s in sys.stdin.readlines() ]

ans = 0
for ai, a in enumerate(points):
    for bi, b in enumerate(points):
        if ai <= bi :
            continue
        diss = 0
        for i in range(d):
            diss +=  (a[i]-b[i]) ** 2
        if math.sqrt(diss) % 1 < 0.00000000001:
            ans += 1

print(ans)

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

# print(X)
d = []

for i in range(N - 1):
    for j in range(i + 1, N):
        d.append((sum((X[j] - X[i]) ** 2)) ** 0.5)
d = np.array(d)
# print(d)
np.mod(d, 1, out=d)
mask = d == 0


# print(mask)
print(np.count_nonzero(mask))

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
 
def dist(A, B):
    sums = 0
    for i in range(len(A)):
        sums += (abs(A[i] - B[i])) ** 2
    sums = sums ** 0.5
    return sums
 
for i in range(N-1):
    for j in range(i+1, N):
#            if isinstance(dist(X[i], X[j]), int):
        if dist(X[i], X[j]).is_integer():
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from math import sqrt
n, d = map(int, input().split())
point = [[int(i) for i in input().split()] for j in range(n)]
count = 0
for i in range(n):
    for j in range(i + 1, n):
        norm = 0
        for pi, pj in zip(point[i], point[j]):
            norm += (pi - pj) ** 2
        if int(sqrt(norm)) == sqrt(norm):
            count += 1

print(count)

Submission status: Accepted

Solution code:
import math

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

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

ans = 0
for i in range(n):
    for j in range(i+1,n):
        d = distance(x[i],x[j])
        if d == int(d):
            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)]


def distance(a, b):
  dist = 0.0
  for i in range(len(a)):
    dist += pow(a[i]-b[i], 2)
  return math.sqrt(dist)

ans = 0
for k in range(N-1):
  for l in range(k+1, N):
    if distance(X[k], X[l]).is_integer():
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
from math import sqrt


import sys
input = sys.stdin.readline


def solve(N, D, X):
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            dist = sqrt(sum((X[i][d] - X[j][d])**2 for d in range(D)))
            if dist == int(dist):
                ans += 1

    return ans


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

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

print(solve(N, D, X))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,d = map(int,input().split( ))
px = [tuple(map(int, input().split( ))) for _ in range(n)]
cnt = 0
for i in range(n):
    for j in range(i):
        sq = 0
        for t in range(d):
            sq += (px[i][t]-px[j][t])**2
        sqsq = int(sq**(1/2))
        if sq == sqsq**2 or sq==(sqsq+1)**2:
            cnt += 1
print(cnt)

Submission status: Accepted

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

res = 0;
rowres = 0
for i in range(0, n):
    for j in range(i+1,n):
        rowres = 0
        for k in range(0, d):
            rowres += (x[i][k] - x[j][k]) ** 2
        if math.sqrt(rowres) - int(math.sqrt(rowres)) == 0:
            res += 1
print(res)

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

print(ans)

Submission status: Accepted

Solution code:
import math

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

count = 0
distance = 0

for i in range(N):
    for j in range(i + 1, N):
        for k in range(D):
            distance += (int(Dists[i][k]) - int(Dists[j][k])) ** 2
        distance = math.sqrt(distance)

        if distance.is_integer():
            count += 1
        distance = 0

print(count)

Submission status: Accepted

Solution code:
import math
a,b = map(int, input().split())
l = [list(map(int,input().split())) for i in range(a)]

cnt = 0
for i in range(a):
  for j in range(i+1,a):
    x = 0
    for k in range(b):
      x += (l[i][k]-l[j][k])**2
    if x**(1/2) - int(x**(1/2)) == 0:
      cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
#133 b
import itertools
n,d=map(int,input().split())
N=[i for i in range(n)]
k=[i*i for i in range(127)]
x=[]
for i in range(n):
    a=list(map(int,input().split()))
    x.append(a)
ans=0
kumi=itertools.combinations(N,2)

for a,b in kumi:
    s=0
    for j in range(d):
        s+=(x[a][j]-x[b][j])**2
    if s in k:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
import itertools
n,d=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
count=0
for i,j in itertools.product(l,l):
  s = sum([abs(i[k]-j[k])**2 for k in range(d)])
  f = s**0.5 - int(s**0.5)==0
  g =s!=0
  if f and g:
    count+=1
print(int(count/2))