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 math
a,aa=map(int,input().split())
b=[list(map(int,input().split())) for i in range(a)]
d=0
for i in range(a-1):
  for j in range(i+1,a):
    c=0
    for k in range(aa):
      c+=(b[i][k]-b[j][k])*(b[i][k]-b[j][k])
    c=math.sqrt(c)
    if c%1==0:
      d+=1

print(d)

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 
z = np.array(x)
count = 0
for i in range(n):
    for j in range(i+1,n):
        distance = np.linalg.norm(z[i]-z[j])
        if distance.is_integer():
            count += 1
print(count)

Submission status: Accepted

Solution code:
from itertools import combinations

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

cnt = 0
for a, b in combinations(X, 2):
    dist = 0
    for i in range(d):
        dist += (a[i] - b[i]) ** 2
    if dist ** 0.5 % 1 == 0:
        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)]
count = 0

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

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
def zill(a,b):
  sum = 0
  for i in range(k):
    sum += (a[i] - b[i])**2
  sq = int(sum**0.5)
  if sq**2 == sum: return 1
  return 0


a=[[] for i in range(n)]

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

res = 0
for i in range(n-1):
  for j in range(i+1,n):
    if zill(a[i],a[j]) : res+=1
print(res)

Submission status: Accepted

Solution code:
import math
n,d = map(int,input().split())
listx = []
for i in range(n):
    a = [int(x) for x in input().split()]
    listx.append(a)
count = 0
for i in range(n):
    for j in range(i+1,n):
        s = 0
        for k in range(d):
            s = s + (listx[i][k] - listx[j][k])**2
        sr = math.sqrt(s)
        if math.ceil(sr) == sr:
            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):
    xi = x[i]
    for j in range(i + 1, n):
        xj = x[j]
        y = 0
        for k in range(d):
            y += (xi[k] - xj[k]) ** 2
        y_sqrt = int(y ** 0.5)
        if y_sqrt ** 2 == y:
            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
for j in range(N-1):
    for k in range(j+1,N):
        L = 0
        for l in range(D):
            L += (X[j][l]-X[k][l])**2
        if math.sqrt(L).is_integer() == True:
            count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from heapq import heappush, heappop
import re
from collections import deque
import sys
import math
input = sys.stdin.readline


def int_raw():
    return int(input())


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


def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret


def main():
    N,D= ints_raw()
    Xs = []
    for _ in range(N):
        Xs.append(ints_raw())
    ans = 0
    for i in range(1,N):
        for j in range(i):
            Xi = Xs[i]
            Xj = Xs[j]
            d2 = sum([(Xi[k]-Xj[k])**2 for k in range(D)])
            if math.sqrt(d2).is_integer():
                ans+=1
    return ans

print(main())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import itertools

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

def integer(x1,x2):
    count = 0
    for i in range(d):
        count += (x1[i]-x2[i])**2
    if math.sqrt(count).is_integer():
        return 1
    else:
        return 0

count = 0
for lists in itertools.combinations(x_list,2):
    count += integer(lists[0],lists[1])

print(count)

Submission status: Accepted

Solution code:
n, d = map(int, input().split(" "))
xs = set(tuple(map(int, input().split(" "))) for i in range(n))
ys = set(xs)
ans = 0
for x in xs:
    ys.remove(x)
    for y in ys:
        d2 = sum(abs(xx - yy) ** 2 for xx,yy in zip(x, y))
        j = 1
        while j ** 2 < d2:
            j += 1
        if j ** 2 == d2:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
# -*- coding utf-8 -*-
import numpy as np

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

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        dist = np.sqrt(np.power(X[i] - X[j], 2).sum())
        if dist.is_integer():
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math
i,j = map(int,input().split())

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

ok = 0
for src in range(i):
  for dst in range(src+1,i):
    itoj =0
    for dim in range(j):
      itoj += (p[dst][dim] - p[src][dim])**2
    if math.sqrt(itoj)%1 == 0:
      ok +=1
print (ok)

Submission status: Accepted

Solution code:
import math
n,d=map(int,raw_input().split())
l=[]
for i in xrange (n):
  a=map(int,raw_input().split())
  l.append(a)
ans=0
for i in xrange (n-1):
  for j in xrange (i+1,n):
    temp=0
    for k in xrange (d):
      temp+=(l[i][k]-l[j][k])**2
    temp=math.sqrt(temp)
    if temp%1==0:
      ans+=1
print ans

Submission status: Accepted

