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
inpl = lambda: list(map(int,input().split()))
N, D = inpl()
X = [ inpl() for _ in range(N) ]
ans = 0
for i in range(N):
    for j in range(i+1,N):
        dist = sqrt(sum( (X[i][d]-X[j][d])**2 for d in range(D)))
        if dist == int(dist):
            ans += 1
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)]

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def dif(X,Y):
    return sum([(x-y)**2 for x,y in zip(X,Y)])

def judge(n):
    for i in range(1,n+1):
        if i**2 == n:
            return True
    return False

cnt = 0
for i in range(N):
    for j in range(i+1,N):
        if judge(dif(X[i],X[j])):
            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)]

def calc(x, y):
    cnt = sum((x[i] - y[i]) ** 2 for i in range(D))
    return cnt ** 0.5 == int(cnt ** 0.5)

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        ans += 1 if calc(X[i], X[j]) else 0
print(ans)

Submission status: Accepted

Solution code:
import math
[n,d] = [int(i) for i in input().split()]
x = []
tmp = 0
cnt = 0
for i in range(n):
    x.append([int(i) for i in input().split()])
#i = 0 ~ n-1
for i in range(n):
    #j = i ~ n-1
    for j in range(i+1,n):
        for k in range(d):
            tmp += (x[i][k]-x[j][k])**2
        tmp = math.sqrt(tmp)
        if tmp - math.floor(tmp) == 0:
            cnt += 1
        tmp = 0
print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from collections import defaultdict, deque
import math
from math import factorial
import re

def dist(x, y):
    d = 0
    for xi, yi in zip(x, y):
        d += (xi - yi) ** 2
    return math.sqrt(d)

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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


def dist(i, j):
    sum = 0
    for i0, j0 in zip(i, j):
        sum += (i0-j0)**2
    return sum**0.5


ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        if dist(X[i], X[j]) == int(dist(X[i], X[j])):
            ans += 1

print(ans)

Submission status: Accepted

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

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):
        tmp = 0
        for d in range(D):
            tmp += abs(x[i][d] - x[j][d])**2
        t = 1
        while t*t <= tmp:
            if t*t == tmp:
                count += 1
            t += 1

print(count)

Submission status: Accepted

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

ans = 0
for i in range(n):
    for j in range(i, n):
        if i == j:
            continue
        dif = 0
        for k in range(d):
            dif += abs(points[i][k] - points[j][k]) ** 2
        if dif ** 0.5 == int(dif ** 0.5):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math

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

ans = 0
for i in range(N):
    for j in range(i+1, N):
        dist = 0
        for d in range(D):
            dist += (X_list[i][d] - X_list[j][d]) ** 2
        dist = dist ** (1/2)
        if dist - math.floor(dist) == 0:
            ans += 1
print(ans)

Submission status: Accepted

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

def distsq(Y,Z):
    res = 0
    for y,z in zip(Y,Z):
        res += (y-z)**2
    return res

def solve(N: int, D: int, X: "List[List[int]]"):
    res = 0
    for i in range(len(X)-1):
        for j in range(i+1,len(X)):
            d = distsq(X[i],X[j])
            d2 = math.floor(d**0.5)
            if d == d2**2:
                res += 1
    print(res)




# 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 math

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

c = 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
        dist = math.sqrt(dist)
        if dist-int(dist) == 0:
            c += 1

print(c)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
ps=[list(map(int,input().split())) for _ in range(n)]
cnt=0
for i in range(n-1):
    for j in range(i+1,n):
        s=0
        for x1,x2 in zip(ps[i],ps[j]):
            s+=(x1-x2)**2
        s=s**0.5
        if s==int(s):
            cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import math
import itertools

n, d = map(int, input().split())
x_list = [list(map(int, input().split())) for _ in range(n)]
count = 0
for y, z in itertools.combinations(x_list, 2):
    s = 0
    for i in range(d):
        s += (y[i] - z[i]) ** 2
    for i in range(1, int(math.sqrt(s)) + 1):
        if s == i ** 2:
            count += 1
            break
