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())
pos = [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):
        distance = 0.0
        for k in range(d):
            distance += (pos[i][k] - pos[j][k]) ** 2
        
        distance = math.sqrt(distance)
        if distance.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)]

ANS=0
import math

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

        if DIS==int(DIS):
            ANS+=1

print(ANS)

Submission status: Accepted

Solution code:
import math

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

def is_int(num):
    if total - int(total) == 0: return True
    else: False

ans = 0
for i in range(n):
    for k in range(i, n-1):
        
        total = 0
        if d == 1:
            total += abs(x[i][0])**2
        else:
            for j in range(d):
                total += abs(x[i][j] - x[k+1][j])**2
            total = math.sqrt(total)
        if is_int(total): 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 i in range(N)])

ans = 0
for n in range(N):
    for i in range(n+1, N):
        if np.linalg.norm(X[n]-X[i]).is_integer():
            ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    X = [[int(next(tokens)) for _ in range(D)] for _ in range(N)]  # type: "List[List[int]]"
    solve(N, D, X)

if __name__ == '__main__':
    main()

Submission status: Accepted

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


def norm(a: "List[int]", b: "List[int]"):
    sqrSum = 0
    for i in range(len(a)):
        sqrSum += (a[i]-b[i])**2
    return math.sqrt(sqrSum)


def solve(N: int, D: int, X: "List[List[int]]"):
    count = 0
    for i in range(N):
        for j in range(i+1, N):
            if i == j:
                continue
            diff = norm(X[i], X[j])
            if diff == math.floor(diff):
                count += 1
    print(count)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    X = [[int(next(tokens)) for _ in range(D)]
         for _ in range(N)]  # type: "List[List[int]]"
    solve(N, D, X)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

count=0

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

Submission status: Accepted

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

n=[i for i in range(N)]
comb=itertools.combinations(n,2)
conunter=0

for c in comb:
    XI=X[c[0]]
    XJ=X[c[1]]
    total=0
    for d in range(D):
        total+=(XI[d]-XJ[d])**2
    total=total**0.5
    if(total.is_integer()):
        conunter+=1


print(conunter)

Submission status: Accepted

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

def dist_sq(x,y):
    ret = 0
    for i in range(D):
        ret += (x[i]-y[i])**2
    return ret

SQ,a = set([]),1
while a**2 <= 40**2*D:
    SQ.add(a**2)
    a += 1

ans = 0
for i in range(N):
    for j in range(i+1,N):
        if dist_sq(X[i],X[j]) in SQ:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np


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

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

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
P = [list(map(int, input().split())) for i in range(N)]
ans = 0
for i in range(N):
    for j in range(i):
        d = sum((x - y)**2 for x, y in zip(P[i], P[j]))
        x = int(d**.5)
        if x**2 == 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 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 
        tmp = math.sqrt(tmp)
        if tmp.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)]

ans = 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
        tmp = tmp**(1/2)
        if(tmp == tmp//1):
            ans += 1

print(ans)

Submission status: Accepted

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

cnt = 0
for i in range(n-1):
    for j in range(i+1, n):
        _d = 0
        for k in range(d):
            _d += (xl[i][k] - xl[j][k]) ** 2
        ans = _d ** 0.5
        if int(ans) == ans:
            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)]
cnt = 0
for i in x:
    for j in x:
        ans = 0
        for k in range(d):
            ans += (i[k] - j[k]) ** 2
        if ans != 0 and sqrt(ans) % 1 == 0:
            cnt += 1
print(cnt // 2)

Submission status: Accepted

Solution code:
n,d = map(int,input().split())
L= []
for i in range(n):
    L.append(tuple(map(int,input().split())))
cnt = 0
for i in range(n-1):
    for j in range(i+1,n):
        dis = 0
        for k in range(d):
            dis += (L[i][k] - L[j][k])**2
        dis = dis**0.5
        if dis%1 == 0:
            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)]
c = 0

for i in range(n - 1):
    for j in range(n - 1 - i):
        total = 0
        for k in range(d):
            total = total + (x[i][k] - x[i + j + 1][k])*(x[i][k] - x[i + j + 1][k])
        total = total**0.5
        if total == int(total):
            c = c + 1

print(c)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy

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

for i in range(n):
  for j in range(i+1,n):
    ans = numpy.sqrt(sum([(pair[0]-pair[1])**2 for pair in zip(X[i],X[j])]))
    if ans.is_integer():
      counter += 1
      
print(counter)

Submission status: Accepted

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

def distance(a,b):
    d=0
    for i in range(len(a)):
        d+=abs(a[i]-b[i])**2
    return d
    
def check(a,b):
    f=0
    for i in range(1000):
        if distance(a,b)==i**2:
            f+=1
            break
        else:
            f=f
    if f>0:
        return True
    else:
        return False
            
    