Solution code:
import math
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()))
result = 0
for i in range(0,n-1):
  for j in range(i+1,n):
    diff = list(map(lambda x,y: pow(x-y,2), x[i], x[j]))
    calc = math.sqrt(sum(diff))
    if calc.is_integer():
      result +=1
print(result)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
    for j in range(i+1,N):

        diff=math.sqrt(sum([(a-b)**2 for a,b in zip(x[i],x[j])]))

        if diff-int(diff)==0:
            count+=1
print(count)

Submission status: Accepted

Solution code:
import math


def check(arr, d):
    count = 0
    length = len(arr)
    # print(length)
    for i in range(length):
        for j in range(i + 1, length):
            sum = 0
            for k in range(d):
                sum += (arr[i][k] - arr[j][k]) ** 2
            # print(math.sqrt(sum))
            # print(math.sqrt(sum).is_integer())
            if(math.sqrt(sum).is_integer() == True):
                # print(math.sqrt(sum))
                count += 1
    return count


s = []
s = input().split(' ') #0:n 1:d
n = int(s[0])
d = int(s[1])

arr = []

ans = 0
for i in range(n):
    s = input().split(' ')
    point = []
    for j in range(d):
        point.append(int(s[j])) 
    arr.append(point)
    # print(arr)


print(check(arr, d))

Submission status: Accepted

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

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

#print(grid)
counter = 0

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

        #y^2がkと等しければ整数があることになる
        if int(round(math.sqrt(float(tmp)))**2) == tmp:
            counter += 1


print(counter)

Submission status: Accepted

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

X = [[int(_) for _ in input().split()] for i in range(N)]

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

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
from operator import itemgetter

N, D = [int(x) for x in stdin.readline().rstrip().split()]
X = []
for i in range(N):
    xi = [int(x) for x in stdin.readline().rstrip().split()]
    X.append(xi)

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

    ret = np.sqrt(ret)
    return ret

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import math


    
def deffer(A,B):
    sum = 0
    for i in range(len(A)):
        sum += (A[i]-B[i])**2
    sum = math.sqrt(sum)
    return sum


N,D= map(int,input().split())
listA = [list(map(int,input().split())) for i in range(N)]
ans =0
for i in range(N):
    for j in range(i +1,N):
        D = deffer(listA[i],listA[j])
        
        if D.is_integer():
            ans +=1
            
print(ans)

    
def deffer(A,B):
    sum = 0
    for i in range(len(A)):
        sum += (A[i]-B[i])**2
    sum = math.sqrt(sum)
    print("sum is {}".format(sum))
    return sum

Submission status: Accepted

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

def dist(A,B):
    D = 0
    for i in range(len(A)):
        D += (A[i]-B[i])**2
    return D**(1/2)





count = 0
for i in range(N):
    for j in range(i+1,len(point)):
        count += (dist(point[i],point[j])).is_integer()
        
print(count)

Submission status: Accepted

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

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

def f(a, b):
    ab = [0] * D
    for i in range(D):
        ab[i] = (a[i] - b[i]) ** 2
    return sum(ab) ** 0.5

ans = 0
for i in range(1 << X):
    p = []
    for j in range(X):
        if (i >> j) & 1:
            p.append(j)
            
    if len(p) != 2:
        continue
        
    t = f(L[p[0]], L[p[1]])
    if t == int(t):
        ans += 1
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import sqrt


def calc(pos_x, pos_y):
  sum = 0
  for i in range(0, len(pos_x)):
    sum += (pos_x[i] - pos_y[i]) ** 2

  return sqrt(sum).is_integer()


size, z = map(int, input().split())
items = []
for i in range(0, size):
  items.append(list(map(int, input().split())))

# items = []
# items.append(list(map(int, "-3 7 8 2".split())))
# items.append(list(map(int, "-12 1 10 2".split())))
# items.append(list(map(int, "-2 8 9 3".split())))

count = 0

for i in range(0, len(items)):
  for j in range(i + 1, len(items)):
    count += 1 if calc(items[i], items[j]) else 0

print(count)

Submission status: Accepted

Solution code:
import math

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

point = [[0]*d for _ in range(n)]

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

count = 0
for i in range(n):
    for j in range(n):
        if i < j:
            sum = 0
            for k in range(d):
                sum += ( point[i][k] - point[j][k] ) ** 2
            sum = math.sqrt(sum)
            if sum % 1 == 0:
                count += 1
        else:
            continue

print(count)

Submission status: Accepted