print(count)

Submission status: Accepted

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

ans = 0


def dist(list1, list2):
    rep = 0
    for k in range(len(list1)):
        rep += (list1[k] - list2[k])**2
    return rep**(1 / 2)


for i in range(N):
    xd1 = XD[i]
    for j in range(i + 1, N):
        xd2 = XD[j]
        if dist(xd1, xd2) == int(dist(xd1, xd2)):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:

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

for i in range(N):

    x = list(map(int,input().split()))

    X.append(x)

for i in range(N):

    for j in range(i):

        summ = 0

        for k in range(D):

            summ += (X[i][k] - X[j][k]) ** 2

        now = 0
        while now ** 2 <= summ:

            if now ** 2 == summ:
                ans += 1

            now += 1

print (ans)

Submission status: Accepted

Solution code:
N, D= map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
def d(x, y):
    ans = 0
    for i in range(D):
        ans+=(x[i]-y[i])**2
    return ans
ans = 0
for i in range(N):
    for j in range(i+1, N):
        dis = d(X[i], X[j])
        if dis==int(dis**(1/2))**2 or dis == int(dis**(1/2)+1)**2:
            ans+=1
print(ans)

Submission status: Accepted

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

count=0
for i,X in enumerate(XX):
    for j,Y in enumerate(XX):
        if i>=j:
            continue
        r=0
        for x,y in zip(X,Y):
            r+=(y-x)**2
        if math.sqrt(r)==int(math.sqrt(r)):
            count+=1

print(count)

Submission status: Accepted

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

ans = 0
for i in range(N-1):
	for j in range(i+1,N):
		dist = 0
		for d in range(D):
			dist += (points[i][d] - points[j][d]) ** 2
		for x in range(1,dist+1):
			if x*x > dist:
				break
			elif x*x == dist:
				ans += 1
				break
print(ans)

Submission status: Accepted

Solution code:
import math

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

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

        t = math.sqrt(tmp)
        if t == int(t):
            ans += 1

print(ans)

Submission status: Accepted

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

ans=0
for i1 in range(n-1):
    for i2 in range(i1+1,n):
        p1=zahyou[i1]
        p2=zahyou[i2]
        dist=0
        for i in range(d):
            tmp = (p1[i]-p2[i])**2
            dist+=tmp
        dist=math.sqrt(dist)
        if dist==int(dist):
            ans+=1

print(ans)

Submission status: Accepted

Solution code:
def solve():
  n,d = (int(i) for i in input().split())
  query = []
  judge = []
  for i in range(1,2001):
    judge.append((i**2))
  
  for i in range(n):
    x = list(int(i) for i in input().split())
    query.append(x)
  ans = 0
  for i in range(n):
    for j in range(n):
      if (i!=j):
        checker = 0
        for k in range(d):
         checker += (query[j][k]-query[i][k])**2
        if checker in judge:
          ans += 1
  print(ans//2)
solve()

Submission status: Accepted

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

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

# print (lst)

def length(lst1, lst2):
    d = 0
    for i in range(D):
        d += (lst1[i] - lst2[i]) ** 2
    return math.sqrt(d)

count = 0
for i in range(N):
    for j in range(i+1, N):
        a = length(lst[i], lst[j])
        if a ** 2 == (int(a)) ** 2:
            count += 1

print (count)

Submission status: Accepted

Solution code:
import math

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

X_list = []

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

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

print(res)

Submission status: Accepted

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

ls = [[int(x) for x in input().split()] for _ in range(n)]
import math
cnt=0
for i in range(n-1):
    for j in range(i+1,n):
        can = 0
        for k in range(d):
            can += (ls[i][k]-ls[j][k])**2
        if int(math.sqrt(can)) == math.sqrt(can):
            cnt +=1
        
print(cnt)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
L=[]
ans=0
for i in range(1,500):
  L.append(i**2)
for i in range(n):
  for j in range(i+1,n):
    ct=0
    for k in range(d):
      ct+=(l[i][k]-l[j][k])**2
    if ct in L:
      ans+=1
print(ans)

Submission status: Accepted

Solution code:
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(N):
        if i < j:
            dis = 0
            for k in range(D):
                dis += (arr[i][k]-arr[j][k])**2
            dis = pow(dis, 1/2)
            if abs(int(dis) - dis) < 0.1**10:
                ans += 1

print(ans)

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
X=[[int(i) for i in input().split()] for i in range(N)]
num=0
for i in range(N):
    for j in range(i+1,N):
        a=0
        for k in range(D):
            a+=(X[i][k]-X[j][k])**2
        #print(a)
        for x in range(201):
            if x**2==a:
                num+=1
                break
print(num)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, D = MAP()

X = [LIST() for _ in range(N)]
ans = 0
for i, j in combinations(X, 2):
	tmp = 0
	for k in range(D):
		tmp += (i[k]-j[k])**2
	if tmp**(1/2) == ceil(tmp**(1/2)):
		ans += 1
print(ans)

Submission status: Accepted

Solution code:
def dist(A, B):
	res = 0
	for i in range(D):
		res += (A[i] - B[i]) ** 2
	res = res ** 0.5
	return res


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):
		if dist(X[i], X[j]).is_integer():
			ans += 1
