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 unittest


class TestB(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think([[1, 2], [5, 5], [-2, 8]]), 1)

    def test_2(self):
        self.assertEqual(think([[-3, 7, 8, 2], [-12, 1, 10, 2], [-2, 8, 9, 3]]), 2)

    def test_3(self):
        self.assertEqual(think([[1], [2], [3], [4], [5]]), 10)


def solve():
    x = read()
    result = think(x)
    write(result)


def read():
    n, d = read_int(2)
    x = []
    for _ in range(n):
        if d == 1:
            x.append([read_int(1)[0]])
        else:
            x.append(read_int(d))
    return x


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(x):
    n = len(x)
    max_d = 10
    max_x, min_x = 20, -20
    set_of_square_of_dist = create_set_of_square_of_dist(max_d, max_x, min_x)

    count = 0
    for i in range(n):
        for j in range(i + 1, n):
            square_of_dist = calc_square_of_dist(x[i], x[j])
            if square_of_dist in set_of_square_of_dist:
                count += 1
    return count


def write(result):
    print(result)


def create_set_of_square_of_dist(max_d, max_x, min_x):
    max_diff = max_x - min_x
    max_square_of_sum = (max_diff ** 2) * max_d

    set_of_square_of_dist = set()
    i = 0
    while True:
        if i ** 2 > max_square_of_sum:
            break
        set_of_square_of_dist.add(i ** 2)
        i += 1
    return set_of_square_of_dist


def calc_square_of_dist(x_1, x_2):
    diff_x = [0 for x in range(len(x_1))]
    for i in range(len(x_1)):
        diff_x[i] = x_1[i] - x_2[i]

    return sum([x ** 2 for x in diff_x])


if __name__ == '__main__':
    # unittest.main()
    solve()

Submission status: Accepted

Solution code:
import math
import sys
def input(): return sys.stdin.readline().strip()

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

main()

Submission status: Accepted

Solution code:
nd = list(map(int, input().split()))
xnd = []
for _ in range(nd[0]):
    xnd.append(list(map(int, input().split())))
    
    
    
import math
count = 0
for i in range(nd[0] - 1):
    for i_2 in range(i+1, nd[0], 1):
        xSum = 0
        for j in range(nd[1]):
            xSum += (xnd[i][j] - xnd[i_2][j]) ** 2
        ans = math.sqrt(xSum)
        if ans == int(ans):
            count += 1
print(count)

Submission status: Accepted

Solution code:
import numpy as np


N, D = list(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):
        dis = np.linalg.norm(np.array(X[i]) - np.array(X[j]))
        if dis - int(dis) < 0.00000001:
            ans += 1
print(ans)

Submission status: Accepted

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

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

#print(xi)

ans=0

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

print(ans)

Submission status: Accepted

Solution code:
import math

n, d = map(int, input().split())
x = []

def check_distance(vec1, vec2):
  ssum = 0
  root = 0
  for i in range(len(vec1)):
    ssum += (abs(vec1[i]-vec2[i])**2)
    root = math.sqrt(ssum)
  return root.is_integer()


ans = 0
for i in range(n):
  x.append(list(map(int, input().split())))
  
for i in range(n):
  for j in range(n):
    if i == j:
      continue
    if check_distance(x[i], x[j]):
      ans += 1
      
print(ans//2)

Submission status: Accepted

Solution code:
from itertools import combinations

n, D = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(n)]
cnt = 0


for a, b in combinations(ls, 2):
    l = 0
    for d in range(D):
        l += (a[d]-b[d])**2
    if l ** 0.5 == int(l ** 0.5):
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import itertools

n, D = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(n)]
cnt = 0

i1 = [int(i) for i in range(n)]
i2 = itertools.combinations(i1, 2)

for a, b in i2:
    l = 0
    for d in range(D):
        l += (ls[a][d]-ls[b][d])**2
    if l ** 0.5 == int(l ** 0.5):
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math
N, D = map(int, input().split())
t = []
for i in range(N):
    t.append(list(map(int, input().split())))
