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
def input():
    return sys.stdin.readline()[:-1]

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):
        dist = 0
        for I, J in zip(X[i], X[j]):
            dist += (I-J)**2
        dist = dist**0.5
        
        if dist.is_integer():
            cnt += 1

print(cnt)

Submission status: Accepted

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

answer = 0
for i in range(N):
  for j in range(i+1, N):
    dist = 0
    x_i = X[i]
    x_j = X[j]
    for d in range(D):
      dist += (x_i[d] - x_j[d])**2
    if (dist**0.5).is_integer():
      answer += 1

print(answer)

Submission status: Accepted

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

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

dis = []
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

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

print(ans)

Submission status: Accepted

Solution code:
def f(A, B):
    ret = 0
    for a, b in zip(A, B):
        ret += (a - b) ** 2
    return ret ** .5
def solve():
    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):
            t = f(X[i], X[j])
            if t - int(t) < 1e-5:
                ans += 1
    print(ans)
solve()

Submission status: Accepted

Solution code:
import sys
import math

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(N, D, inputs):
    points = list(map(lambda x: string_to_int(x), inputs))

    count = 0
    for i in range(0, len(points)-1):
        for j in range(i+1, len(points)):
            each_d_sum = 0

            for di in range(0, D):
                each_d_sum += (points[j][di] - points[i][di]) ** 2
            result = math.sqrt(each_d_sum)
            if result.is_integer():
                count += 1
    return count


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    [N, D] = string_to_int(input())

    ret = solve(N, D, inputs(N))
    print(ret)

Submission status: Accepted

Solution code:
import math
n,d=map(int,input().split())
xl=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        fx=xl[i]
        tx=xl[j]
        t=0
        for k in range(d): 
            t+=(fx[k]-tx[k])**2
        ts=math.sqrt(t)
        if ts==float(ts//1):
            ans+=1
print(ans)

Submission status: Accepted

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

for i in range(N-1):
    for q in range(i+1,N):
        res_doubled = 0
        for a,b in zip(pos[i],pos[q]):
            res_doubled += (a-b)**2
        res = math.sqrt(res_doubled)
        if res==int(res):
            ans += 1
print(ans)

Submission status: Accepted

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

ls =[]

for _ in range(n):
  ls.append(list(map(int,input().split())))

def calc(a,b):
  num = 0
  for i in range(len(a)):
    num += (a[i]-b[i])**2
  if num**0.5 == int(num**0.5):
    return 1
  return 0

count = 0
for i in range(n-1):
  for j in range(i+1,n): 
    count += calc(ls[i],ls[j])
print(count)

Submission status: Accepted

Solution code:
N,D=(int(x) for x in input().split())
X=[[0]*D for _ in range(N)]
for n in range(N):
    A=list(map(int,input().split()))
    for d in range(D):
        X[n][d]=A[d]
def kyori(x,y,d):
    c=0
    for dd in range(d):
        c=c+(x[dd]-y[dd])**2
    return(c**(1/2))
ans=0
for i in range(N):
    for j in range(i+1,N):
        kyo=kyori(X[i],X[j],D)
        if kyo.is_integer()==True:
            ans=ans+1
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import numpy as np

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

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

x = np.array(x)

ans = 0

for i in range(len(x)):
    for j in x[i+1:]:
        if np.sqrt(sum((x[i]-j)**2))%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 _ in range(n)]
l = []
cnt = 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 t == int(math.sqrt(t))**2:
            cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
from math import ceil, sqrt
n,d=map(int,input().split())
pw=[]
for i in range(n):
    inp=tuple(map(int,input().split()))
    pw.append(inp)

ans=0
for i in range(n-1):
    for j in range(i+1, n):
        dis=sqrt(sum([(a-b)**2 for a,b in zip(pw[i],pw[j])]))
        if ceil(dis)==int(dis):
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter
import math
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, d = na()
pl = []
for i in range(n):
    pl.append(na())
#print(pl)
ct = 0
for i in range(n):
    for j in range(i+1, n):
        l = 0
        if i != j:
            #print(i, j)
            for k in range(d):
                l += ((pl[i][k] - pl[j][k]) ** 2)
                #print(l)
            if math.sqrt(l).is_integer():
                ct += 1
print(ct)

Submission status: Accepted

Solution code:
import functools as ft
import heapq
import itertools as it
import logging
import unittest
from collections import (
    OrderedDict,
    defaultdict,
    namedtuple,
    Counter,
)

import numpy as np