print(ans)

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
XN = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n):
    for j in range(i+1, n):
        Y = XN[i]
        Z = XN[j]
        dis = 0
        for y, z in zip(Y, Z):
            dis += (y-z)**2
        if int(dis**.5) == dis**.5:
            ans += 1
print(ans)

Submission status: Accepted

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

import math

def ri():
    return int(input())

def rl():
    return list(input().split())

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

def dist(a, b):
    d = 0
    for a1, b1 in zip(a, b):
        d += (a1-b1)**2
    d = math.sqrt(d)
    return (d-int(d)) < 0.00001

def main():
    n, d = rli()
    lp = []
    for _ in range(n):
        lx = rli()
        lp.append(lx)
    ans = 0
    for i in range(n):
        for j in range(i+1, n):
            if dist(lp[i], lp[j]):
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()

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 check(x,y):
    s = 0
    for i in range(D):
        s += (x[i]-y[i])**2
    j = math.floor(math.sqrt(s))
    return j**2 == s
ans = 0
for i in range(N):
    for j in range(i+1, N):
        if check(X[i],X[j]):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
def distance(A, B):
    d = 0
    for a, b in zip(A, B):
        d += (a - b) ** 2
    return d ** 0.5


n, d = map(int, input().split())
X = [tuple(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        d = distance(X[i], X[j])
        if d == round(d):
            ans += 1
print(ans)

Submission status: Accepted

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

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

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

print(count)

Submission status: Accepted

Solution code:
import math
def f(i,j):
    global N,D,X
    res = 0
    for x in range(D):
        res += (X[i][x]-X[j][x])**2
    return math.sqrt(res)
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(N):
        if i<=j:
            break
        if f(i,j)%1==0:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
import math

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

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

count = 0
for i in range(N):
    for j in range(i+1, N):
        m = sum((y-z)**2 for y, z in zip(X[i], X[j]))**(1/2)
        # print(i, j, m)
        if m % 1 == 0:
            count += 1

print(count)

Submission status: Accepted

Solution code:
N,D = map(int,input().split())
X = [list(map(int,input().split())) for _ in [0]*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 abs(int(dist**0.5)**2 - dist) < 1e-6:ans+=1
print(ans)

Submission status: Accepted

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

def leng(A,B):
    ans = 0
    for i in range(len(A)):
        ans += (A[i]-B[i])**2
    return ans**0.5
ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        if leng(X[i],X[j]) % 1 == 0:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
#

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop
import math

def main():
    n, d = map(int, input().split())
    x = [list(map(int, input().split())) for _ in range(n)]
    # print(x)

    ans = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            diff = 0
            for d1, d2 in zip(x[i], x[j]):
                diff += (d1 - d2) ** 2
            # print(diff)
            diff = math.sqrt(diff)
            if diff == int(diff):
                ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

coodi = []
count = 0
for i in range(n):
	coodi.append( list(map(int, input().split())) )

for i in range(n):
	for j in range(i+1, n):
		dist = 0
		for d in range(dim):
			dist += ( coodi[i][d] - coodi[j][d] ) ** 2
		for k in range(0, 200):
			if k ** 2 == dist:
				count += 1
				break

print(count)

Submission status: Accepted

Solution code:
import math


N, D = list(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):
        d2 = sum((X[i][k] - X[j][k]) ** 2 for k in range(D))
        d = math.floor(math.sqrt(d2))
        if d * d == d2:
            res += 1
print(res)

Submission status: Accepted

Solution code:
import math

def sqdist(a,b):
	temp = 0
	for i in xrange(len(a)):
		temp += (a[i] - b[i])**2
	return temp

n,d = map(int,raw_input().split())
x = []
for i in xrange(n):
	x.append(map(int,raw_input().split()))

res = 0
for i in xrange(n-1):
	for j in xrange(i+1,n):
		dist = sqdist(x[i],x[j])
		if math.sqrt(dist) == math.floor(math.sqrt(dist)):
			res += 1
print res

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
points = [[]] * n
for i in range(n):
  points[i] = list(map(int, input().split()))
 
def helper(a, b):
  s = 0
  for i in range(d):
    s += (a[i] - b[i]) ** 2
  a = int(0.5 + (s ** 0.5))
  if a * a == s:
    return 1
  return 0
 
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        ans += helper(points[i], points[j])
print(ans)

Submission status: Accepted

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

ret = 0
for i in range(N-1) :
    for j in range(i + 1, N) :
        d = 0
        for k in range(D) :
            d += (X[i][k] - X[j][k]) ** 2
        
        k = 1
        while k * k < d :
            k += 1
        if k * k == d :
            ret += 1
            
print(ret)

Submission status: Accepted

Solution code:
import numpy as np

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):
        s = np.linalg.norm(np.array(X[i])-np.array(X[j]))
        if s==int(s):
            count+=1

print(count)

Submission status: Accepted

Solution code:
import math


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


def main():
    N, D = map(int, input().split())
    P = [tuple(map(int, input().split())) for _ in range(N)]
    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            if check(P[i], P[j], D):
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

import numpy as np  # 1.8.2

def main():
    N, D = i2nn()
    X = ii2nnn(N)
    n = 0
    for i in range(N):
        for j in range(i+1, N):
            a = np.array(X[i])
            b = np.array(X[j])
            c = a - b
            d = np.linalg.norm(c)
            if int(d) == float(d):
                n += 1
    print(n)

main()

Submission status: Accepted

Solution code:
import math

n, d = map(int, input().split())  # 複数数値入力
li = list()
for i in range(n):
    li.append(list(map(int, input().split())))  # 複数数値入力(リスト格納)
ans = 0

for i in range(n):
    for j in range(i + 1, n):
        sum = 0
        for k in range(d):
            sum += (li[i][k] - li[j][k]) ** 2

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

Submission status: Accepted

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

xlist=[]
for i in range(N):
  x=list(map(int,input().split()))
  xlist.append(x)
  
#print(xlist)
answer=0
for i in range(0,N-1):
  x1=xlist[i]
  for j in range(i+1,N):
    x2=xlist[j]
    
    dist2=0
    for d in range(D):
      dist2+=(x2[d]-x1[d])**2
      
    dist=math.sqrt(dist2)
    if int(dist) == dist:
      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)]