count = 0
sum = 0
for i in range(0, N-1):
    for j in range(i + 1, N):
      for d in range(D):
        sum += pow(t[i][d] - t[j][d], 2)
        sqrt = math.sqrt(sum)
      if sqrt == int(sqrt):
        count += 1
      sum = 0
      sqrt = 0
print(count)

Submission status: Accepted

Solution code:
import math

tmp = list(map(int, input().split()))
n = tmp[0]
d = tmp[1]

x = [[0] * d for i in range(n)]
for i in range(n):
  tmp = list(map(int, input().split()))
  for j in range(d):
    x[i][j] = tmp[j]

cnt = 0
for i in range(n):
  for j in range(i+1, n):
    len = 0
    for k in range(d):
      len += (x[i][k] - x[j][k]) ** 2
    len = math.sqrt(len)
#    print('I=' + str(i) + ' J=' + str(j) + ' LEN=' + str(len))
    if len.is_integer():
      cnt += 1

print (cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,d=map(int,input().split(" "))
s=[list(map(int,input().split(" "))) for i in range(0,n)]
from math import*
#print(s)
co=0
for i in range(0,n-1):
    for j in range(i+1,n):
        combi=[abs(x-y)**2 for (x,y)in zip(s[i],s[j])]
        if sqrt(sum(combi))%1==0:
            co+=1
print(co)

Submission status: Accepted

Solution code:
from itertools import combinations
import numpy as np
N,D = map(int,input().split())
X = []
for i in range(N):
    X.append(np.array(list(map(int,input().split()))))
comb = list(combinations(list(range(N)),2))
count = 0
for i in range(len(comb)):
    dist = (sum(list(np.power(X[comb[i][0]]-X[comb[i][1]],2))))**(1/2)
    if int(dist) == dist:
        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)]

import numpy as np

def dist(a,b):
  arr_a=np.array(a)
  arr_b=np.array(b)
  return np.sqrt(np.sum((arr_a - arr_b)  ** 2))

count = 0

for i in range(n-1):
  for j in range(i+1,n):
    if dist(x[i],x[j]).is_integer():
      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 i in range(n)]

ans=0
tmp=0

for i in range(n):
  for j in range(i+1, n):
    xi,xj = x[i],x[j]
    for k in range(d):
      tmp += (xi[k]-xj[k]) ** 2  
    if sqrt(tmp)%1==0:
      tmp=0
      ans += 1
    else:
      tmp=0

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

import math
def main():
    N,D = map(int, input().split())
    Dimention = [ [int(s) for s in input().split()] for i in range(N)]
    result = 0
    for i, y in enumerate(Dimention):
        for j, z in enumerate(Dimention):
            if i == j or i > j:
                continue
            kei = 0
            for num in range(D):
                kou = y[num] - z[num]
                kou = kou**2
                kei += kou
            if math.sqrt(kei).is_integer():
                result += 1
    print(result)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC133B - Good Distance
def main():
    N, D, *X = map(int, open(0).read().split())
    X = tuple(zip(*[iter(X)] * D))
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            r = sum(abs(a - b) ** 2 for a, b in zip(X[i], X[j]))
            ans += 1 if r ** 0.5 == int(r ** 0.5) else 0
    print(ans)


if __name__ == "__main__":
    main()

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

def square(list):
  return [x**2 for x in list]

def calc_distance(l1, l2):
  dif = [l1[i] - l2[i] for i in range(len(l1))]
  d = sum(square(dif))
  return d

for i in range(n - 1):
  for j in range(i + 1, n):
    temp = calc_distance(v[i], v[j])
    if temp in sq_list:
      ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math

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

def dist(R,L):
    P=0
    for z in range(D):
        P+=(R[z]-L[z])**2
    return math.sqrt(P)

count=0
for j in range(N-1):
    for k in range(j+1,N):
        #print(dist(X[j],X[k]))
        #print(math.floor(dist(X[j],X[k])))
        if dist(X[j],X[k])==math.floor(dist(X[j],X[k])):
            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
