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

def distance(A, B):
    s = sum((a-b)**2 for a, b in zip(A, B))
    s = sqrt(s)
    return s

def solve(N, D, X):
    c = 0
    for i in range(N):
        for j in range(i+1, N):
            d = distance(X[i], X[j])
            if float(int(d)) == d:
                c+=1
    return c

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

    print(solve(N, D, X))

main()

Submission status: Accepted

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

cnt = 0
for i in range(n-1):
    for j in range(i+1, n):
        distance = 0
        for k in range(d):
            distance += (x[i][k]-x[j][k])**2
        distance = distance**0.5
        if distance%1==0:
            cnt+=1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

def distance(A, B):
    d = 0
    for i in range(D):
        d += (A[i] - B[i])**2
    return math.sqrt(d)

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,d = map(int,input().split())
x = []
for _ in range(n):
  xi = list(map(int,input().split()))
  x.append(xi)
def dis(a,b,d):
  s = 0
  for i in range(d):
    s += (a[i] - b[i])**2
  return s
count = 0
for i in range(n-1):
  for j in range(i+1,n):
    e = dis(x[i],x[j],d)
    ed = e**(1/2)
    if (ed - int(ed)) == 0:
      count += 1
print(count)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
s=[]
for i in range(n):
    s.append(list(map(int,input().split())))
dis=[]
for i in range(n):
    for j in range(i+1,n):
        D=0
        for k in range(d):
            D+=(s[i][k]-s[j][k])**2
        dis.append(D**(1/2))
cnt=0
for i in range(len(dis)):
    if dis[i]%1==0:
        cnt+=1
print(cnt)

Submission status: Accepted

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

arr=[]
for i in range(N):
    for j in range(N):
        if i < j:
            dist_l=[]
            for d in range(D):
                dist_l.append((X[i][d]-X[j][d])**2)
            arr.append(sum(dist_l)**(1/2))

print(sum(list(map(lambda x: x%1==0,arr))))

Submission status: Accepted

Solution code:
from math import sqrt

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):
        tmp = 0
        for k in range(d):
            tmp += (x[i][k] - x[j][k]) ** 2
        s = sqrt(tmp)
        if s - int(s) == 0:
            count += 1

print(count)

Submission status: Accepted

Solution code:
from math import sqrt
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 k in range(D):
            dist += (X[i][k] - X[j][k])**2
        if sqrt(dist).is_integer():
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

# n = int(input())
# a, b
# s = input()

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


def dist(l1, l2):
    res = 0
    for i in range(1, D+1):
        tmp = (l1[i] - l2[i])
        res += tmp * tmp
    return res


#
ans = 0
for i in range(1, N+1):
    for j in range(i+1, N+1):
        tmp = dist(X[i], X[j])
        k = 0
        while k * k <= tmp:
            if k * k == tmp:
                ans += 1
            k += 1
print(ans)

Submission status: Accepted

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


def dist2(pos1, pos2):
    return sum([(p - q)**2 for p, q in zip(pos1, pos2)])


ans = 0
for i in range(N):
    for j in range(i + 1, N):
        dist = dist2(Positions[i], Positions[j])
        if int(dist**0.5)**2 == dist:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
from math import sqrt
n, d = map(int, input().split())
X = []
ans = 0
for _ in range(n):
    x = [int(i) for i in input().split()]
    X.append(x)

for i in range(n):
    for j in range(i+1,n):
        Y = X[i]
        Z = X[j]
        d = sqrt(sum([(y-z)**2 for y,z in zip(Y, Z)]))
        if divmod(d,1)[-1] == 0:
            ans += 1
            
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())))
    
ans = 0
for idx, point in enumerate(x):
    for idx2 in range(idx+1, len(x), 1):
    
        norm =  np.linalg.norm(np.asarray(point) - np.asarray(x[idx2]))
        if norm % 1 == 0:
            ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,D = map(int,input().split())
X = [[int(x) for x in input().split()] for i in range(N)]
ans = 0
for i in range(N):
  for j in range(N):
    d = 0
    if i != j:
      for k in range(D):
        d += (X[i][k]-X[j][k])**2
      d = d ** (1/2)
      if int(d) == d:
        ans += 1
print(int(ans/2))

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
xs = list()
for i in range(n):
    x = list(map(int, input().split()))
    xs.append(x)


