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
from bisect import *
from collections import *
from heapq import *
from itertools import *
from math import *
from operator import *
import numpy as np

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    N,D = map(int, input().split())
    XS = [list(map(int, input().split())) for _ in range(N)]
    ans = 0
    for i,j in combinations(XS, 2):
        total = sum([(x-y)**2 for x,y in zip(i,j)])
        if total == floor(sqrt(total))**2: ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
n,d=map(int,input().split())
v=[]
for i in range(n):
  v.append(np.array(list(map(int,input().split()))))
  
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    dist=np.linalg.norm(v[i]-v[j], ord = 2)
    if int(dist) == dist:
      ans += 1

print(ans)

Submission status: Accepted

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

count = 0
for i in range(N-1):
  for j in range(i+1,N):
    dist = 0
    for m in range(D):
      dist += (x[i][m] - x[j][m]) **2
    if (dist ** 0.5) % 1 == 0:
      count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

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

X_arr = np.array(X_lis)

count = 0

for i in range(N):
    for j in range(i+1, N):
        squared_d = np.sum((X_arr[i] - X_arr[j]) ** 2)
        if (squared_d)**(1/2) == int(squared_d**(1/2)):
            count += 1

print(count)

Submission status: Accepted

Solution code:
while True:
    try:
        N, D = map(int, input().split())
        P = []
        for i in range(N):
            P.append(list(map(int, input().split())))
            
        ans = 0
        for i in range(N-1):
            for j in range(i+1, N):
                distance = 0
                for k in range(D):
                    distance += (P[i][k] - P[j][k]) ** 2
                if distance == int(distance ** 0.5) ** 2:
                    ans += 1
        print(ans)
    except:
        break

Submission status: Accepted

Solution code:
import math
N,D = map(int,input().split())
L = [list(map(int, input().split())) for i in range(N)]
c = 0
for i in range(N):
    for j in range(i+1,N):
        di = 0
        for k in range(D):
            di += (L[i][k]-L[j][k])**2
        if math.sqrt(di).is_integer():
            c += 1 
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
import itertools

if __name__ == '__main__':
    N, D = map(int, input().split())
    X = [list(map(int, input().split())) for _ in range(N)]
    count = 0
    for x in itertools.combinations(X,2):
        m = math.sqrt(sum( [ ((x[0][i] - x[1][i]) ** 2) for i in range(D)] ))
        if m.is_integer():
            count += 1
    print(count)

Submission status: Accepted

Solution code:
def distance(y,z):
    ans = 0
    for i,j in zip(y,z):
        ans += (i - j)**2
    return ans**0.5

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

for i in range(n-1):
    for j in range(i+1, n):
        tmp = distance(x_arr[i],x_arr[j])
        if tmp//1 == tmp:
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
n, d = list(map(int, input().split()))
x = [list(map(int,input().split())) for _ in range(n)]
num = 0
for i in range(n):
    for j in range(i + 1, n):
        dis = 0
        for k in range(d):
            dis += (x[i][k] - x[j][k]) ** 2
        root = dis ** 0.5
        if root.is_integer():
            num += 1
print(num)

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

for i in range(n):
    if i < n-1:
        for j in range(i+1, n):
            s = 0
            for t in range(d):
                s += np.power((x[j][t]-x[i][t]), 2)
            if np.sqrt(s).is_integer():
                ans += 1

print(ans)

Submission status: Accepted

Solution code:
def sq(x,y):
    tot = 0
    for i in range(D):
        tot += (x[i]-y[i])**2
    return tot
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):
        x = X[i]
        y = X[j]
        if abs(round(sq(x,y)**0.5,1)**2-sq(x,y))<10**(-8):
            cnt += 1
print(cnt)

Submission status: Accepted

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

ans=0
for i in range(N-1):
  for j in range(i+1,N):
    sum=0
    for p in range(D):
      sum=sum+(d[i][p]-d[j][p])**2
    if (math.sqrt(sum)).is_integer():
      ans=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)]
counter = 0
for i in range(n):
    for j in range(i+1, n):
        dif = [(x[i][di] - x[j][di])**2 for di in range(d)]
        sumdif = sum(dif)
        if sumdif == int(math.sqrt(sumdif))**2:
            counter += 1