def try_square_root_naive(n):
  m = int(n ** .5)
  return m if abs(m * m - n) < 1e-6 else None

ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    temp = 0
    for k in range(d):
      temp += (x[i][k] - x[j][k]) ** 2
    if try_square_root_naive(temp) is not None:
      ans += 1

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC133 B

import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
def LI(): return list(map(int,sys.stdin.readline().split()))
def LIR(n): return [LI() for _ in range(n)]

n,d = LI()
x = LIR(n)
ans = 0
for i in range(1,n):
    for j in range(i):
        sum = 0
        for k in range(d):
            sum +=(x[i][k] - x[j][k])**2
        if sum**(1/2) % 1 == 0:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
from math import sqrt
N,D = map(int, input().split())
L = []
for i in range(N):
    L.append([int(i) for i in input().split()])
ans = 0
for i in range(N):
    for j in range(N):
        if i >= j:
            continue
        a = L[i]
        b = L[j]
        e = sqrt(sum([abs(c-d)**2 for c, d in zip(a, b)]))
        if e == int(e):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

import math

n, d = getList()

zahyo = [getList() for i in range(n)]

ans = 0

for i in range(n):
    for j in range(i+1, n):
        tmp = 0
        va = zahyo[i]
        vb = zahyo[j]
        for dim in range(d):
            tmp += (vb[dim] - va[dim]) ** 2

        base = int(math.sqrt(tmp))
        if base ** 2 == tmp:
            ans += 1
            # print(va, vb)