_ = [ft, it, np, heapq, namedtuple, Counter, defaultdict, OrderedDict]

debug = logging.getLogger(__name__).debug


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


def _main():
    n, d = input_ints()
    x = [input_ints() for _ in range(n)]
    x = np.array(x)
    print(sum(
        d == np.round(d)
        for i in range(n)
        for j in range(i)
        for d in [np.sqrt(np.sum((x[i] - x[j]) ** 2))]
    ))


class Test(unittest.TestCase):
    def setUp(self):
        import run
        self._test = run

    def test_main(self):
        self._test.test_files(self, _main)


if __name__ == '__main__':
    _main()

Submission status: Accepted

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

def solve(N: int, D: int, X: "List[List[int]]"):
    
    ans = 0
    for i in range(N-1):
        l = [.0]*N
        for j in range(i+1,N):
            t = sum([(X[j][k]-X[i][k]) ** 2 for k in range(D)])
            l[j] = sqrt(t)

        for j in range(1,N):
            if(l[j] != 0 and l[j].is_integer()):
                ans += 1

    print(ans) 
    return


# Generated by 1.1.4 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,heapq,math
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
def ddprint(x):
  if DBG:
    print(x)

n,d = inm()
x = []
for i in range(n):
    x.append(inl())
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        q = sum([(x[i][k]-x[j][k])**2 for k in range(d)])
        if (int(math.sqrt(q)))**2 == q:
            ans += 1
print(ans)

Submission status: Accepted

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

cnt = 0
zizyou = [x**2 for x in range(128)]

for i in range(len(xs)-1):
    for j in range(i+1,len(xs)):
        s = 0
        for d in range(D):
            s += (xs[i][d]-xs[j][d])**2
        
        if s in zizyou:
#             print(i,j,s)
            cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
import math


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


def square_distance(point1, point2):
    distance = 0
    for x, y in zip(point1, point2):
        distance = distance + (x - y) ** 2
    return distance


def int_distance(point1, point2):
    return round(math.sqrt(square_distance(point1, point2)))


if __name__ == "__main__":
    [n, d] = li()
    x_list = [li() for _ in range(n)]

    count = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            if square_distance(x_list[i], x_list[j]) == int_distance(x_list[i], x_list[j]) ** 2:
                count = count + 1
    print(count)

Submission status: Accepted

Solution code:
import sys
import math
input = sys.stdin.readline
N, D = map(int, input().split())
A = [0]*N
for i in range(N):
    A[i] = list(map(int, input().split()))

counter = 0
for i in range(N):
    for j in range(i+1, N):
        dist = 0
        for k in range(D):
            dist += abs(A[i][k] - A[j][k])**2
        dist = math.sqrt(dist)
        if dist.is_integer():
            counter += 1
print(counter)

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
L=[]
for i in range(N):
    x=list(map(int,input().split()))
    L.append(x)
#print(L)
ans=0
for i in range(N-1):
    for j in range(i+1,N):
        cnt=0
        for k in range(D):
            cnt+=(L[i][k]-L[j][k])**2
        if pow(cnt,0.5)==int(pow(cnt,0.5)):
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
import math


def ok(y: list, z: list, D: int)->bool:
    d = 0
    for i in range(D):
        d += (y[i]-z[i]) ** 2

    s = int(math.sqrt(d))

    return s * s == d


def good_distance(N: int, D: int, X: list)->int:
    count = 0

    for i in range(N):
        y = X[i]
        for j in range(i+1, N):
            z = X[j]

            count += ok(y, z, D)

    return count


if __name__ == "__main__":
    N, D = map(int, input().split())
    X = [[int(s) for s in input().split()] for _ in range(N)]
    ans = good_distance(N, D, X)

    print(ans)

Submission status: Accepted

Solution code:
import math
n,d=map(int,input().split())
x=[list(map(int,input().split()))for _ in range(n)]
def a(a,b):
  aa=0
  for i in range(d):aa+=abs(a[i]-b[i])**2
  if math.sqrt(aa)%1==0:return 1
  return 0
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    ans+=a(x[i],x[j])
print(ans)

Submission status: Accepted

Solution code:
from math import sqrt
from itertools import combinations

def dist(X, Y):
    d = 0
    for x, y in zip(X, Y):
        d += pow(x-y, 2)
    d = sqrt(d)
    if d == int(d):
        return 1
    return 0

N, D = map(int, input().split())
Z = []
for n in range(N):
    z = list(map(int, input().split()))
    Z.append(z)

