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 sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,d=mp()
l=[]
for i in range(n):
    l.append(lmp())
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        a=0
        for k in range(d):
            a+=(l[i][k]-l[j][k])**2
        if (a ** .5).is_integer():
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
import math

N,D = map(int,input().split())
x = []
count = 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):
        Distance = 0
        for k in range(D):
            Distance += (x[i][k] - x[j][k])**2
        
        if math.sqrt(Distance) == int(math.sqrt(Distance)):
            count += 1
            
print(count)

Submission status: Accepted

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

def distance(x,y):
  num=0
  for i in range(d):
    num=num+(x[i]-y[i])*(x[i]-y[i])
  return num

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

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

Submission status: Accepted

Solution code:
import math
def distance(x, y):
    b = 0
    for k in range(d):
        b += (x[k] - y[k]) ** 2
    return float(math.sqrt(b))

n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
a = 0
for j in range(n - 1):
    for i in range(j + 1):
        if distance(x[i], x[j + 1]) == math.floor(distance(x[i], x[j + 1])):
            a += 1
print(int(a))

Submission status: Accepted

Solution code:
import itertools
n, d = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for a, b in itertools.combinations(X, r=2):
    s = (sum(map(lambda x, y: (x - y)**2, a, b)))**0.5
    if s.is_integer():
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
#B - Good Distance
import math
N,D = map(int,input().split())
X = []
for _ in range(N):
    Xi = list(map(int,input().split()))
    X.append(Xi)
count = 0
for i in range(N):
    for k in range(i+1,N):
        D_sqrt = 0
        for j in range(D):
            D_sqrt += (X[i][j] - X[k][j])**2
        D_ans = math.sqrt(D_sqrt)
        if D_ans.is_integer():#float型が整数か判定するメソッド
            count += 1
print(count)

Submission status: Accepted

Solution code:
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()
import math

def resolve():
    import sys
    input = sys.stdin.readline
    n, d = [int(x) for x in input().rstrip().split(" ")]

    ans = 0
    points = []

    for i in range(n):
        current = [int(x) for x in input().rstrip().split(" ")]
        for point in points:
            dist = math.sqrt(sum([(a - b)**2 for a, b in zip(point, current)]))
            if dist.is_integer():
                ans += 1
        points.append(current)

    print(ans)



if __name__ == "__main__":
    resolve()

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)

c=0
D2=[]
for i in range(n-1):
    for j in range(i+1,n):
        d2=0.0
        for k in range(d):
            d2 += (X[i][k]-X[j][k])**2
        D2.append(d2**0.5)
        if (d2**0.5)%1==0 :
            c+=1
print(c)

Submission status: Accepted

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

for i in range(N - 1):
    for j in range(i+1, N):
        dist_squared, dist = 0, 0
        for y, z in zip(X_ls[i], X_ls[j]):
            dist_squared += (y - z) ** 2
        dist = math.sqrt(dist_squared)
        if dist - math.floor(dist) == 0:
            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):
    for j in range(i+1,n):
        t = 0
        for k in range(d):
            t += (x[i][k] - x[j][k]) ** 2
        if float.is_integer(sqrt(t)):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math
N,D = map(int,input().split())
X = []
c = 0
s = 0
for i in range(N):
    X.append(list(map(int,input().split()))) 
for l in range(N):
    # print(str(l) + "l")
    if l == N - 1:
        break
    for i in range(l+1,N):
        for j in range(D):
            s += abs(X[l][j] - X[i][j]) ** 2
        s = math.sqrt(s)
        if s % 1 == 0:
            c += 1
        # print(str(i) + "i")
        s = 0

print(c)

Submission status: Accepted

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]
import math

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import sqrt


def dist(l, m):
    temp = 0
    for i in range(len(l)):
        temp += (l[i] - m[i]) ** 2
    return sqrt(temp).is_integer()


n, d = list(map(int, input().split()))
res = 0
l = []
for _ in range(n):
    l.append(list(map(int, input().split())))
for i in range(n - 1):
    for j in range(i + 1, n):
        res += dist(l[i], l[j])
print(res)

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

Submission status: Accepted

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

Submission status: Accepted

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

for _ in range(n):
  x = list(map(int, input().split()))
  l.append(x)
    