LL = 0
for i in range(N):
  for j in range(i+1,N):
    for k in range(D):
      LL += (X[i][k]-X[j][k])**2
    L = math.sqrt(LL)
    if LL == int(L)**2:
      ans += 1
    L = 0
    LL = 0
print(ans)

Submission status: Accepted

Solution code:
#import pprint
n, d = map(int, input().split())
#x = list[int(input().split()) for i range(1, n+1)]
x = [list(map(int, input().split())) for _ in range(n)]
#pprint.pprint(x)

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

Submission status: Accepted

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

Submission status: Accepted

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

import numpy as np
count = 0
X = np.array(X)
for i in range(N):
  for j in range(N-i-1):
    dist = np.linalg.norm(X[i]-X[N-j-1])
    if dist.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)]

ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        v = 0
        for k in range(D):
            v += (X[j][k] - X[i][k]) ** 2
        sr = v ** 0.5
        a = int(sr)
        b = a + 1
        if a * a == v or b * b == v:
            ans += 1

print(ans)

Submission status: Accepted

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

ans = 0
for i in range(n):
    for j in range(i+1, n):
        if math.sqrt(sum(list(map(lambda c: (c[0] - c[1])**2, zip(x[i], x[j]))))).is_integer():
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools
import math
N, D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]
ans = 0
for Y, Z in itertools.combinations(X,2):
  tmp = 0
  for d in range(D):
    tmp += (Y[d] - Z[d]) ** 2
  if math.sqrt(tmp) % 1 == 0:
    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)]

x = np.array(X)
dist_mat = np.linalg.norm(x[:, np.newaxis] - x, axis=-1)

count = 0
for i in dist_mat:
    for j in i:
        if j.is_integer():
            count += 1