C = [i for i in range(N)]
ans = 0
for c in combinations(C, 2):
    ans += dist(Z[c[0]], Z[c[1]])

print(ans)

Submission status: Accepted

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

x = []

for i in range(n):
	xi = [int(i) for i in input().split()]
	x.append(xi)

c = 0
for i in range(n):
	for j in range(i,n):
		tmp = 0.0
		for k in range(d):
			tmp += (x[i][k] - x[j][k])**2
		tmp = tmp**0.5
		if tmp != 0 and tmp.is_integer():
			c+=1
print(c)

Submission status: Accepted

Solution code:
def main():
    N, D = list(map(int, input().split()))
    X = []
    for i 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):
            total = 0.0
            for x, y in zip(X[i], X[j]):
                total += abs(x - y) ** 2
            total = total ** 0.5
            if int(total) == total:
                count += 1

    print(count)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math


def distance(A,B):
    tmp = 0
    for i in range(len(A)):
        tmp += (A[i] - B[i]) ** 2
    tmp = math.modf(tmp ** 0.5)
    if tmp[0] == 0.0:
        return True
    else:
        return False


N,D = [int(i) for i in input().split()]
X = [[int(i) for i in input().split()] for _ in range(N)]    
ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        if distance(X[i],X[j]):
            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 dist(p1, p2, D):
    sum = 0
    for i in range(D):
        sum += (p1[i] - p2[i]) ** 2
    return math.sqrt(sum)


cnt = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        d = dist(X[i], X[j], D)
        if d.is_integer():
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from math import sqrt

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

ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        sq_d = 0
        for k in range(D):
            sq_d += (X[i][k] - X[j][k]) ** 2
        d = sqrt(sq_d)
        if d - int(d) == 0:
            ans += 1
print(ans)

Submission status: Accepted

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

r = 0
for i in range(N):
  for j in range(i+1, N):
    y, z= Xs[i], Xs[j]
    d2 = 0
    for k in range(D):
      d2 += (y[k]-z[k])*(y[k]-z[k])
    d = math.sqrt(d2)
    if d==int(d):
      r += 1
print(r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def inpl():
    return list(map(int, input().split()))


def distance(X, Y):
    tmp = 0
    for i in range(len(X)):
        tmp += (X[i] - Y[i])**2
    return tmp**0.5


def isInteger(i):
    return i - int(i) == 0


N, D = inpl()
X = [inpl() for i in range(N)]

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    n, d = map(int, input().split())
    xs = [[int(a) for a in input().split()] for _ in range(n)]

    cnt = 0
    for i, x in enumerate(xs):
        for j, y in enumerate(xs):
            if i >= j:
                continue
            d = sum([(xi - yi)**2 for xi, yi in zip(x, y)])
            d2 = int(d ** 0.5) - 1
            if d2 ** 2 == d or (d2 + 1) ** 2 == d or (d2 + 2) ** 2 == d:
                cnt += 1
    print(cnt)


main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math

def dist(x, y):
    s = 0
    for _x, _y in zip(x, y):
        s += (_x - _y) ** 2
    return math.sqrt(s)


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

cnt = 0
for i in range(n):
    for j in range(i+1, n):
        d = dist(xs[i], xs[j])
        if d == int(d):
            cnt += 1

print(cnt)

Submission status: Accepted

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

xs = []
for _ in range(n):
    xs.append(list(map(int, input().split())))
ans = 0
for i in range(n):
    xi = xs[i]
    for j in range(i+1, n):
        xj = xs[j]
        dist = sum([(xid - xjd)**2 for (xid, xjd) in zip(xi, xj)]) ** 0.5
        if dist.is_integer():
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math
n,d=map(int,input().split())
co=[]
for _ in range(n):
    x=list(map(int,input().split()))
    co.append(x)
ans=0
for i in range(n):
    for j in range(n):
        if i<j:
            a=0
            for k in range(d):
                a+=(co[i][k]-co[j][k])**2
            b=int(math.sqrt(a))
            if b*b-a==0:
                ans+=1
print(ans)

Submission status: Accepted

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

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

def dist(l,m):
    sum = 0
    for i in range(D):
        sum += (X[l][i] - X[m][i])**2
    return math.sqrt(sum)

ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        #print("{} {}".format(i,j))
        d = dist(i,j)
        if d.is_integer():
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import copy


def dist2(y, z):
    return np.sum((y - z)**2)


def main():
    N, D = map(int, input().split())
    Xs = []
    for _ in range(N):
        X = list(map(int, input().split()))
        Xs.append(X)
    Xs = np.array(Xs, dtype=np.int)
    assert Xs.shape == (N, D)

    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            d = dist2(Xs[i, :], Xs[j, :])
            if d == int(np.sqrt(d))**2:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

result = 0

for i in range(n):
    for j in range(i+1, n):
        sum = 0
        for k in range(d):
            sum += (points[i][k] - points[j][k]) ** 2
        dist = sum ** 0.5
        if dist.is_integer():
            result += 1
print(result)

Submission status: Accepted

Solution code:
import math

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

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

count = 0
for i in range(N-1):
    for j in range(i+1, N):
        total = 0
        for d in range(D):
            total += pow(points[i][d] - points[j][d], 2)
        if math.sqrt(total).is_integer():
            count += 1

print(count)

Submission status: Accepted

Solution code:
def getlist():
	return list(map(int, input().split()))

N, D = getlist()

XL = []

for i in range(N):
	X = getlist()
	XL.append(X)

ans = 0
for i in range(N):
	for j in range(i + 1, N):
		c = 0
		for k in range(D):
			c += (XL[i][k] - XL[j][k]) ** 2
		for k in range(150):
			if k ** 2 == c:
				ans += 1
				break

print(ans)

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())))
count=0
#print(x)
y=np.array(x)
#print(y)
for i in range(n):
    for j in range(n):
        if i<j:
            s=sum((y[i]-y[j])**2)
            #print(s)
            if np.round(np.sqrt(s))**2==s:
                #print(s)
                count+=1