for i in range(n):
    for j in range(i+1,n):
        if check(x[i],x[j]):
            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
def check(i, j):
  d2 = 0
  for k in range(d):
    d2 += (x[i][k] - x[j][k]) ** 2
  for j in range(d2 + 1):
    if j ** 2 > d2:
      return False
    if j ** 2 == d2:
      return True
  return False

for i in range(n):
  for j in range(i + 1, n):
    if check(i, j):
      ans += 1

print(ans)

Submission status: Accepted

Solution code:
import itertools

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

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

res = list(itertools.combinations(X,2))

cnt = 0

for i in itertools.combinations(X,2):
    #tmp = zip(i[0],i[1])
    tmp = 0
    for j in zip(i[0],i[1]):
        tmp += pow(j[0]-j[1],2)
    ans = tmp ** 0.5
    if ans.is_integer():
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math
n, d = map(int, input().split())
x_list = [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 math.sqrt(sum([(y - z) ** 2 for y, z in zip(x_list[i], x_list[j])])).is_integer():
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
n,d = map(int,input().split())
l = list (list(map(int,input().split())) for i in range(n))
#print(l)
count = 0
q = 0
for i in range(n):
  a = l[i]
  for t in range(n):
    b = l[t]
    for c in range(d):
      q += (a[c]-b[c])**2
    if int(q**0.5)**2==q:
      count += 1
    q =0
print(int((count-n)/2))

Submission status: Accepted

Solution code:
def LI(): return list(map(int,input().split()))
N,D = LI()
X = [LI() for _ in range(N)]
ans = 0
for i in range(N):
    for j in range(i+1,N):
        temp = 0
        for k in range(D):
            temp += (X[j][k]-X[i][k])**2
        if temp **0.5%1==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)]
count = 0
for i in range(n):
    for k in range(n):
        sum = 0
        if i == k:
            continue
        for j in range(d):
            sum += (x[i][j]-x[k][j])**2
        if math.sqrt(sum) % 1 == 0:
            count += 1
print(count//2)

Submission status: Accepted

Solution code:
import numpy as np
from scipy.spatial import distance

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

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

vector = np.array(l)

distMatrix = distance.cdist(vector, vector, metric="euclidean")

#print(distMatrix)

ans = 0
for i in range(N-1):
    #print(*distMatrix[i][i+1:])
    #print([x.is_integer() for x in distMatrix[i][i+1:]])
    ans += [x.is_integer() for x in distMatrix[i][i+1:]].count(True)
    #float.is_integer()
    
print(ans)

Submission status: Accepted

Solution code:
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np
# import scipy as scp

# 入力の受け取り
n,d = map(int,input().split())
arr = np.array([])
for _ in range(n):
    arr = np.append(arr,np.array(input().split(),dtype=np.int64))

arr = arr.reshape(n,-1)

ans = 0
for i in range(n):
    for j in range(i+1,n):
        num = np.sqrt(sum((arr[i] - arr[j])**2))
        if num % 1 == 0:
            ans +=1
        else:
            continue

print(ans)
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する

Submission status: Accepted

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

ans=0
for i in range(n-1):
    for j in range(i+1,n):
        cnt=0
        for k in range(d):
            cnt+=(X[i][k]-X[j][k])**2
        cnt=math.sqrt(cnt)
        if int(cnt)==cnt:
            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)]
cnt = 0
for i in range(N-1):
    for j in range(i+1,N):
        distance = 0
        for d in range(D):
            distance += (X[i][d]-X[j][d])**2
        distance = math.sqrt(distance)
        if(distance == int(distance)):
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import math
n,d = map(int,input().split())
grid = [list(map(int,input().split())) for i in range(n)]
dis = 0
count = 0
che = 0
for i in range(n):
    for j in range(i+1,n):
        for k in range(d):
            dis +=(grid[i][k]-grid[j][k])**2
        che = int(math.sqrt(dis))
        if che ** 2 == dis:
            count+=1
        dis = 0
print(count)

Submission status: Accepted

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

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

ans = 0
for j in range(n):
    for k in range(1,n-j):
        tmp = 0
        for l in range(d):
            tmp += abs(x_list[j][l]-x_list[j+k][l])**2
        tmp = tmp**0.5

        if tmp.is_integer() == True:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math
n,d = map(int,raw_input().split())
l = []
ctr = 0
for ii in xrange(n):
    l.append(map(int,raw_input().split()))

for i in xrange(n):
    for j in xrange(i+1,n):
        
        res = 0
        for k in xrange(d):
            # print l[i][k] , l[j][k]
            res += (l[i][k] - l[j][k])**2
        if str(math.sqrt(res))[-2:] == ".0":
            ctr += 1
        # print str(math.sqrt(res))