print(counter)

Submission status: Accepted

Solution code:
N,D = list(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):
    a = 0
    for d in range(D):
      a += (X[i][d]-X[j][d])**2
    for l in range(a+1):
      if l**2==a:
        ans+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

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

clist=list(itertools.combinations(x,2))
res=0
for c in clist:
  dist=sum([(c[0][i]-c[1][i])**2 for i in range(len(c[0]))])**0.5
  if dist==int(dist):
    res+=1
print(res)

Submission status: Accepted

Solution code:
from sys import exit, stderr, stdin
input = stdin.readline
def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return


def main():
    N,D = [int(n) for n in input().split()]
    ans = 0
    X = [[0 for __ in range(D)] for _ in range(N)]
    for i in range(N):
        X[i] = [int(n) for n in input().split()]
    # print(X)
    for i in range(N):
        d = 0
        for j in range(i+1,N):
            d = sum([pow(y-z,2) for y,z in zip(X[i],X[j])])
            # print(d)
            d **= 0.5
            if d/1 == d//1:
                ans += 1
    print(ans)
if __name__ == "__main__":
    main()

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

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
a = [[int(i) for i in input().split()] for i in range(n)]
ans = 0
def dis(x,y):
    T = []
    for i in range(len(x)):
        T.append((x[i]-y[i])**2)
    return sum(T)
for i in range(n):
    for j in range(i+1,n):
        r = dis(a[i], a[j])
        for k in range(r + 1):
            if k ** 2 == r:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math
import numpy as np
n, d = map(int, input().split())
a = []
cnt = 0
for x in range(n):
    a.append(list(map(int, input().split())))
for i in range(len(a)):
    for j in range(len(a)):
        if i < j:
            dis = np.array(a[i]) - np.array(a[j])
            if np.linalg.norm(dis).is_integer():
                cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import math
n,d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
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
    l = math.sqrt(temp)
    if l.is_integer():
      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)]
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
    l = math.sqrt(temp)
    if l % 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())))

x = np.array(x)

count =	0
for i in range(n):
    for j in range(i+1, n):
        dist = np.linalg.norm(x[i] - x[j])
        if dist == int(dist):
            count += 1

print(count)

Submission status: Accepted

Solution code:
n,d = map(int,input().split())
co = []
for i in range(n):
    co.append(tuple(int(j) for j in input().split()))
flag = 0
for i in range(n):
    for j in range(i+1,n):
        sq = 0
        for k in range(d):
            sq = sq + (co[i][k]-co[j][k])**2
        sqrt = sq**(1/2)
        if float(int(sqrt)) == sqrt:
            flag = flag + 1

print(flag)

Submission status: Accepted

Solution code:
import numpy as np
N,D=map(int,input().split())
A=[]
for i in range(N):
    B=list(map(int,input().split()))
    A.append(B)

all_diffs = np.expand_dims(A, axis=1) - np.expand_dims(A, axis=0)
degree_distance = np.sqrt(np.sum(all_diffs ** 2, axis=-1))

Q=0
for i in range(N):
    for j in range(N):
        if degree_distance[i][j].is_integer()==True:
            Q+=1
            
        
print(int((Q-N)/2))

Submission status: Accepted

Solution code:
n, d = input().split()
a = []
#print(a)
pair = 0
for i in range(int(n)):
    a.append(input().split())
#print('\n', a, '\n')
for i in range(int(n)):
    for j in range(i+1, int(n)):
        t = 0
        for k in range(int(d)):
           # print(int(a[i][k]) , int(a[j][k]))
            t+=(int(a[i][k]) - int(a[j][k])) * (int(a[i][k]) - int(a[j][k]))

        t**=0.5
        if t == int(t):
            pair += 1
print(pair)

Submission status: Accepted

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

def jadge(one ,two):
    z = 0
    for i in range(d):
        z += (one[i] - two[i]) ** 2
    z = math.sqrt(z)
    if z == int(z):
        return 1
    else:
        return 0
for one in range(n-1):
    for two in range(one+1,n):
        ans += jadge(x[one], x[two])
print(ans)

Submission status: Accepted

