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:
from math import sqrt
from itertools import combinations
N, D = map(int, input().split())
X = [[] for _ in range(N)]
for i in range(N):
    X[i] = list(map(int, input().split()))

def dist(p1, p2):
    ret = 0
    for a,b in zip(p1, p2):
        ret += abs(a-b)**2
    ret = sqrt(ret)
    return ret-int(ret)==0
ans = 0
for i,j in combinations(list(range(N)), 2):
    ans += dist(X[i], X[j])
print(ans)

Submission status: Accepted

Solution code:

import numpy as np


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


N,D=acinput()
X=[]
for i in range(N):
        X.append(np.array(acinput()))


count=0
for i in range(N-1):
        for j in range(i+1,N):
                tmp=np.linalg.norm(X[i]-X[j])
                if tmp%1.0==0:
                        count+=1


print(count)

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

def diff(A,B,D):
    y = []
    for l in range(D):
        y.append((A[l] - B[l])**2)
    return math.sqrt(sum(y))

count = 0
for i in range(N):
    for j in range(i+1,N):
        y = diff(X[i], X[j], D)
        if y % 1 == 0:
            count += 1
print(count)

Submission status: Accepted

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

for i in range(n):
    points.append(tuple(map(int, input().split())))

for i in range(n):
    for j in range(i+1, n):
        dist = 0
        for k in range(d):
            dist += pow(points[i][k]-points[j][k], 2)
        dist = pow(dist, 1/2)
        if dist.is_integer():
            ints += 1

print(ints)

Submission status: Accepted

Solution code:
n,m = (int(i) for i in input().split())  
d = [[int(i) for i in input().split()] for i in range(n)] 
count = 0
for i,v in enumerate(d):
  for j in range(i+1,len(d)):
    sum = 0
    # print(d[i],d[j])
    for k in range(len(v)):
      sum += abs(d[i][k] - d[j][k])**2
    if pow(sum,1/2).is_integer():
      count += 1

print(count)

Submission status: Accepted

Solution code:
import math
import numpy as np

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


cnt = 0
for i in range(N):
    for j in range(i):
        diff2 = ((xss[i] - xss[j])**2).sum()
        d = int(np.sqrt(diff2))
        if d * d == diff2: 
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
from math import sqrt
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):
    tmp=0
    for yi, zi in zip(x[i], x[j]):
      tmp+=(yi-zi)**2
    tmp=sqrt(tmp)
    if tmp==int(tmp):
      cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
import math

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

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

cnt = 0
tmp = 0

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

print(cnt)

Submission status: Accepted

Solution code:
n,d = [int(i) for i in input().split()]
a=[]
ctr=0
for i in range(n):
  c= [int(i) for i in input().split()]
  a.append(c)
#print(a)
for i in range(n-1):
  for j in range(i+1,n):
    ans=0
    for k in range(d):
     # print(i,j,d)
      ans+=pow(a[i][k]-a[j][k],2)
    ans = pow(ans,0.5)
    if(ans - int(ans) < 0.000001):ctr+=1
print(ctr)

Submission status: Accepted

Solution code:
import math

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

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

ans = 0

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

Submission status: Accepted

Solution code:
import math
N,D = map(int, input().split())
n=N
e = [[int(i) for i in input().split()] for i in range(n)]
Num=0
for x in range(0,N):
    for y in range(x+1,N):
        S=0
        for z in range(0,D):
            S=S+(e[x][z]-e[y][z])**2
        A=math.sqrt(S)
        if A%1==0:
            Num=Num+1


print(Num)

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):
		t=0
		for l in range(d):
			t+=(x[i][l]-x[j][l])**2
		if t**(1/2)%1==0:
			ans+=1
print(ans)

Submission status: Accepted

Solution code:
#B
def dist(x1, tmpx):
    d2 = 0
    for k in range(len(x1)):
        d2 += (x1[k] - tmpx[k])**2
    d = d2 ** (1/2)
    return d