Solution code:
import math

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

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

c=0
for i in range(N):
  for j in range(i+1,N):
     d = 0
     for k in range(D):
       d += (X[i][k]-X[j][k])**2
     if int(round(math.sqrt(float(d)))**2) == d:
       c += 1
print(c)

Submission status: Accepted

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

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        a = 0
        for k in range(D):
            a += abs(X[i][k] - X[j][k]) ** 2
        if math.sqrt(a).is_integer():
            cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

n = [[]]
a, b = input("").split(" ")
a = int(a)
b = int(b)
for i in range(a):
    tmp = input("").split(" ")
    for j in range(b):
        tmp[j] = int(tmp[j])
    n.append(tmp)
n.remove(n[0])
rep = 0
for i in range(a):
    for j in range(a-i-1):
        ans = 0
        for s in range(b):
            p = (n[i][s] - n[j+i+1][s])
            ans += (n[i][s] - n[j+i+1][s])**2
        ans = math.sqrt(ans)
        intans = int(ans)
        if ans - intans == 0:
            rep+=1
print(rep)

Submission status: Accepted

Solution code:
import numpy as np
N,D=map(int, input().split())
X=np.zeros((D,N))
count=0;
for i in range(N):
    X[:,i]=np.array(input().split(),dtype=float)
for i in range(N-1):
    for k in range(i+1,N):
        dist=np.linalg.norm(X[:,i]-X[:,k])
        dist=dist.astype('float')
        if dist.is_integer():
            count=count+1
print(count)

Submission status: Accepted

Solution code:
from itertools import combinations

def calc(y, z):
    s = 0
    for p, q in zip(y, z):
        s += (p - q)**2
    return s ** (1/2)

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

c = 0
for i in combinations(points, 2):
    d = calc(i[0], i[1])
    if d == int(d):
        c += 1
print(c)

Submission status: Accepted

Solution code:
#距離を計算する関数
def distance(k,j,zen,d):
    a = zen[k]
    b = zen[j]
    r = 0
    for i in range(d):
        r = r + (int(a[i]) - int(b[i])) ** 2
    return r ** 0.5

#2次元配列を用意
zen = []
#N、Dを得る
n, d = map(int, input().split())

for i in range(n):
    #xを得る
    x = input()
    #リストにする
    xi =x.split()
    #2次元配列に追加
    zen.append(xi)

#2次元配列を表示
#print(zen)
#print(zen[1])
count = 0
good=[]
for k in range(n-1):
    for j in range(k+1, n):
        #good.append(distance(k, j, zen, d))
        if distance(k, j, zen, d).is_integer():
            count = count + 1

#print(good)
print(count)

Submission status: Accepted

Solution code:
import numpy as np
from itertools import combinations

# 平方数　桁落ち対策
def is_square(n):
  m = int(round(n**0.5))
  return n == m*m
  
N, D = map(int, input().split())
A = [np.array(input().split(), dtype=np.int64) for _ in range(N)]
answer = 0
for x, y in combinations(A, 2):
  d = (pow((x-y),2)).sum()
  if is_square(d):
    answer += 1
print(answer)

Submission status: Accepted

Solution code:
import math

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

a = [[0 for i in range(d)] for j in range(n)]

score = 0

for i in range(n):
    a[i] = input().strip().split()
    
for i in range(n):
    for m in range(n-i-1):
        k=0
        if d >1:
            for l in range(d):
                k += (int(a[i][l])-int(a[i+m+1][l]))*(int(a[i][l])-int(a[i+m+1][l]))
            
            if math.sqrt(k).is_integer():
                score += 1
                
        else:
            score += 1
            
        
    
print(score)

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())))
for i in range(N):
    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 math
n,d = list(map(int,input().split()))
cnt = 0
x_list = []
for i in range(n):
	x = list(map(int,input().split()))
	x_list.append(x)

for j in range(n):
	for k in range(1,n-j):
		l = 0
		for m in range(d):
			l += (x_list[j][m]-x_list[j+k][m])**2
		if(math.sqrt(l).is_integer()):
			cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
N,D=map(int,input().split())
X=[]
dist=[]
Xsumnow=0
Xsumnext=0

for i in range(N):
    X.append([int(j) for j in input().split()])
count=N
for m in range(N):
    for j in range(m+1,N):
        for k in range(D):
            Xsumnow+=abs(X[j][k]-X[m][k])*abs(X[j][k]-X[m][k])
        dist.append(np.sqrt(Xsumnow))
        Xsumnow=0