def is_valid(k):
    for i in range(200):
        m = i ** 2
        if k == m:
            return True
        elif k < m:
            return False
    
    return False


ans = 0
for i in range(n):
    for j in range(i + 1, n):
        s = 0
        for e in range(d):
            s += (xs[i][e] - xs[j][e]) ** 2
        if is_valid(s):
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math
a,b = list(map(int, input().split()))

xs = []
for i in range(a):
    x = list(map(int, input().split()))
    xs.append(x)
ans = 0
for i in range(a):
    for j in range(a):
        if(i>=j):
            continue
        dist = 0
        for k in range(b):
            dist+= (xs[i][k]-xs[j][k])**2
        dist = math.sqrt(dist)
        if(dist%1==0):
            ans +=1
            
print(ans)

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
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 _pf(s): return print(s, flush=True)

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

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

Submission status: Accepted

Solution code:
from math import *

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

ans = 0
for i in range(N):
    for j in range(i+1, N):
        d2 = 0
        for k in range(D):
            d2 += (X[i][k] - X[j][k])**2
        if sqrt(d2)*10%10 == 0:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
n,d=map(int, input().split())
x=[list(map(int, input().split())) for i in range(n)]
count=0
for i in range(n):
    for j in range(n):
        if i== j or i>j:continue
        num=0    
        for k in range(d):
            num+=(x[i][k]-x[j][k])**2
        if abs(int(num**0.5)-num**0.5)<0.001:
            #print(x[i],x[j],num)
            count+=1
print(count)

Submission status: Accepted

Solution code:
import sys
import math
from itertools import combinations

fin = sys.stdin.readline
N, D = [int(elem) for elem in fin().split()]
x_list = [[int(elem) for elem in fin().split()] for _ in range(N)]


def checkInteger(y, z):
    sum_all = 0
    for i in range(len(y)):
        sum_all += (y[i] - z[i]) ** 2
    return math.sqrt(sum_all).is_integer()


count_all = 0
for each_combi in combinations(x_list, 2):
    if checkInteger(each_combi[0], each_combi[1]):
        count_all += 1

print(count_all)

Submission status: Accepted

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

x=[]

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

def K(a1,a2):
    return math.sqrt(sum(map(lambda x:pow(x[0]-x[1],2),zip(a1,a2))))

A=0

for i in range(N):
    for j in range(i+1,N):
        temp=K(x[i],x[j])
        if temp==math.floor(temp):
            A+=1

print(A)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, a, b = LI()
    print(min(n * a, b))
    return

#B
def B():
    n, d = LI()
    x = LIR(n)
    a = list(itertools.combinations(range(n), 2))
    ans = 0
    for a1,a2 in a:
        b = 0
        for bi in range(d):
            b += (x[a1][bi] - x[a2][bi])** 2
        if float.is_integer(math.sqrt(b)):
            ans += 1
    print(ans)
    return

#C
def C():
    l, r = LI()
    if l // 2019 == r // 2019:
        print((l * (l + 1)) % 2019)
    else:
        print(0)
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Accepted

Solution code:
import sys
from math import sqrt

input = sys.stdin.readline

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

count = 0
for i in range(N - 1):
    for j in range(i+1, N):
        p1 = points[i]
        p2 = points[j]
        dist = sqrt(sum((x - y) ** 2 for x, y in zip(p1, p2)))
        if int(dist) == dist:
            count += 1

print(count)

Submission status: Accepted

Solution code:
import math

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

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

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

            y = int(math.sqrt(sum))
            if y**2 == sum:
                count +=1

print(count)

Submission status: Accepted

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

def isint(a, b):
    s = 0
    for i in range(D):
        s += (X[a][i]-X[b][i])**2
    if int(s**0.5+0.5) ** 2 == s:
        return 1
    return 0

ans = 0
for a in range(N):
    for b in range(a+1, N):
        ans += isint(a, b)
print(ans)

Submission status: Accepted

Solution code:
import math

n, d = (int(_) for _ in input().split())

xlist=[]

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

kotae=0

for i in range(n):
    for j in range(n-i-1):
        a=i
        b=i+j+1
        kyori=0
        for k in range(d):
            kyori+=(xlist[a][k]-xlist[b][k])**2
        kyori2=math.sqrt(kyori)
        if kyori2==int(kyori2):
            kotae+=1

print(kotae)

Submission status: Accepted

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