for i in range(n-1):
  for j in range(i+1,n):
    k = 0
    for a,b in zip(l[i], l[j]):
      k += (a-b)**2
    if (k**0.5).is_integer():
      count += 1

print(count)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

def is_square_num(n):
  i2 = 0
  for i in range(0, n + 1):
    if i2 == n:
      return True
    if i2 > n:
      return False
    i2 += i * 2 + 1

c = 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 is_square_num(dist):
            c += 1

print(c)

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):
        dis=0
        for k in range(d):
            dis+=(x[i][k]-x[j][k])**2
            
        if math.sqrt(dis)==int(math.sqrt(dis)):
            cnt+=1
        
print(cnt)

Submission status: Accepted

Solution code:
def distance(a_lst, b_lst):
    n = len(a_lst)
    tmp_distance = 0

    for i in range(n):
        a = a_lst[i]
        b = b_lst[i]

        tmp_distance += (a - b) ** 2

    distance = (tmp_distance) ** (1/2)
    return distance


def main():
    n, d = map(int, input().split())
    x_lst = [0] * n
    count = 0

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

    for i in range(n-1):
        a_lst = x_lst[i]

        for j in range(i+1, n):
            b_lst = x_lst[j]

            if distance(a_lst, b_lst) == int(distance(a_lst, b_lst)):
                count += 1

    print(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
z=[]
for i in range(N):
    x=list(map(int,input().split()))
    z.append(x)
def judge_dis(K,L):
    d=0
    for k,l in zip(K,L):
        d+=(k-l)**2
    import math
    d=math.sqrt(d)
    return d.is_integer()
ans=0
for x in range(N-1):
    for i in range(x+1,N):
        if judge_dis(z[x],z[i]):
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
import math
n,m=map(int,input().split())
data = []
ans = 0
for i in range(n):data.append(list(map(int,input().split())))

for i in range(n):
  for j in range(n):
    if(i>=j):continue
    t = 0
    for k in range(m):
      
      t += (data[i][k] - data[j][k])**2
    
    res = math.sqrt(t)
    if(res == int(res)):ans+=1
print(ans)

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
X = [tuple(map(int, input().split())) for _ in range(N)]
r = 0
for p in X:
    for q in X:
        if p != q:
            d = sum([(x-y)**2 for x, y in zip(p, q)])**(0.5)
            if int(d) == d:
                r += 1
print(r//2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, d = inintm()

X = []
ans = 0

for _ in range(n):
    x = inintl()
    X.append(x)


for i in range(n):
    Xi = X[i]
    for j in range(i+1, n):
        Xj = X[j]
        z = 0
        for k in range(d):
            z += (Xi[k] - Xj[k])**2
        if z**0.5 == int(z**0.5):
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import itertools

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

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

cnt = 0
for c in itertools.combinations(range(n), 2):
    sum = 0
    for i in range(d):
        sum += (x[c[0]][i] - x[c[1]][i])**2
    dist = sum**0.5

    if dist.is_integer():
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math
N, D = map(int, input().split(' '))
X_ls = []
cnt = 0

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

for i in range(N - 1):
    for j in range(i+1, N):
        dist_squared, dist = 0, 0
        for y, z in zip(X_ls[i], X_ls[j]):
            dist_squared += (y - z) ** 2
        dist = math.sqrt(dist_squared)
        if dist - math.floor(dist) == 0:
            cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import itertools

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

def get_distance(p1, p2):
    d2 = 0
    for i in range(D):
        d2 += (p1[i] - p2[i])**2
    return math.sqrt(d2)

count = 0
for i, j in itertools.combinations(range(N), 2):
    if get_distance(X[i], X[j]).is_integer():
        count += 1

print(count)

Submission status: Accepted

Solution code:
from itertools import combinations
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
data = [0]*16002
i = 1
while i**2<=16001:
    data[i**2]=1
    i += 1
res = 0
for a, b in combinations(X,2):
    temp = 0
    for x, y in zip(a, b):
        temp += (x-y)**2
    if data[temp]:
        res += 1
print(res)

Submission status: Accepted

Solution code:
# ABC_123_B_Good_Distance.py
from math import sqrt

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

ct = 0
# ans=[]
# dis=[]
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
        # dis.append((i,j,sum))
        if int(sqrt(sum))**2 == sum:
            ct += 1
            # ans.append((i,j))
print(ct)
# print(dis)
# print(ans)

Submission status: Accepted

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

def f(list_1, list_2):
    len_ = len(list_1)
    sum_ = 0
    for i in range(len_):
        sum_ += ( list_1[i] - list_2[i] ) ** 2
    return sum_

count = 0
for i in range(n):
    for j in range(i):
        if i == j:
            continue
        # print("j_i", j, i)
        if f(data[i], data[j])**0.5 % 1 == 0.0:
            count += 1

print(count)

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

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

Submission status: Accepted

Solution code:
import math

def is_int(n):
  return True if int(n) == n else False

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

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

cnt = 0

for j in range(N):
  for k in range(j):
    if is_int(dist(X[j], X[k])):
      cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

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

Submission status: Accepted

Solution code:
# 少しめんどくさい方法です。
import itertools
n, d = map(int, input().split())
x = []
s = []  # 組み合わせ用の変数。
for i in range(n):
    s.append(i)
    a = list(map(int, input().split()))
    x.append(a)
# 単純に組み合わせで判定する。
ans = 0
for v in itertools.combinations(s, 2):
    t = 0
    # 距離を判定する。
    for i in range(d):
        t += (x[v[0]][i] - x[v[1]][i])**2
    # 少数かどうか？
    if (t**0.5).is_integer():
        ans += 1
print(ans)

Submission status: Accepted

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

ans = 0
for v in itertools.combinations(s, 2):
    t = 0
    for i in range(d):
        t += (x[v[0]][i] - x[v[1]][i])**2
    if (t**0.5).is_integer():
        ans += 1
print(ans)

Submission status: Accepted

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

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

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

        for k in range(1000):
            if dist == k**2:
                ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

count = 0
for i in range(N):
    for j in range(i+1,N):
        if float.is_integer(np.linalg.norm(x[i][:]-x[j][:], ord=2)):
            count += 1
print(count)

Submission status: Accepted

Solution code:
import math
N,D = map(int,input().split())
counter = 0
X = []
for i in range(N):
    ls = list(map(int,input().split()))
    X.append(ls)
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
        for l in range(1,int(math.sqrt(dist))+1):
            if l**2 == dist:
                counter += 1
print(counter)

Submission status: Accepted

Solution code:
inp=list(map(int,input().split()))
n=inp[0]
arr=[]
for i in range(n):
  inp=list(map(int,input().split()))
  arr.append(inp)
ans=0
for i in range(len(arr)):
  for j in range(i+1,len(arr)):
    x=0
    for k in range(len(arr[0])):
      x+=(arr[i][k]-arr[j][k])**2
    z=int(pow(x,0.5))
    if z**2==x:
      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)]