Solution code:
from math import sqrt


def distance_calculator(coordinates1, coordinates2, d):
    distance = 0
    for i in range(d):
        distance += (coordinates1[i] - coordinates2[i]) ** 2
    return sqrt(distance)


n, d = map(int, input().split())
points = [[]] * n
for i in range(n):
    points[i] = list(map(int, input().split()))
answer = 0
for i in range(n):
    for j in range(i + 1, n):
        distance = distance_calculator(points[i], points[j], d)
        if int(distance) == distance:
            answer += 1
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from math import ceil
from operator import itemgetter as get

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

def iinput():
    return int(input())

def finput():
    return float(input())

def tinput():
    return input().split()

def rinput():
    return map(int, tinput())

def rlinput():
    return list(rinput())

def nod(a, b):
    while b: 
        a, b = b, a % b
    return a
 
def calc(n, c, d):
    return n - n // c - n // d + n // (c * d // nod(c, d))   


def main():
    res, x = 0, []
    n, d = rinput()
    for i in range(n):
        x.append(rlinput())
     
    for o in range(n - 1):
        for u in range(o + 1, n):
            if ((sum((i - j) ** 2 for i, j in zip(x[o], x[u]))) ** 0.5).is_integer():
                res += 1
    print(res)
main()

Submission status: Accepted

Solution code:
import math

n,d = map(int,input().split())
x_list = []
count = 0
sum = 0
dist = 0
for i in range(n):
    x_list.append(list(map(int,input().split())))
for i in range(n-1):
    for j in range(i+1,n):
        for k in range(d):
            sum += (x_list[i][k] - x_list[j][k])**2
        if math.sqrt(sum) % 1 ==0:
            count += 1
        sum = 0    
print(count)

Submission status: Accepted

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

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

count = 0 
for i in range(n-1):
	for j in range(i+1, n):
		dist = math.sqrt(sum(pow(points[i][k] - points[j][k], 2) for k in range(d)))
		if dist == int(dist):
			count += 1
print(count)

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# 初項s, 交差dのn個の数列の和
def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def func(x1, x2):
    r = 0
    for i in range(len(x1)):
        r += (x1[i] - x2[i]) ** 2

    a = int(sqrt(r))
    return a ** 2 == r or (a - 1) ** 2 == r or (a + 1) ** 2 == r


def main():
    N, D = map(int, input().split())

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

    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            ans += func(dot[i], dot[j])
    print(ans)


if __name__ == '__main__':
    main()

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 i in range(n)]

cnt = 0
for i in range(n):
    for j in range(i+1,n):
        dd = 0
        for d_ in range(d):
            diff = x[i][d_] - x[j][d_]
            dd += diff**2
        if math.sqrt(dd).is_integer():
            cnt += 1
        

print(cnt)

Submission status: Accepted

Solution code:
import math
n, d = map(int, input().split())
x = [None]*n
ans = 0

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

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

Submission status: Accepted

Solution code:
import math

n,d = map(int,input().split())
loc = [list(map(int,input().split())) for _ in range(n)]
dis = []
ans = 0
for i in range(n):
  for j in range(i+1,n):
    dis_k = 0
    for k in range(d):
      dis_k += (loc[i][k]-loc[j][k])**2
    dis.append(dis_k)
    
for d in dis:
  for i in range(1,math.ceil(math.sqrt(d))+1):
    if i**2 ==d:
      ans += 1
      break
    else:
      pass
    
print(ans)

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
X=[list(map(int,input().split())) for i in range(N)]
c=0
for i in range(N-1):
    for j in range(i+1,N):
        c += (sum((a-b)**2 for a,b in zip(X[i],X[j]))**0.5).is_integer()
print(c)

Submission status: Accepted

Solution code:
nd=list(map(int,input().split()))
listx=[]
count=0#整数型の個数をカウント
for i in range(nd[0]):
    listx=listx+[list(map(int,input().split()))]
for i in range(nd[0]-1):
    for k in range(i+1,nd[0]):
        d2=0
        for n in range(nd[1]):
            d2+=(listx[i][n]-listx[k][n])**2
        if float.is_integer(d2**0.5)==True:
                count+=1
print(count)

Submission status: Accepted