print((count-N)//2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
B - Good Distance
https://atcoder.jp/contests/abc133/tasks/abc133_b

"""
import sys
from itertools import combinations


def solve(points):
    ans = 0
    for p1, p2 in combinations(points, 2):
        d = sum([(a-b)**2 for a, b in zip(p1, p2)])
        ans += (d**0.5).is_integer()
    return ans


def main(args):
    n, d = map(int, input().split())
    points = [[int(x) for x in input().split()]  for _ in range(n)]
    ans = solve(points)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

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

count = 0

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

print(count)

Submission status: Accepted

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

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


def calc_length(d, p, q):
    sqr_length = 0
    for i in range(d):
        sqr_length += (p[i] - q[i]) ** 2

    return math.sqrt(sqr_length)


lengthes = list()

for i in range(n-1):
    p = x[i]
    for j in range(i+1, n):
        q = x[j]

        lengthes.append(calc_length(d, p, q))

ans = 0
for i in range(len(lengthes)):
    if isinstance(lengthes[i], int):
        ans += 1
    else:
        if lengthes[i].is_integer():
            ans += 1


print(ans)

Submission status: Accepted

Solution code:
import math

n, d = map(int, input().split())
x = [[0]*d for _ in range(n)]
ans = 0
for i in range(n):
  x[i] = list(map(int, input().split()))

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

print(ans)

Submission status: Accepted

Solution code:
perfect_squares = set(i**2 for i in range(1, 128))

n, d = (int(x) for x in input().split())
points = []
for _ in range(n):
  points.append([int(x) for x in input().split()])
ans = 0
for i in range(n-1):
  for j in range(n-i-1):
    nn = 0
    for dim in range(d):
        nn += (points[i][dim] - points[j+1+i][dim]) ** 2
    if nn in perfect_squares:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def main():
    n,d = [int(x) for x in input().split()]

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

    for i in range(n-1):
        for j in range(i+1, n):
            sumary = 0
            for k in range(d):
                sumary += (array[i][k] - array[j][k])**2
            distance = math.sqrt(sumary)
            if distance.is_integer():
                count += 1
    print(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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


res=0

for i in range(N):
        for j in range(i+1,N):
                dist=0
                for d in range(D):
                        dist += (S[i][d] - S[j][d])**2

                if (dist ** 0.5).is_integer():
                        res+=1


print(res)

Submission status: Accepted

Solution code:
import math
n,d = map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]
norm = 0
ans = 0
for i in range(n - 1):
  for j in range(i+1,n):
    # if i >= j:
    #   continue
    #print(x[i][j])
    for k in range(d):
      #print(abs(x[i][k]-x[j][k])**2)
      norm += abs(x[i][k]-x[j][k])**2
      if k == (d - 1):
        p = math.sqrt(norm)
        #print(str(x[i][k])+"と"+str(x[j][k]))
        #print(p)
        norm = 0
        if p.is_integer():
          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)]
total = 0
for i in range(0,n-1):
    for j in range(i+1,n):
        r = 0
        for k in range(0,d):
            r += (x[i][k] - x[j][k])**2
        if (r**0.5).is_integer():
            total += 1
print(total)

Submission status: Accepted

Solution code:
def calc(y,z):
    flag=0
    LL=0
    for i in range(D):
        LL +=(y[i] - z[i])**2
    L =LL**0.5
    if L == int(L) :
        flag=1
    return(flag)


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

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

    cnt=0
for i in range(N-1):
        for j in range(i+1,N):
                cnt += calc(X[i],X[j])
                
print(cnt)

Submission status: Accepted

Solution code:
N,D=map(int,input().split())
L=[list(map(int,input().split())) for i in range(N)]
n=0
for i in range(N):
  for j in range(i):
    DD=0
    for k in range(D):
      DD+=(L[i][k]-L[j][k])**2
    if any(n**2==DD for n in range(1,128)):
      n+=1
print(n)

Submission status: Accepted

Solution code:
import sys

def solve():
    n,d = map(int, input().split())
    l = [list(map(int, X.split())) for X in sys.stdin.readlines()]
    count = 0
    for i in range(n):
        Y = l[i]
        for Z in l[i+1:]:
            total = 0
            for y,z in zip(Y,Z):
                total += (y-z)**2
            d = total**0.5
            if d == int(d):
                count += 1
    return count

if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
def solve():
    n,d = map(int, input().split())
    l = [[int(x) for x in input().split()] for _ in range(n)]
    count = 0
    for i in range(n):
        Y = l[i]
        for Z in l[i+1:]:
            total = 0
            for y,z in zip(Y,Z):
                total += (y-z)**2
            d = total**0.5
            if d == int(d):
                count += 1
    return count

if __name__ == '__main__':
    print(solve())

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(n-1):
    for j in range(i+1, n):
        square = 0
        for k in range(d):
            square += (x[i][k]-x[j][k])**2
        if (square**0.5).is_integer():
            dist_int += 1

print(dist_int)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]
def l1(a,b,d):
    s=0
    for i in range(d):
        s+=(a[i]-b[i])**2
    return s**0.5
cnt=0
for i in range(n):
    for j in range(i,n):
        #print(i,j)
        if l1(x[i],x[j],d)!=0 and l1(x[i],x[j],d)%1==0:
            cnt+=1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    n,d = map(int, input().split())
    L = [[int(x) for x in input().split()] for _ in range(n)]
    count = 0
    for i in range(n):
        y = L[i]
        for z in L[i+1:]:
            total = 0
            for a,b in zip(y,z):
                total += (a-b)**2
            if total**0.5 == int(total**0.5):
                count += 1
    return count
    
if __name__ == '__main__':
    print(solve())

Submission status: Accepted

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

ans = 0
for i in range(N):
    for j in range(i+1, N):
        s = 0
        for d in range(D):
            s += (array[i][d]-array[j][d]) ** 2
        if s ** (1/2) % 1 == 0:
            ans += 1

print(ans)

Submission status: Accepted

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

count = 0
for i in range(len(X)):
	for j in range(i + 1, len(X)):
		power = 0
		for idx in range(len(X[i])):
			power += (X[i][idx] - X[j][idx])**2
		if(abs(int(math.sqrt(power))**2 - power ) < 0.001):
			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+1):
    x=0
    for j in range(i,N):

        x=sum(list(map(lambda x,y:(x-y)**2,X[i-1],X[j])))
        if math.sqrt(x)==int(math.sqrt(x)):
            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)]
cnt = 0
for i in range(0,N):
    for j in range(0,N):
        if i >= j:
            pass
        else:
           dif = [(y-x)**2 for (x,y) in zip(X[i],X[j])]
           J = sum(dif)**(1/2)
           if J.is_integer():
               cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

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

def distance(np_1, np_2):
    dif = np_1 - np_2
    dif_sq = np.square(dif)
    dist_sq = np.sum(dif_sq)
    dist = np.sqrt(dist_sq)
    return dist


for n in range(N):
    for i in range(n,N):
        x = distance(X[n], X[i])

        if x.is_integer():
            ans += 1

print(ans)

Submission status: Accepted

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

from math import sqrt
b = []
for i in range(0,N):
  b.append([int(x) for x in input().split()])
#print(b)

def distance(p,q,n):
  d = 0
  for i in range(0,n):
    d += (p[i]-q[i])**2
  return sqrt(d)

cnt = 0
for l in range(0,N-1):
  for k in range(l+1,N):
    if distance(b[l],b[k],D)-int(distance(b[l],b[k],D))==0:
      cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import math as m

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

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

print(ans)

Submission status: Accepted

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

X = [[0 for i in range(D)]for j in range(N)]

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

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

print(cnt)

Submission status: Accepted

Solution code:
import math
n, d = map(int, input().split())
x = [[int(e) for e in input().split()] for _ in range(n)]
result = 0
for i in range(n - 1):
  for j in range(i + 1, n):
    t = math.sqrt(sum((x[i][k] - x[j][k]) * (x[i][k] - x[j][k]) for k in range(d)))
    if t == math.ceil(t):
      result += 1
print(result)

Submission status: Accepted

Solution code:
import numpy as np

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

X = np.atleast_3d(X)
L = np.linalg.norm(X - X.T, axis=1)
c = (np.count_nonzero(L == L.astype(int)) - N) // 2

print(c)

Submission status: Accepted

Solution code:
n,b=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):
    t=0
    for k in range(b):
      t += (x[i][k]-x[j][k])**2
    t = t**(1/2)
    if t.is_integer():
      count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,d=[int(x) for x in input().split()]
x=[list(map(int,input().split())) for i in range(n)]
answer = 0
for i in range(n):
  for j in range(i+1,n):
    v = 0
    for k in range(d):
    	v += (x[i][k]-x[j][k])**2
    	t = 1
    while t**2<=v:
      	if t**2 == v:
        	answer += 1
        	break
      	t += 1
print(answer)

Submission status: Accepted

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

Submission status: Accepted

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


for i in range(n-1):
    for j in range(i+1,n):
        d2=0
        for l in range(d):
            d2+=(x[i][l]-x[j][l])**2
        d2=int(d2)
        for k in range(1,d2//2+2):
            if d2==k**2:
                ans+=1
                break

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

Submission status: Accepted

Solution code:
n,d = map(int, input().split())
L = [list(map(int, input().split())) for i in range(n)]
cnt = 0
for i in range(n):
  for k in range(i+1,n):
    dist = 0
    for v in range(d):
      dist += (L[i][v]-L[k][v])**2
    if (dist**0.5).is_integer():
      cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
ans=0
x=[]
y=[]
check=0
e=0
for i in range(n):
    x.append(input())
    x[i]=x[i].split()
    for j in range(d):
        x[i][j]=int(x[i][j])
for z in range(1,n):
    for l in range(n-z):
        for k in range(d):
            e=x[l][k]-x[l+z][k]
            check+=e**2
        q=int(check**0.5)
        if q**2==check:
            ans+=1
            check=0
        else:
            check=0
print(ans)