n,d = map(int, input().split())
x1 = []
x1.append(list(map(int,input().split())))
cnt = 0
for i in range(1,n):
    tmpx = list(map(int,input().split()))
    for j in range(0,i):
        d = dist(x1[j],tmpx)
        if d == int(d):
            cnt += 1
    x1.append(tmpx)
print(cnt)

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
X = [list(map(int, input().split())) 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

cnt = 0
import itertools
for i in itertools.combinations(range(N), 2):
  dist = 0
  for j in range(D):
    dist += (X[i[0]][j] - X[i[1]][j]) ** 2
  if is_integer_num(dist ** (1/2)):
    cnt += 1
print(cnt)

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
n, D = map(int, input().split())
X = [[int(i) for i in input().split()] for i in range(n)]

def isqrt(n):
    x = n
    y = (x + 1) // 2
    while y < x:
        x = y
        y = (x + n // x) // 2
    return x

cnt = 0
for i in range(n):
    for j in range(i+1, n):
        sum_ = 0
        for d in range(D):
            sum_ += pow((X[i][d] - X[j][d]), 2)
        a = isqrt(sum_)
        if a * a == sum_:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import math
N, D = map(int, input().split())
Spot = [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 += (Spot[i][k] - Spot[j][k])**2
        if math.sqrt(distance).is_integer():
            cnt += 1
print(cnt)

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 i in range(N-1):
    x = (X[i] - X[i+1:]) ** 2
    total = np.sum(x, axis=1) ** 0.5

    for t in total:
        if t.is_integer():
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math

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

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

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

print(ans)

Submission status: Accepted

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

def main():
    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 += (x[i][k] - x[j][k])** 2
            if (tmp ** 0.5).is_integer():
                ans += 1
    print(ans)

if __name__ == "__main__":
    main()

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

xs = []

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

xs = np.array(xs)

count = 0

for i, xi in enumerate(xs):
    for j in range(i+1, N):
        # print("i=" + str(i))
        # print("j=" + str(j))
        xj = xs[j]
        tmp = xi - xj
        tmp2 = tmp ** 2
        d = np.sqrt(np.sum(tmp2))
        if d - int(d) == 0:
            count += 1

print(count)

Submission status: Accepted

Solution code:
from math import sqrt
N, D = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for s1 in S:
    for s2 in S:
        c = 0
        for x1, x2 in zip(s1, s2):
            c += (x1-x2)**2
        if int(sqrt(c))**2 == c:
            ans += 1
print((ans-N)//2)

Submission status: Accepted

Solution code:
import math


def is_distance_int(D, y, z):
    sum_diff_squre = 0
    for i in range(D):
        sum_diff_squre += (y[i] - z[i]) * (y[i] - z[i])
    distance = int(math.sqrt(sum_diff_squre))

    if distance * distance == sum_diff_squre:
        return True
    else:
        return False


if __name__ == '__main__':
    N, D = map(int, input().split())
    X = [list(map(int, input().split())) for _ in range(N)]

    answer = 0
    for i in range(N):
        for j in range(0, i):
            # print(str(i+1) + ',' + str(j+1))
            if is_distance_int(D, X[i], X[j]):
                answer += 1

    print(answer)

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

Submission status: Accepted

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

N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
for j in range(N):
    for i in range(j):
        dist = 0
        for d in range(D):
            dist += (X[i][d] - X[j][d]) ** 2
        if math.sqrt(dist) % 1 == 0:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import math
N, D = map(int, input().split())
X = [[int(_) for _ in input().split()] for _ in range(N)]
ans = 0
for i in range(N - 1):
    x1 = X[i]
    for j in range(i + 1, N):
        x2 = X[j]
        work = 0
        for x, y in zip(x1, x2):
            work += (x - y) ** 2

        # 判定
        if math.sqrt(work).is_integer():
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    N, D = [int(x) for x in stdin.readline().rstrip().split()]
    Xs = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]
    count = 0
    for i in range(N - 1):
        for j in range(i + 1, N):
            sum_ = sum([(a - b) ** 2 for a, b in zip(Xs[i], Xs[j])])
            ans = sum_ ** (1 / 2)
            if int(ans) == ans:
                count += 1
    print(count)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import itertools
import math

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

def calc_dist(Y, Z):
    return math.sqrt(sum((y - z) ** 2 for y, z in zip(Y, Z)))

print sum([calc_dist(Y, Z).is_integer() for Y, Z in itertools.combinations(X, 2)])

Submission status: Accepted

Solution code:
def main():
    n,d = map(int,input().split(' '))
    x=[]
    for i in range(n):
        x.append(list(map(int,input().split(' '))))
    res = 0
    dis = 0
    for i in range(n):
        for j in range(i,n):
            if i !=j:
                for k in range(d):
                    dis += (x[i][k]-x[j][k])**2
                if dis**0.5%1 ==0:
                    res += 1
                dis = 0
    print(res)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

N, D = map(int, input().split())
X = []
for i 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(N):
        if i >= j:
            continue

        x_i = X[i]
        x_j = X[j]

        cache = float(0)
        for d in range(D):
            cache += (x_i[d] - x_j[d]) ** 2

        cache = math.sqrt(cache)

        if cache.is_integer():
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

N, D = [int(x) for x in input().split()]

X = np.zeros((N, D))
for i in range(N):
	t = [int(x) for x in input().split()]
	X[i,:] = np.array(t)

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

Submission status: Accepted

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
sys.setrecursionlimit(10**7)
# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###

N, D = mi()

Xs = [list(mi()) for _ in range(N)]

nijouset = {x*x for x in range(200)}

ans = 0
for i in range(N):
  j = i + 1
  while (j < N):
    tmpsum = 0
    for a, b in zip(Xs[i], Xs[j]):
      tmpsum += (a-b) * (a-b)
    if tmpsum in nijouset:
      ans += 1
    j += 1

print(ans)

Submission status: Accepted

Solution code:
import math
def isInteger(p1, p2):
    s = sum([(p1[i] - p2[i]) ** 2 for i in range(len(p1))])
    num = math.sqrt(s)
    return num - int(num) == 0
N, D = map(int, input().split())

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

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        if isInteger(points[i], points[j]): cnt += 1
print(cnt)

Submission status: Accepted

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

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def local_input():# {{{
    from pcm.utils import set_stdin
    import sys
    from pathlib import Path
    parentdir = Path(os.path.dirname(__file__)).parent
    inputfile = parentdir.joinpath('test/sample-1.in')
    if len(sys.argv) == 1:
        set_stdin(inputfile)
# }}}

def solve():
    n,d = map(int,input().split())
    lst = [0]*n
    for i in range(n):
        lst[i] = list(map(int,input().split()))
    ans = 0
    for i in range(n-1):
        for j in range(i+1,n):
            sum = 0
            for k in range(d):
                sum += (lst[j][k]-lst[i][k])**2
            if round(math.sqrt(sum))**2 == sum:
                ans +=1
    print(ans) 
    return 0

if __name__ == "__main__":# {{{
    try:
        local_input()
        def dump(*args):
            names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
            print(', '.join(names.get(id(arg),'???')+' => '+repr(arg) for arg in args), file=sys.stderr)
    except:
        def dump(*args):
            pass

    solve()

# vim: set foldmethod=marker:}}}

Submission status: Accepted

Solution code:
n,d = map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]
cn = 0
for i in range(n):
    for k in range(i+1,n):
        a = 0
        for j in range(d):
            a += (x[i][j] - x[k][j])**2
        b = a**0.5
        c = round(b)
        if -0.0001 < b-c < 0.0001:
            cn += 1
print(cn)

Submission status: Accepted

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

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

def dist(a,b):
    cnt = 0
    for i in range(len(a)):
        cnt += (a[i]-b[i])**2
    #print(cnt,math.sqrt(cnt))
    return math.sqrt(cnt)

ans = 0
for i in range(N):
    for j in range(i+1,N):
        if dist(l[i],l[j])%1 == 0:
            ans += 1
            #print(dist(l[i],l[j]))

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N, D = list(map(int, input().split()))

X = []

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


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

Submission status: Accepted

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

def dist(x,y):
    res = 0
    for i,j in zip(x,y):
        res += (i - j)**2
    if int(math.sqrt(res)) == math.sqrt(res):
        return 1
    else:
        return 0

ans = 0
for i in range(n):
    for j in range(i+1,n):
        ans += dist(l[i],l[j])

print(ans)

Submission status: Accepted

Solution code:
import math

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

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

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        v = 0
        for d in range(D):
            v += abs(point[i][d] - point[j][d]) ** 2
        v = math.sqrt(v)
        if v.is_integer():
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,d = na()
xx = []
for i in range(n):
    x = na()
    xx.append(x)

import itertools
import math

ans = 0

nums = range(n)
for a,b in itertools.combinations(nums, 2):
    c = 0
    for j in range(d):
        c += (xx[a][j]-xx[b][j])**2
    ans = ans+1 if round(math.sqrt(c))**2 == c else ans

print(ans)

Submission status: Accepted

Solution code:
N,D = map(int,input().split())
cood_list = [[int(i) for i in input().split()] for i in range(N)]
ans=0
dis_sum=0
for i in range(N):
    for j in range(i+1,N):
        for l in range(D):
            dis_sum += (cood_list[i][l]-cood_list[j][l])**2
        dis_sum = float(dis_sum)
        if dis_sum**(1/2)%1 == 0:
            ans +=1
        dis_sum=0
print(ans)

Submission status: Accepted

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

cnt = 0
for i in range(N):
    for j in range(N):
        if i < j :
            comb = [(x - y) * (x - y) for (x, y) in zip(x[i], x[j])]
            d = int(math.sqrt(sum(comb)))
            if d * d == sum(comb):
                cnt +=1

print(cnt)

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
count2 = 0
for i in range(N):
    for j in range(N):
        buff = 0
        flag = False
        for d in range(D):
            if i != j:
                count2 += 1
                flag = True
                buff += abs(X[i][d]-X[j][d])**2
        if math.sqrt(buff) % 1 == 0 and flag:
            # print(buff)
            count += 1

# print(count2)
# print(X)
print(count//2)

Submission status: Accepted

Solution code:
heihousu = set(int(i**2) for i in range(1000))
N,D = list(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):
    if sum([int((X[i][d]-X[j][d])**2) for d in range(D)]) in heihousu:
      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 + 1, n):
        d2 = sum((y - z) ** 2 for y, z in zip(x[i], x[j]))
        if d2 ** 0.5 % 1 == 0:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy

N, D = map(int, input().split())
points = []
for i in range(N):
	temp = numpy.array([int(x) for x in input().split()])
	points.append(temp)

count = 0
for i in range(N-1):
	for j in range(1, N):
		d = numpy.sqrt(numpy.sum((points[i] - points[j])**2))
		if(d.is_integer() and i<j):
			count+=1

print(count)

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)

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

Submission status: Accepted

Solution code:
import math

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

n, d = map(int, input().split())
x = []
for i in range(n):
    x.append(list(map(int, input().split())))
a = 0
for i in range(n):
    for k in range(i+1, n):
        tmp = 0
        for x1, x2 in zip(x[i], x[k]):
            tmp += (x1 - x2) ** 2
        a += is_integer_num(math.sqrt(tmp))

print(a)

Submission status: Accepted

Solution code:
import numpy as np

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

ps = []
for i in range(n):
    p = np.array(list(map(int, input().split())))
    ps.append(p)

count = 0
for i, pi in enumerate(ps):
    for pj in ps[i+1:]:
        d = np.sum((pi-pj)**2)
        sq = np.sqrt(d)
        if sq%1 < 1e-6:
            count += 1
print(count)

Submission status: Accepted

Solution code:
from itertools import combinations
def dist2(a, b):
    return sum([(i - j)**2 for i, j in zip(a, b)])


def check(num):
    return sum([True if i**2 == num else False for i in range(1, 202)]) > 0


n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
print(sum([check(dist2(i, j)) for i, j in combinations(x, 2)]))

Submission status: Accepted

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

# for i in range(N):


num_l = list(itertools.combinations(num, 2))

for num in num_l:
        # print(num)
        left = num[0]
        right = num[1]
        wa = 0
        for i in range(D):
                wa += (X[left][i] - X[right][i]) ** 2
        dist = math.sqrt(wa)
        if dist-int(dist) == 0:
                ans += 1

print(ans)

                
        #dist = math.sqrt(left)

Submission status: Accepted

Solution code:
import sys
from fractions import gcd
from collections import Counter
from itertools import combinations
from math import sqrt
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def calc(a, b):
    return sqrt(sum([(i -j)*(i-j) for i, j in zip(a,b)]))

def main():
    n, d = LI()
    xs = []
    ds = []
    ans = 0
    for i in range(n):
        xs.append(LI())
    for a, b in combinations(range(n), 2):
        ds.append(calc(xs[a], xs[b]))
    for i in ds:
        if i == i // 1:
            ans += 1
    print(ans)







if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans_sum = 0
for i in range(N):
    for j in range(N):
        temp = 0
        for d in range(D):
            temp += (abs(X[i][d] - X[j][d]))**2
        ans = temp**(1/2)
        if ans.is_integer():
            ans_sum += 1

print((ans_sum - N)//2)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
x=[]
for _ in range(n):
  x+=[list(map(int,input().split()))]
ans=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():
      ans+=1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np


def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod


mod = 10 ** 9 + 7  # 出力の制限
N = 10 ** 4
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)


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


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

ans = 0

for i in range(n):
    for j in range(i + 1, n):
        d = dist(arr[i], arr[j])
        if abs(d - int(d)) < 0.00001:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import math

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

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

for i in range(n):
    hoge = np.array([int(x) for x in input().split()])
    points[i, :] = hoge

total = 0

# calc distance
for i in range(n):
    for j in range(i+1, n):
        foo = (points[i, :] - points[j, :]) ** 2
        foo_sum = foo.sum()
        if int(foo_sum) == int(math.sqrt(foo_sum)) ** 2:
            total += 1

print(total)

Submission status: Accepted

Solution code:
# coding: utf-8
import numpy as np
n,d = map(int, input().split())
X = [list(map(int,list(input().split()))) for i in range(n)]
X = np.array(X)
#print(n,d)
#print(X)
count = 0

for i in range(n-1):
    for j in range(i+1,n):
        ans = np.sqrt(np.sum(np.square(X[i]-X[j])))
        #print(X[i]-X[j])
        #print(np.square(X[i]-X[j]))
        #print(ans,ans.is_integer())
        if ans.is_integer():
            count += 1
print(count)

Submission status: Accepted

Solution code:
import numpy as np

N,D = map(int, input().split())
A = np.zeros((N,D))

for i in range(N):
    A[i] = np.array(input().split(), dtype=np.int64)
    
ans = 0
    
for i in range(N):
    for j in range(N):
        B = A[i]
        C = A[j]
        k = np.linalg.norm(C - B, ord=2)
        if k.is_integer() == True:
            ans += 1
            
ans = ans - N
ans = int(ans / 2)
print(ans)

Submission status: Accepted

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

ans = 0

for i in range(n):
  for j in range(i+1, n):
    dis_2 = 0
    for k in range(d):
      dis_2 += (points[i][k] - points[j][k]) ** 2
    if (dis_2 ** 0.5) == int(dis_2 ** 0.5):
      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):
        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:
N, D = map(int, input().split())
XList = list()

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

answer = 0

for i, x1 in enumerate(XList):
    for j, x2 in enumerate(XList):
        if i >= j:
            continue
        sumple = 0
        for d in range(D):
            sumple += (x1[d] - x2[d]) ** 2
        if abs((sumple ** 0.5 )- (sumple ** 0.5)//1) < 10**(-7):
            answer += 1

print(answer)

Submission status: Accepted

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