print(count)

Submission status: Accepted

Solution code:
N,D = map(int,input().split())
nums = []
for i in range(N):
    nums.append(list(map(int,input().split())))
count = 0
for j in range(len(nums)):
    for k in range(len(nums)):
        ans = 0
        if j==k:
            continue
        for (x,y) in zip(nums[j],nums[k]):
            ans+=abs(x-y)**2
        ans = ans**(1/2)
        if int(ans)==ans:
            count+=1
print(count//2)

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
x = []
for i in range(n):
    x.append(list(map(int, input().split())))
counter = 0
# 出力
for i in range(n):
    for j in range(i+1,n):
        dist = 0
        for k in range(d):
            dist += (x[i][k]-x[j][k])**2
        if dist**0.5%1 == 0:
            counter+=1
print(counter)

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 y in range(n):
    for z in range(y+1, n):
        temp = 0
        for i in range(d):
            temp += (x[y][i] - x[z][i])**2
        if float(math.sqrt(temp)).is_integer():
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
N,D = [int(i) for i in input().split()]
X = []
for n in range(N):
    X.append([int(i) for i in input().split()])
import numpy as np
X = np.array(X)
cnt = 0
for n in range(N):
    for nn in range(n+1,N):
        tmp = np.linalg.norm(X[n] - X[nn])
        if tmp == int(tmp):
            cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import math

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

  for i in range(N):
    xi = X[i]
    for j in range(i + 1, N):
      xj = X[j]
      dist = math.sqrt(sum([(xi[d] - xj[d]) ** 2 for d in range(D)]))
      if dist.is_integer(): cnt += 1

  return cnt

print(solve())

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
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):
		dist = 0
		for k in range(D):
			dist += (X[i][k] - X[j][k]) ** 2
			
		dist **= 0.5
		if dist - int(dist) == 0:
			count += 1

print(count)

Submission status: Accepted

Solution code:
import math

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

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

print(cnt)

Submission status: Accepted

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

sqs = [i ** 2 for i in range(100000)]

ans = 0
for i in range(n):
    for j in range(i+1,n):
        d1 = dots[i]
        d2 = dots[j]
        temp = 0
        for dd1,dd2 in zip(d1,d2):
            temp += (dd1 - dd2) ** 2
        if temp in sqs:
            ans += 1



print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

X = np.array(X)
count = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        x1, x2 = X[i], X[j]
        dist = np.sqrt(((x1 - x2) ** 2).sum())
        if dist - int(dist) < 1e-10:
            count += 1
print(count)

Submission status: Accepted

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

def dist2(x, y):
    return sum((a-b)**2 for (a, b) in zip(x, y))

def judge(d):
    m = int(d ** 0.5)
    return m*m == d

cnt = 0
for p in combinations(X, 2):
    x, y = p
    cnt += 1 if judge(dist2(x, y)) else 0

print(cnt)

Submission status: Accepted

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

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