TrueCounter=0
for l in range(len(dist)):
    if dist[l].is_integer():
        TrueCounter+=1

print(TrueCounter)

Submission status: Accepted

Solution code:
import math
s = [int(i) for i in input().split()]
N = s[0]
D = s[1]

def combinations(n, r):
    return math.factoriak(n)/(math.factorial(n-r)*math.factorial(r))

dot = []
dist = []

for i in range(N):
    dot.append([int(j) for j in input().split()])

for i in range(N-1):
    for j in range(i+1, N):
        tmp = []
        for k in range(D):
            c = (dot[i][k] - dot[j][k])**2
            tmp.append(c)
        if k == D-1:
            dist.append(sum(tmp))

answer = list(map(lambda x:pow(x, 1/2), dist))
count = 0
for i in range(len(answer)):
    if answer[i].is_integer() == True:
        count = count + 1
print(count)

Submission status: Accepted

Solution code:
import math
n,d=input().split()
n=int(n)
d=int(d)
def combinations(n, r):
    return math.factorial(n)/(math.factorial(n-r)*math.factorial(r))
x=[]
for i in range(n):
    xa=[int(s) for s in input().split()]
    x.append(xa)
    a=[]
for i in range(n-1):
    for j in range(i+1,n):
        t=[]
        for k in range(d):
            c=(x[i][k]-x[j][k])*(x[i][k]-x[j][k])
            t.append(c)
        if k==d-1:
            a.append(sum(t))
answer=list(map(lambda x:pow(x,1/2),a))
count=0
for l in range(len(answer)):
    if answer[l].is_integer()==True:
        count=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)]
S = {i**2 for i in range(1000)}
ans = sum(
    a != b and sum((x - y)**2 for x, y in zip(a, b)) in S
    for a in X
    for b in X
) // 2

print(ans)

Submission status: Accepted

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

N, D = map(int, input().split())
s_lines = sys.stdin.readlines()

ans = 0
X_list_list = []
for s in s_lines:
    new_list = list(map(int, s.split()))
    for i in range(len(X_list_list)):
        sum_num = float(0)
        for idx, ite in enumerate(X_list_list[i]):
            sum_num += (new_list[idx] - ite) ** 2
        if pow(sum_num, 0.5).is_integer():
            ans += 1
    X_list_list.append(new_list)

print(ans)

Submission status: Accepted

Solution code:
#133

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


count = 0
#距離計算(X_ikとX_jk)(i < J)
for i in range(0,N - 1):
    for j in range(i + 1,N):
        distance = 0;
        for k in range(0, D):
            distance +=  (X[i][k] - X[j][k]) * (X[i][k] - X[j][k])
        for l in range(0,200):
            if(distance == l*l):
                count = count + 1

print(count)

Submission status: Accepted

Solution code:
import math
n, d = list(map(int, input().split()))
m=0
x=[]
for i  in range(n):
	 x.append(list(map(int ,input().split())))
for i  in range(n):
	for s in range (i+1,n):
		D=0
		for t in range (d):
			D += (x[i][t]-x[s][t])**2
			D2 =math.floor(D**(1/2))
		if D == D2**2:
			m+=1
print(m)

Submission status: Accepted

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

print(ans//2)

Submission status: Accepted

Solution code:
import math
import itertools

a,b=map(int,input().split())
X = [[int(i) for i in input().split()] for i in range(a)] 
#for i in range():
c = list(itertools.combinations(X, 2))


ans = 0

for i in range(len(c)):
  d = 0
  for j in range(b):
    d += (c[i][0][j]-c[i][1][j])**2
    if j == b-1:
      d = math.sqrt(d)
      if d.is_integer():
        ans = ans+1

print(ans)

Submission status: Accepted

Solution code:
p=input().rstrip().split(' ')
L=[]
for i in range(0,1000000):
    L.append(i**2)
l=[]
q=[]
w=[]
S=[]
D=[]
V=0;
for i in range(0,int(p[0])):
    u=input().rstrip().split(' ')
    l.append(u)
for i in range(0,len(l)-1):
    A=l[i]
    for j in range(i+1,len(l)):
        B=l[j]
        T=0;
        for k in range(0,len(A)):
            T+=(abs(int(A[k])-int(B[k]))**2)
        if T in L:
            V+=1;
print(V)

Submission status: Accepted

Solution code:
p=input().rstrip().split(' ')
L=[]
for i in range(0,1000):
    L.append(i**2)
l=[]
q=[]
w=[]
S=[]
D=[]
V=0;
for i in range(0,int(p[0])):
    u=input().rstrip().split(' ')
    l.append(u)
for i in range(0,len(l)-1):
    A=l[i]
    for j in range(i+1,len(l)):
        B=l[j]
        T=0;
        for k in range(0,len(A)):
            T+=(abs(int(A[k])-int(B[k]))**2)
        if T in L:
            V+=1;
print(V)

Submission status: Accepted

Solution code:
from itertools import combinations

n, d = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(n)]
cnt = 0
for a, b in combinations(X, 2):
    dist = 0
    for i in range(d):
        dist += (a[i] - b[i]) ** 2
    if dist ** 0.5 % 1 == 0:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import math