print(ans)

Submission status: Accepted

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

def dis(A, B):
    s = 0
    for a, b in zip(A, B):
        s += (b - a) ** 2
    return s ** 0.5

res = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        dist = dis(P[i], P[j])
        if dist - int(dist) < 10 ** -8:
            res += 1
print(res)

Submission status: Accepted

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

ans = 0
for i in range(N):
    Xi = Xss[i]
    for j in range(i+1, N):
        Xj = Xss[j]
        dist = 0
        for k in range(D):
            dist += (Xi[k]-Xj[k])**2
        if dist**0.5 == int(dist**0.5):
            ans += 1

print(ans)

Submission status: Accepted

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

ans = 0
for i in range(N):
  for j in range(i):
    t = sum((X[i][k]-X[j][k])**2 for k in range(D))
    if int(t**0.5+0.01)**2==t:
      ans += 1
print ans

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
x_array = [[int(x) for x in input().split()] for y in range(n)]
cnt = 0
for i in range(n):
    for j in range(i+1, n):
        if i == j:
            continue
        tmp_i = x_array[i]
        tmp_j = x_array[j]
        tmp = sum([abs(x-y)**2 for x, y in zip(tmp_i, tmp_j)])
        if tmp ** 0.5 %1 == 0:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
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)
#print(X)
ans = 0
for i in range(n):
    for j in range(i+1,n):
        #print(i,j)
        sq = np.sqrt(sum((X[j]-X[i])**2))
        #print(sq)
        if sq == int(sq):
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
def dist(X1, X2):
    return sum((x1 - x2)**2 for x1, x2 in zip(X1, X2))

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

sq = set(i**2 for i in range(10**5))

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations

def sqdist(X, Y):
    temp = 0
    for x, y in zip(X, Y):
        temp += (x - y)**2
    return temp

N, D = map(int, input().split())
points = [tuple(map(int, input().split())) for _ in range(N)]
ans = 0
for x, y in combinations(points, 2):
    d2 = sqdist(x, y)
    if d2 == int(d2**0.5)**2: 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)]

def dist(a, b):
    return math.sqrt(sum([(a[i] - b[i])**2 for i in range(d)]))

ans = 0
for i in range(n):
    for j in range(i+1, n):
        y = x[i]
        z = x[j]
        w = dist(y, z)
        # print(w, int(w), w == int(w))
        if w == int(w):
            ans += 1

# print(x)
print(ans)

Submission status: Accepted

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

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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

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

ans = 0
for n1 in range(N - 1):
    for n2 in range(n1 + 1, N):
        v1 = vectors[n1]
        v2 = vectors[n2]
        dist2 = 0
        for e1, e2 in zip(v1, v2):
            dist2 += (e1 - e2) ** 2
        tmp = int(round(math.sqrt(dist2)))
        if tmp * tmp == dist2:
            ans += 1
print(ans)