count = 0
for i in range(n):
    for j in range(n):
        if i != j:
            d = np.linalg.norm(x[i] - x[j])
            if math.floor(d) == d:
                count += 1
print(count//2)

Submission status: Accepted

Solution code:
from math import sqrt
N,D = list(map(int, input().split()))
P = []
for i in range(N):
  P.append( list(map(int, input().split())) )
  
def dist(a,b):
  ret = 0
  for i in range(D):
    ret += (a[i] - b[i]) ** 2
  return ret

ans = 0
for i in range(N):
  for j in range(i+1,N):
    work = sqrt(dist(P[i], P[j]))
    if abs(int(work) - work) < 1e-11:
      ans += 1
      
print(ans)

Submission status: Accepted

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

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

def solve(N: int, D: int, X: "List[List[int]]"):
    count = 0
    for i in range(N):
        for j in range(i+1, N):
            dist = distance(X[i], X[j])
            if dist % 1 == 0:
                count += 1
            else:
                pass
    print(count)
    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:
# -*- coding: utf-8 -*-

import math

def readInts():
  return [int(s) for s in input().split(" ")]

def isDistanceInt(X1, X2):
  d = 0
  for i in range(len(X1)):
    d += (X1[i] - X2[i]) ** 2

  dr = int(math.sqrt(d))
  return dr ** 2 == d

def main():
  N, D = readInts()
  Xs = [readInts() for _ in range(N)]
  ans = 0
  for i in range(N-1):
    for j in range(i+1, N):
      if isDistanceInt(Xs[i], Xs[j]):
        ans += 1
  print(ans)


if __name__ == "__main__":
  main()

Submission status: Accepted

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

from itertools import combinations

pairs = list(combinations(X, 2))

res = 0
for pair in pairs:
    d = 0
    for i in range(D):
        d += (pair[0][i] - pair[1][i])**2
    d = d**0.5
    if int(d) == d:
        res += 1

print(res)

Submission status: Accepted

Solution code:
import math

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


def distisint(a, b):
    dsq = 0
    for i in range(D):
        dsq += (Xs[a][i] - Xs[b][i]) ** 2
    d = math.sqrt(dsq)
    return math.floor(d) ** 2 == dsq


c = 0
for i in range(0, N - 1):
    for j in range(i + 1, N):
        if distisint(i, j):
            c += 1
print(c)

Submission status: Accepted

Solution code:
import sys, math

def input(): return sys.stdin.readline()[:-1]
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 MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
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

def main():
    N, D = MAP()
    X = MATINT(N)
    count = 0
    for i in range(N - 1):
        for j in range(i + 1, N):
            sum = 0
            for d in range(D):
                sum += (X[i][d] - X[j][d])**2
            ans = math.sqrt(sum)
            if ans * 10 % 10 == 0:
                count += 1
    print(count)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
n, d = map(int, input().split())
dat_x = []
for i in range(n):
    l = map(int, input().split())
    l = list(l)
    dat_x .append((l))
res = 0
for i in range(n):
    for j in range(n):
        if i == j:
            break
        s = 0
        for k in range(d):
            s += (dat_x[i][k] - dat_x[j][k]) * (dat_x[i][k] - dat_x[j][k])
        #print(s)
        t = math.sqrt(s)
        if t.is_integer():
            #print("{0} {1}".format(i, j))
            res += 1
print(res)

Submission status: Accepted

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

ans=0
import itertools
for i,j in itertools.combinations(range(n),2):
    res=0
    for k in range(d):
        res+=(x[i][k]-x[j][k])**2
    q=res**0.5
    if q==q*10//10:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
point=[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):
        now=0
        for k in range(d):
            now+=(point[i][k]-point[j][k])**2
        if int(now**0.5)**2==now:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
x=[[int(a) for a in input().split()] for _ in range(n)]
ans = 0
for i in range(n):
    for j in range(i+1,n):
        s = sum([(a-b)*(a-b) for a,b in zip(x[i],x[j])])
        t = int(s**.5)
        if s == t*t:
            ans +=1
print(ans)

Submission status: Accepted

Solution code:
import math
def cal_dis(a,b):
    out = 0
    for i in range(len(a)):
        out += (a[i]-b[i])**2
    return out


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

cnt = 0
for i in range(n):
    for j in range(i+1,n):
        distanse = cal_dis(points[i],points[j])
        if math.sqrt(distanse)%1 ==0:
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)