Solution code:
import math

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from math import sqrt

count = 0
n, d = map(int, input().split())
x = [[int(xx) for xx in input().split()] for _ in range(n)]

for y in range(n - 1):
    for z in range(y + 1, n):
        if sqrt(sum((i - j) ** 2 for i, j in zip(x[y], x[z]))).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 _ in range(N)]

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
import sys
import math
from copy import deepcopy
from collections import deque
sys.setrecursionlimit(20000000)


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

    count = 0

    def diff(a, b):
        sm = 0
        for i in range(D):
            sm += ((a[i] - b[i]) ** 2)

        return sm

    for p in range(len(P) - 1):
        s = 0
        for x in range(p+1, len(P)):
            s = diff(P[p], P[x])

            if str(s**0.5)[-1] == '0':
                count += 1

    print(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math as m

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

count = 0

for i in range(n-1):
	for j in range(i+1, n):
		acc = 0
		for k in range(d):
			acc += (lp[j][k] - lp[i][k]) ** 2
		
		if m.sqrt(acc).is_integer():
			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)]

cnt = 0
dst = 0

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

cnt = 0
dst = 0

for i in range(N):
    for j in range(i+1, N):
        dst = 0
        for k in range(D):
            dst += (X[i][k] - X[j][k]) ** 2
        if int(dst ** 0.5) ** 2 == dst:
            cnt += 1
        
print(cnt)

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(i+1,N):
        y = X[i]
        z = X[j]
        l = 0
        for Y, Z in zip(y, z):
            l += (Y-Z)**2
        for k in range(1,8001):
            if l** (1/2) == k:
                ans += 1
                break
print(ans)

Submission status: Accepted

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

ans = 0

for i in range(n):
    for j in range(i+1, n):
        left = l[i]
        right = l[j]
        sm = sum(list(map(lambda x,y: pow(x-y, 2), left, right)))

        result = pow(sm, 1/2)
        if result.is_integer():
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
N, D = map(int,input().split())
K = [list(map(int,input().split()))for x in range(N)]
ans = 0
for i in range(N-1):
  for j in range(i+1,N):
    goukei=0
    for a,b in zip(K[i],K[j]):
      goukei += (a-b)**2
    ans += (goukei**0.5).is_integer()
print(ans)

Submission status: Accepted

Solution code:
def distance(Y,Z):
    sum = 0
    for y,z in zip(Y,Z):
        tmp = y-z
        tmp = tmp*tmp
        sum += tmp
    return sum**0.5

cnt = 0
N,D = map(int,input().split())
i = 0
X = []
while(i < N):
    X.append(list(map(int,input().split())))
    i += 1
i = 0
while(i < N-1):
    j = i+1
    while(j < N):
        if distance(X[i],X[j]).is_integer():
            cnt += 1
        j += 1
    i += 1
print(cnt)

Submission status: Accepted

Solution code:
import math
N, M = (int(a) for a in input().split())
X = [list(map(int,input().split())) for i in range(N)]
count = 0
for i in range(N-1):
    for j in range(i+1,N):
        sum = 0
        squ = 0
        for k in range(M):
            sum += abs(X[j][k]-X[i][k])**2
        squ = pow(sum,0.5)
        if math.ceil(squ) == math.floor(squ):
            count += 1
print(count)

Submission status: Accepted

Solution code:
m = list(map(int,input().split()))
l = [list(map(int,input().split())) for i in range(m[0])]

from itertools import combinations
import math

k =list(combinations(l,2))

c=0
for i in range(len(k)):
      dis = 0
      for x in range(m[1]):
          dis = dis + (k[i][0][x] - k[i][1][x])**2
      dis = math.sqrt(dis)
      if dis == int(dis):
          c=c+1
      else:
          c=c      
print(c)

Submission status: Accepted

Solution code:
N,D = map(int,input().split())
X = [0]+[list(map(int,input().split()))for _ in range(N)]
List = []
ans = 0
for j in range(1,N):
    for i in range(j+1,N+1):
        v = 0
        for k in range(D):
            v+=(X[j][k]-X[i][k])**2
        for l in range(v+1):
            List.append(l**2)
        if v in List:
            ans+=1
      
            
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N, D = map(int, input().split())
x = []
m = 0
for _ in range(N):
    x.append(list(map(int, input().split())))