res = 0

for i in range(N - 1):
    for j in range(i + 1, N):
        t = 0
        for d in range(D):
            t += (X[i][d] - X[j][d]) ** 2

        tt = math.sqrt(t)
        if tt.is_integer():
            res += 1

print(res)

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())))
count=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 math.sqrt(distance)==int(math.sqrt(distance)):
            count+=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import numpy as np
N,D = map(int,input().split())
X = np.array([list(map(int,input().split())) for n in range(N)])
ans = 0

for n in range(N):
  for m in range(N):
    d = 0
    for x,y in zip(X[n],X[m]):
      d += (x-y)**2
    if math.sqrt(d).is_integer() and d != 0:
      ans+=1
        
print(ans//2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
x = 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):
    sq_dis = 0
    
    for k in range(d):
      sq_dis += (x[i][k] - x[j][k])**2
      
    dis = sq_dis ** 0.5

    if dis.is_integer() == True:
      cnt += 1
        
print(cnt)

Submission status: Accepted

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



ans = 0
a = 0

for i in range(N):
    for j in range(N):
        if i != j:
            for k in range(D):
                a += (int(X[i][k]) - int(X[j][k])) ** 2
            a = math.sqrt(a)
            if int(a) == a:
                ans += 1            
            a  = 0
print(ans // 2)

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

for i in range(n):
  for j in range(i+1,n):
    for k in range(d):
      distance+=(x[i][k]-x[j][k])**2
    if math.sqrt(distance).is_integer():
      ans+=1
    distance=0
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)]
res = 0
for i in range(n):
  for j in range(i+1, n):
    cal = 0
    for k in range(d):
      dis = (x[i][k] - x[j][k]) ** 2
      cal += dis
    if math.sqrt(cal)%1==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)]