debug = True
debug = False


def dprint(*objects):
    if debug == True:
        print(*objects)



def solve():
    N, D = map(int, input().split())
    x_list = []
    for i in range(N):
        x_list.append(list(map(int, input().split())))

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

    import math
    cnt = 0
    for i in range(N):
        for j in range(i+1, N):
            d = math.sqrt(dist(x_list[i], x_list[j]))

            if d - int(d) == 0:
                cnt += 1

    print(cnt)
solve()

Submission status: Accepted

Solution code:
import math

def issq(x):
    sx = int(math.sqrt(x))
    return any([
        (sx - 1)**2 == x,
        sx**2 == x,
        (sx + 1)**2 == x,
    ])


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


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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

l = []
cnt = 0
for _ in range(N):
    if len(l) == 0:
        l.append([int(x) for x in input().split()])
    else:
        new_point = [int(x) for x in input().split()]
        for known_point in l:
            sum_val = 0
            for i in range(D):
                sum_val += (new_point[i] - known_point[i]) ** 2

            root = math.sqrt(sum_val)
            if root == int(root):
                cnt += 1

        l.append(new_point)

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, itertools
N,D = map(int, input().strip().split(' '))

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

X = [list(map(int, line.strip().split(' '))) for line in sys.stdin]

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

Submission status: Accepted

Solution code:
import math
N, D = (int(i) for i in input().split())
e = [[int(i) for i in input().split()] for i in range(N)]
count = 0
for i in range(N):
    for j in range(i+1, N):
        total = 0
        for k in range(D):
            total += (e[i][k]-e[j][k])**2
        if math.sqrt(total).is_integer():
            count +=1

print(count)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

def is_square(N):
    for i in range(1000):
        if i * i == N:
            return True
    return False

def dist(X1, X2):
    ans = 0
    for i in range(len(X1)):
        ans += (X1[i] - X2[i]) ** 2
    return ans

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

Submission status: Accepted

Solution code:
N,D = map(int,input().split())
d = {}
for i in range(40*4):
    d[i**2] = 0

def dist(y,z):
    res = 0
    for i in range(D):
        res += (y[i]-z[i])**2
    return res
ans = 0
X = [list(map(int,input().split())) for _ in range(N)]
for i in range(N):
    for j in range(i+1,N):
        d2 = dist(X[i],X[j])
        if d2 in d:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n, d = li()
x = [list(li()) for _ in range(n)]

SQUARE = set([i * i for i in range(10000)])
ans = 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 in SQUARE:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
# Setup
import sys
import math
import copy
sys.setrecursionlimit(4100000)

n,d = [int(i) for i in input().split()]
x = [[int(i) for i in input().split()] for i in range(n)]
counter = 0
for i in range(n):
    for k in range(i+1,n):
        current = 0

        for a in range(d):
            current += abs(x[i][a] - x[k][a])**2
        current = math.sqrt(current)
        if current.is_integer():
            counter += 1
print(counter)

Submission status: Accepted

Solution code:
from math import sqrt

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

count = 0

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

Submission status: Accepted

Solution code:
#    !/usr/bin/env python3
#    encoding: UTF-8
#    Modified: <07/Jul/2019 05:37:20 PM>


#    ✪ H4WK3yE乡
#    Mohd. Farhan Tahir
#    Indian Institute Of Information Technology (IIIT), Gwalior


import sys
import os
from io import IOBase, BytesIO


def dis(A, B):
    l = len(A)
    ans = 0
    for i in range(l):
        ans += (A[i] - B[i])**2
    return ans


def main():
    n, d = get_ints()
    arr = [0] * n
    for i in range(n):
        arr[i] = get_array()
    from math import floor, sqrt
    ans = 0
    for i in range(n):
        for j in range(i + 1, n):
            dist = dis(arr[i], arr[j])
            x = floor(sqrt(dist))
            if x**2 == dist:
                ans += 1
    print(ans)


BUFSIZE = 8192


class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill():
            pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill()
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        py2 = round(0.5)
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2 == 1:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode("ascii"))
            self.read = lambda: self.buffer.read().decode("ascii")
            self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)


def get_array(): return list(map(int, sys.stdin.readline().split()))


def get_ints(): return map(int, sys.stdin.readline().split())


def input(): return sys.stdin.readline().strip()


if __name__ == "__main__":
    main()

Submission status: Accepted

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