print ctr

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math
def is_int_distance_yz(y, z):
    dist = 0
    for (yi, zi) in zip(y, z):
        dist += (yi - zi)**2
    dist_sqrt = int(math.sqrt(dist))
    return dist == dist_sqrt**2

def solve(N: int, D: int, X: "List[List[int]]"):
    ans = 0
    for i in range(N-1):
        for j in range(i+1, N):
            if is_int_distance_yz(y=X[i], z=X[j]):
                ans += 1
    print(ans)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    X = [[int(next(tokens)) for _ in range(D)] for _ in range(N)]  # type: "List[List[int]]"
    solve(N, D, X)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

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

N, D = lr()
X = np.array([lr() for _ in range(N)])
answer = 0
for i in range(N-1):
    for j in range(i+1, N):
        a = (((X[i] - X[j]) ** 2).sum()) **.5
        if is_integer_num(a):
            answer += 1

print(answer)

Submission status: Accepted

Solution code:
n,d = list(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):
        z = 0
        for k in range(d):
            z += (x[i][k] - x[j][k])**2
        if z**0.5 == (z**0.5)//1:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
mod = 10**9 + 7 
sys.setrecursionlimit(1000010)

def isOK(x1,x2):
    sq = 0 
    for i in range(D):
        sq = sq + (x1[i]-x2[i])**2
    sq2 = int(math.sqrt(sq)+0.5)
    if sq == sq2 ** 2:
        return True
    else:
        return False

N,D= nm()

X = [] 
for i in range(N):
    x  = nl()
    X. append(x)
ans =0
for i in range(N-1):
    for j in range(i+1,N):
        if isOK(X[i],X[j]):
            ans = ans + 1
print(ans)

Submission status: Accepted

Solution code:
f=lambda:map(int,input().split())
n,d=f();x=[list(f()) for _ in range(n)]
print(sum(sum((s-t)**2 for s,t in zip(x[i],x[j]))**.5%1==0 for j in range(n) for i in range(j)))

Submission status: Accepted

Solution code:
f=lambda:map(int,input().split())
n,d=f();x=[list(f()) for _ in range(n)]
print(sum(sum((x[i][k]-x[j][k])**2 for k in range(d))**.5%1==0 for j in range(n) for i in range(j)))

Submission status: Accepted

Solution code:
f=lambda:map(int,input().split())
n,d=f()
ll=[list(f()) for _ in range(n)]
a=0
for j in range(n):
  for i in range(j):
    a+=sum((ll[i][k]-ll[j][k])**2 for k in range(d))**.5%1==0
print(a)

Submission status: Accepted

Solution code:
# B
n,d = map(int, input().split())
xi = [list(map(int, input().split())) for i in range(n)]
heihou = [i*i for i in range(200)]
count=0
for i in range(n-1):
    for j in range(i+1, n):
        total = 0
        for k in range(d):
            h = xi[i][k] - xi[j][k]
            hpow = h*h
            total+=hpow
        if total in heihou:
            count+=1
print(count)

Submission status: Accepted

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

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

cnt=0
for p1,p2 in combinations(range(1,N+1), 2):
    sum=0
    for i in range(D):
        sum += ( X_list[p1-1][i] - X_list[p2-1][i] )**2
    
    dist = sum**(1/2)
    if dist % 1 == 0:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
N , D = (map(int , input().split()))
sc = [list(map(int, input().split())) for i in range(N)]
a_list = []
for i in range(len(sc)):
    for j in range(i+1,len(sc)):
        t = 0
        for k in range(D):
            t += ((sc[i][k] - sc[j][k])**2)
        a_list.append(t)
ans = 0
for i in a_list:
    for j in range(i+1):
        if j**2 == i:
            ans += 1
            break
print(ans)

Submission status: Accepted

Solution code:
def solve():
    N, M = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(N)]
    c = 0
    for i in range(N):
        for j in range(i+1, N):
            tmp = 0
            for k in range(M):
                tmp += (A[i][k] - A[j][k]) ** 2
            if tmp % (tmp ** 0.5) == 0:
                c += 1
    return c

print(solve())

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(0, N - 1):
    for j in range(i + 1, N):
        dist = 0
        f = 0
        for d in range(D):
            dist += (X[i][d] - X[j][d])**2
        root = int(math.sqrt(dist))
        for r in range(root-2, root+3):
            if r**2 == dist:
                f = 1
        if f == 1:
            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