ret = 0
for i in range(n-1):
    for j in range(i+1, n):
        meu = 0
        for y, z in zip(x[i], x[j]):
            meu += (y-z)**2
        if (meu**0.5).is_integer():
            ret += 1
print(ret)

Submission status: Accepted

Solution code:
import numpy as np

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):
        dist = 0
        for k in range(D):
            dist += abs(X[i][k] - X[j][k])**2
        dist = np.sqrt(dist)
        if dist % 1 == 0:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools
import math
n,d = map(int,input().split())
xl = []
for _ in range(n):
    x = list(map(int,input().split()))
    xl.append(x)

cnt = 0
for v in itertools.combinations(xl,2):
    x, y = v[0], v[1]
    sum = 0
    for i in range(d):
        sum += (x[i]-y[i])**2
    dist = math.sqrt(sum)
    if dist.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())))

count = 0
for i in range(n):
    for j in range(i+1, n):
        s = 0
        for k in range(d):
            diff = x[i][k]-x[j][k]
            s += diff * diff
        sq = math.sqrt(s) 
        if sq == int(sq):
            count += 1
print(count)

Submission status: Accepted

Solution code:
import math
n,m = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(n)]
cnt,tmp = 0,0
for i in range(n-1):
	for j in range(i+1,n):
		tmp = 0
		for M in range(m):
			tmp += (x[i][M] - x[j][M])**2
			#print(tmp)
		if math.sqrt(tmp).is_integer():
			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)]
cnt = 0
for i in range(N):
    for j in range(i+1,N):
        num = 0
        for k in range(D):
            num += (X[i][k]-X[j][k])**2
        if math.sqrt(num) == int(math.sqrt(num)):
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n,d=map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
squares=[i*i for i in range(200)]
cnt=0
for i in range(n):
  for j in range(i+1,n):
    distance=0
    for k in range(d):
      distance+=(a[i][k]-a[j][k])**2
    if distance in squares:
      cnt+=1
print(cnt)

Submission status: Accepted

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

counter = 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
        distance = math.sqrt(distance)
        if distance == int(distance):
            counter += 1
print(counter)

Submission status: Accepted

Solution code:
import numpy
from itertools import combinations
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
c = 0
for x, y in combinations(X, 2):
  s = sum(p**2 for p in numpy.array(x)-numpy.array(y))**.5
  if s.is_integer():
    c += 1
print(c)

Submission status: Accepted

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

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

for i in range(n):
    for j in range(i+1,n):
        sum = 0
        for v1, v2 in zip(a[i], a[j]):
            sum += (v1-v2)**2
        sum**=0.5
        #print(sum)
        if sum == int(sum):
            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):
    a=0
    for k in range(D):
      a+=(X[i][k]-X[j][k])**2
    if math.sqrt(a).is_integer():
      count+=1
print(count)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
li=[list(map(int, input().split())) for _ in range(n)]
res=0
import math
for i in range(n):
    for j in range(i+1,n):
        dis2=0
        for k in range(d):
          dis2+=(li[i][k]-li[j][k])**2
        dis=dis2**(1/2)
        if dis%1==0:res+=1
print(res)

Submission status: Accepted

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

for i in range(n):
    for j in range(i+1, n):
        a = 0
        for k in range(d):
            a += pow(x[i][k]- x[j][k], 2)
            
        a = math.sqrt(a)
        b = int(a)
        if a == b:
            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)]
count = 0
for i in range(N-1):
  for j in range(i+1,N):
    x = 0
    for k in range(D):
      x += abs(P[i][k] - P[j][k])**2
    ans = x**(1/2)
    if ans.is_integer():
      count += 1
print(count)

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
P = [list(map(int, input().split())) for _ in range(N)]
sq = set(i**2 for i in range(200))
ans = 0
for i, p in enumerate(P[:-1]):
  for q in P[i+1:]:
    d_sq = 0
    for x, y in zip(p, q):
      d_sq += (x-y)**2
    if d_sq in sq:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
x_l = [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_l[j][k] - x_l[i][k]) ** 2
        if tmp**0.5%1 == 0:
            ans += 1

print(ans)