x =  [int(s) for s in input().split()]
numList = [[int(s) for s in input().split()] for i in range(x[0])]
sum = 0
for i in range(len(numList)):
    for j in range(i+1,len(numList)):
        d = 0
        for k in range(x[1]):
            d += (numList[i][k] - numList[j][k]) ** 2
        num = d ** 0.5
        numStr = str(num).split('.')
        if(numStr[len(numStr)-1] == '0'):
            sum += 1
            
print(sum)

Submission status: Accepted

Solution code:
from math import sqrt
from functools import reduce

def dist(l1, l2):
	if len(l1) != len(l2):
		return False
	sqr_diff = []
	for i in range(len(l1)):
		sqr_diff.append((l1[i] - l2[i]) * (l1[i] - l2[i]))
	return sqrt(reduce(lambda p, c: p + c, sqr_diff))

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

count = 0
for i in range(n):
	for j in range(i + 1, n):
		distance = dist(x[i], x[j])
		# print(distance, int(distance))
		if distance == int(distance):
			count += 1
print(count)

Submission status: Accepted

Solution code:
import numpy as np

def ret_dist(x, y):
	dist = 0
	for i in range(x.shape[0]):
		dist += (x[i] - y[i])**2
	return np.sqrt(dist)

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

ans = 0
EPS = 10**-8
for i in range(N):
	for j in range(i + 1, N):
		dist = ret_dist(X[i], X[j])
		if (dist - int(dist) < EPS):
			ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
from collections import deque
from functools import reduce
from operator import mul
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) 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 MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def COMBINATION(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    r = min(n-r, r)
    if r == 0:
        return 1
    o = reduce(mul, range(n, n - r, -1))
    u = reduce(mul, range(1, r + 1))
    return o // u
class UnionFind():

    def __init__(self, n):
        self.n = n
        self.node = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def same(self, x, y):
        return bool(self.root(x) == self.root(y))

    def root(self, x):
        if self.node[x] == x:
            return x
        else:
            self.node[x] = self.root(self.node[x])  # 経路圧縮
            return self.node[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return  # 結合不要
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.node[y] = x
        self.size[x] += self.size[y]

    def return_size(self, x):
        return self.size[self.root(x)]


n, d = MI()
x = [LI() for _ in range(n)]
ans = 0
for i in range(n):
    for j in range(i+1, n):
        a = [(x[i][k] - x[j][k]) ** 2 for k in range(d)]
        if (sum(a) ** 0.5).is_integer():
            ans += 1
print(ans)

Submission status: Accepted

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



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

sq_list = set([])
for i in range(1, 151):
    sq_list.add(i ** 2)


cnt = 0
for i in range(N):
    Y = X[i]
    for j in range(i, N):
        Z = X[j]
        sum_val = 0
        for y, z in zip(Y, Z):
            sum_val += (y - z) ** 2
        if sum_val in sq_list:
            cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,d=map(int,input().split())
l=[]
for _ in range(n):
    x=list(map(int,input().split()))
    l.append(x)
cnt=0
for i in range(n-1):
    for j in range(i+1,n):
        num=0
        for k in range(d):
            num+=(l[i][k]-l[j][k])**2
        num=num**(1/2)
        if num==int(num):
            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)]
y = []
for i in range(N):
    for j in range(i + 1, N):
        calc_x = 0
        for k in range(D):
            calc_x += pow(x[i][k] - x[j][k], 2)
        y.append(pow(calc_x, 1/2))

print(sum([1 if y[i] % 1 == 0 else 0 for i in range(len(y))]))

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):
        sumD = 0
        for d in range(D):
            sumD += (X[i][d]-X[j][d])**2
        for x in range(128):
            if(sumD==x**2):
                ans += 1
                break
print(ans)