counter = 0
for i in range(N):
    for j in range(i+1, N):
        s = 0
        for d in range(D):
            s += (point[i][d] - point[j][d]) ** 2
        # print(s)
        dist = int(math.sqrt(s))
        # print(i, j, dist, s)
        if dist ** 2 == s:
            counter += 1
print(counter)

Submission status: Accepted

Solution code:
import math
def prob_b():
    n, d = [int(a) for a in input().split()]
    spot_list = list()
    for i in range(n):
        spot_list.append([int(a) for a in input().split()])
    counter = 0
    for i in range(n-1):
        spot_1 = spot_list[i]
        for j in range(n-1-i):
            spot_2 = spot_list[i+1+j]
            dist_sq = sum([(a-b) ** 2 for a, b in zip(spot_1, spot_2)])
            dist = math.sqrt(dist_sq)
            if dist_sq == int(dist) ** 2:
                counter += 1
    print(str(counter))


prob_b()

Submission status: Accepted

Solution code:
import numpy as np
N, D = list(map(int, input().split()))
vecs = np.array([list(map(int, input().split())) for _ in range(N)])
cnt = 0
for i in range(N):
    for j in range(i+1,N):
        dist = np.linalg.norm(vecs[i]-vecs[j])
        if dist.is_integer():
            cnt+=1
print(cnt)

Submission status: Accepted

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

res = set()
for i in range(1000):
    res.add(i ** 2)

ans = 0
for i in range(N):
    a = 0
    for j in range(i + 1, N):
        tmp = 0
        for k in range(D):
            y = items[i][k]
            x = items[j][k]
            tmp += abs(y-x) ** 2
        a = tmp
        if a in res:
            ans += 1
print(ans)

Submission status: Accepted

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


def isSquared(n):
    for i in range(128):
        if i ** 2 > n:
            return False
        elif i ** 2 == n:
            return True
    return False


def squaredDist(x, y):
    s = 0
    for i, j in zip(x, y):
        s += (i - j)**2
    return s


def solve():
    N, D = list(map(int, input().split()))
    points = [list(map(int, input().split())) for _ in range(N)]
    count = 0
    for i in range(N):
        for j in range(i + 1, N):
            if isSquared(squaredDist(points[i], points[j])):
                count += 1
    return count


def main():
    print(solve())


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, D = map(int, input().split())
list_x = [list(map(int, input().split()))]
count = 0
for i in range(1, N):
    list_x.append(list(map(int, input().split())))
    for j in range(i):
        sum_square = 0
        for k in range(D):
            sum_square += (list_x[i][k] - list_x[j][k]) ** 2
        sum = sum_square ** (1/2)
        if(sum == int(sum)):
            count += 1
print(count)

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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
from math import sqrt

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,D=MAP()
X=[]
for i in range(N):
    X.append(LIST())

cnt=0
for i in range(N):
    for j in range(i+1, N):
        sm=0
        A=X[i]
        B=X[j]
        for k in range(D):
            sm+=(A[k]-B[k])**2
        ans=sqrt(sm)
        if ans>=0 and ans.is_integer():
            cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
from itertools import combinations
import math

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

for a, b in combinations(X, 2):
    dist = 0.0
    for d in range(D):
        dist += abs(a[d] - b[d])**2
    if math.sqrt(dist).is_integer():
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
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 II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    N, D = LI()
    X = []
    for _ in range(N):
        X.append(LI())

    counter = 0
    import itertools
    for i, j in itertools.combinations(range(N),2):
        summation = 0
        for dim in range(D):
            summation += (X[i][dim] - X[j][dim]) **2

        import math
        if math.sqrt(summation).is_integer():
            counter += 1


    print(counter)





main()

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
X=[list(map(int,input().split())) for i in range(N)]
a=0
from math import sqrt
for i in range(N-1):
    for j in range(i+1,N):
        d=0
        for x in range(D):
            d+=(X[i][x]-X[j][x])*(X[i][x]-X[j][x])
        if sqrt(d)%1==0:
            a+=1
print(a)

Submission status: Accepted

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

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 = sqrt(distance)
        if int(distance) - distance == 0:
                cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import math

a,b = map(int,input().split())
x = []
for i in range(a):
    t= list(map(int,input().split()))
    x.append(t)
# print(x)
res = 0
for i in range(a):
    for j in range(i,a):
        if i == j :continue

        s = 0
        # print((x[i],x[j]))
        for k,t in zip(x[i],x[j]):
            p = (k-t)**2
            s+=p
        # print((math.sqrt(s)),int(math.sqrt(s)))
        res += (math.sqrt(s))==int(math.sqrt(s))
print(res)