for i in range(N):
    for j in range (i):
        d = np.sqrt(sum((x[i][k]-x[j][k])**2 for k in range(D)))
        if d.is_integer():
            m += 1
print(m)

Submission status: Accepted

Solution code:

def f_b():
    n, d = map(int, input().split())
    x = []
    stack = []
    c = 0

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

    for i in range(n):
        xi = x[i]
        for xj in stack:
            d = 0
            for y, z in zip(xi, xj):
                d += (y-z)**2
            if (d**0.5)%1==0:
                c += 1
        stack.append(xi)

    print(c)

if __name__ == "__main__":
    f_b()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, d = list(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 a, b in zip(x[i], x[j]):
            tmp += (a-b)**2
        ans += (tmp**0.5).is_integer()

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n,d =map(int,input().split())
l=[]
ans=0
for i in range(n):
    l.append(list(map(int,input().split())))
for i in range(n):
    for j in range(i):
        z=0
        for k in range(d):
            z+=(l[i][k]-l[j][k])**2
        if float(np.sqrt(z)).is_integer():
            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)]
c=0
for i in range(N-1):
  for j in range(i+1,N):
    c += (sum((a-b)**2 for a,b in zip(X[i],X[j]))**0.5).is_integer()
print(c)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
w=[]
for i in range(n):
    l=[int(i) for i in input().split()]
    w.append(l)
ans=0
chk=set([int(i)**2 for i in range(0,401,1)])
for i in range(n-1):
    for j in range(i+1,n):
        cnt=0
        for k in range(d):
            cnt+=(w[i][k]-w[j][k])**2
        if cnt in chk:
            ans+=1
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
import math
number = list(map(int,input().split()))
n = number[0]
d = number[1]
number_list = []
for i in range(n):
    number_list.append(list(map(int,input().split())))
count = 0
sum = 0
for i in range(n):
    for j in range(i+1,n):
        for k in range(d):
            sum += (number_list[i][k]-number_list[j][k])**2
        distance = math.sqrt(sum)
        if list(str(distance))[-1] == "0":
            count += 1
        sum = 0
print(count)

Submission status: Accepted

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

count=0
i=0
while i<n-1:
  j=i+1
  while j<n:
    temp=0
    k=0
    while k<d:
      temp+=(int(r[i][k])-int(r[j][k]))**2
      k+=1
    if temp**(1/2)==temp**(1/2)//1:
      count+=1
    j+=1
  i+=1
  
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
from itertools import combinations
l=[]
ans=0
for i in range(N):
  l.append(list(map(int,input().split())))
for m,n in combinations(l,2):
  sv=0
  for a in range(D):
    sv+=(abs(m[a]-n[a]))**2
  if sv**(1/2)%1==0:
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
import math

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


def dist2(pt0, pt1):
    d = 0
    for x0, y0 in zip(pt0, pt1):
        d += (x0 - y0)**2
    return d


count = 0
for i in range(n):
    for j in range(i + 1, n):
        d2 = dist2(pts[i], pts[j])
        if int(math.sqrt(d2))**2 == d2:
            count += 1
print(count)

Submission status: Accepted

Solution code:
n,d = map(int,input().split())
X = [list(map(int,input().split())) for i in range(n)]
number = [i for i in range(1,200)]
square = list(map(lambda i: i**2, number))
count = 0
for i in range(0,n):
  for j in range(0,n):
    distance = 0
    for p in range(0,d):
      distance += (X[j][p]-X[i][p])**2
    if square.count(distance) == 1 and i < j:
      count += 1
print(count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
n, d = map(int, input().split())

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

#print(x)

def dist_calc(lis1, lis2):
    sum = 0
    for i in range(len(lis1)):
        sum += (lis1[i]-lis2[i])**2
    return math.sqrt(sum)

count = 0
for i in range(n):
    for j in range(i+1,n):
        if i==j:
            continue
        else:
            dist = dist_calc(x[i],x[j])
#            print(dist)
            if dist.is_integer() == True:
                count += 1
            else:
                continue

print(count)