import itertools
import math
com=itertools.combinations([i for i in range(n)],2)
for p,q in com:
    s=0
    for k in range(d):
        s+=(x[p][k]-x[q][k])**2
    if math.ceil(s**0.5)==s**0.5:
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
#=============================================================================
# ABC133 B
#=============================================================================
import itertools
import math
N,D=map(int,input().split())
id=[i for i in range(N)]
point=[list(map(int,input().split())) for _ in range(N)]
comb=itertools.combinations(id,2)
cnt=0
for p,q in comb:
    Squ=0
    for k in range(D):
        Squ+=(point[p][k]-point[q][k])**2
    if math.ceil(Squ**0.5)==Squ**0.5:
        cnt+=1
print(cnt)

Submission status: Accepted

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

def dis(y, z):
    return (sum([(y[i] - z[i]) ** 2 for i in range(d)]) ** .5).is_integer()

l = [[int(i) for i in input().split()] for _ in range(n)]

c = 0
for p in range(n - 1):
    for q in range(p + 1, n):
        c += dis(l[p], l[q])
print(c)

Submission status: Accepted

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




def dst(i, j):
    a = pnt[i]
    b = pnt[j]
    ret = 0
    for p, q in zip(a, b):
        ret += (p - q) ** 2
    r = ((ret ** (0.5)))

    return r


ans = 0
for i in range(n):
    for j in range(i + 1, n):
        tmp = dst(i, j)
        if tmp == int(tmp):
            ans = ans + 1 

print(ans)

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
p = []
cnt = 0
for j in range(n):
    for k in range(n):
        if j != k:
            wa = 0
            for t in range(d):
                wa += (l[j][t] - l[k][t]) ** 2
                #print(wa)
            if wa ** (1 / 2) % 1 == 0:
                cnt += 1
                
print(int(cnt / 2))

Submission status: Accepted

Solution code:
import itertools

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

cnt=0
for x,y in itertools.combinations(c,2):
    t=0
    for i in range(d):
        t+=(l[x][i]-l[y][i])**2
    if (t**0.5).is_integer()==True:
        cnt+=1
print(cnt)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n-1):
    for j in range(i+1, n):
        count += (sum((a-b)**2 for a,b in zip(x_list[i], x_list[j]))**0.5).is_integer()
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)]
count = 0
for i in range(N-1):
    for j in range(i+1, N):
        squared_sub = [pow(X_i - X_j, 2) for (X_i, X_j) in zip(X[i], X[j])]
        distance = math.sqrt(sum(squared_sub))
        if distance == int(distance):
            count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

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

for i in range(len(x_list)-1):
    for j in range(i+1, len(x_list)):
        cal = 0
        for k in range(d):
            cal += (x_list[i][k] - x_list[j][k])**2
        if math.sqrt(cal) == int(math.sqrt(cal)):
            count += 1

print(count)

Submission status: Accepted

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

cnt=0
for i in range(n):
  for j in range(n):
    if i==j:continue
    k=(sum((x[i]-x[j])**2))**.5
    if int(k)-k==0:
      cnt+=1
print(cnt//2)

Submission status: Accepted

Solution code:
import itertools as ite


def dist_cal(point_i, point_j):
    total = 0
    for i, j in zip(point_i, point_j):
        total += (i-j)**2
    return total ** (1/2)


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

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

cmb = list(ite.combinations(x, 2))

cnt = 0
for i, j in cmb:
    dist = dist_cal(i, j)

    if dist == int(dist):
        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-1):
  for j in range(i+1,N):
    dis = 0
    for d in range(D):
      dis += (X[j][d]-X[i][d])**2
    if math.sqrt(dis)%1 == 0:
      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 - 1):
    for j in range(i + 1, N):
        total = 0
        for (y, z) in zip(x[i], x[j]):
            total += abs(y - z) ** 2
        dist = math.sqrt(total)
        if dist.is_integer():
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math

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

cnt = 0
for i in range(N-1):
  for j in range(i+1, N):
    A = X[i]
    B = X[j]
    AB = 0.0
    for a, b in zip(A, B):
      AB += (b - a)**2
    AB = math.sqrt(AB)
    if AB.is_integer():
      cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
from itertools import combinations as comb


def main():
    n, d = map(int, input().split())
    xs = [list(map(int, input().split())) for _ in range(n)]
    xs_combs = list(comb(xs, 2))
    ans = 0
    for xs_comb in xs_combs:
        xs_comb = np.array(xs_comb)
        dist = np.linalg.norm(xs_comb[0]-xs_comb[1])
        if int(dist) == dist:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

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
tmp = 0
s = 1.5
for i in range(N):
    for k in range(N):
        if i == k:
            continue
        else:
            for j in range(D):
                tmp += (X[i][j] - X[k][j]) ** 2
                s = math.sqrt(tmp)
        if s % 1 == 0:
            ans += 1
        s = 0
        tmp = 0
print(ans//2)