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

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

x = [[]]*N
for l in range(N):
    x[l] = list(map(int, input().split()))

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

print(count)

Submission status: Accepted

Solution code:
from sys import stdin
N, D = [int(x) for x in stdin.readline().rstrip().split()]
X = [stdin.readline().rstrip().split() for _ in range(N)]
count = 0
for i in range(0, N):
    for j in range(i+1, N):
        distance = 0
        for k in range(0, D):
            distance += abs(int(X[i][k]) - int(X[j][k])) ** 2
        distance = distance ** 0.5
        if(distance.is_integer()):
            count += 1
print(count)

Submission status: Accepted

Solution code:
import itertools
import math
answer = 0
N,D = map(int,input().split())
X_list=[]
for i in range(N):
  X_list.append(list(map(int,input().split())))
for v in itertools.combinations(range(N),2):
  sum_2 = 0
  for j in range(D):
    sum_2 += (X_list[v[0]][j] - X_list[v[1]][j])**2
  if math.sqrt(sum_2).is_integer():
    answer += 1
print (answer)

Submission status: Accepted

Solution code:
# coding: utf-8
# 133B

import math

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

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

count = 0
for i in range(len(X)-1):
    for j in range(i+1, len(X)):
        ds = 0
        for k in range(D):
            ds += (X[i][k] - X[j][k])**2
        ds = math.sqrt(ds)
        #print(ds)
        if ds - int(ds) == 0:
            count += 1
print(count)

Submission status: Accepted

Solution code:
n,d = map(int,input().split())
x1,x2,x3,x4,x5,x6,x7,x8,x9,x10 = [],[],[],[],[],[],[],[],[],[]
all_x = [x1,x2,x3,x4,x5,x6,x7,x8,x9,x10]

import math

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


t = 0
for i in range(n):
    for k in range(n):
        if i < k:
            y = 0
            for j in range(d):
                y += (all_x[i][j] - all_x[k][j])**2
            z = math.sqrt(y)
            if z - int(z) == 0:
                t += 1

print(t)

Submission status: Accepted

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

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

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        dis = 0
        for k in range(d):
            dis += abs(x[i][k] - x[j][k])*abs(x[i][k] - x[j][k])
        a, _ = math.modf(math.sqrt(dis))
        if a == 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)]
cnt=0
for i in range(n-1):
    for j in range(i+1,n):
        s=0
        for k in range(d):
            s+=(abs(x[i][k]-x[j][k]))**2
        if s**0.5==int(s**0.5):
            cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
n,d= map(int,input().split())
a=[]
for i in range(n):
    l=list(map(int,input().split()))
    a.append(l)
ans=0


for j in range(n):
    for k in range(n):
        bb=0
        for l in range(d):
            bb+=abs(a[j][l]-a[k][l])**2
        sq=np.sqrt(bb)
        if sq.is_integer():
            ans+=1
print(int((ans-n)/2))

Submission status: Accepted

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

listA=[]
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;

idx1 = 0
cnt = 0
for idx1 in range(N):
  idx2 = idx1 + 1
  for idx2 in range(idx1 + 1 , N):
    idx3 = 0
    dis_sq = 0
    dis = 0
    for idx3 in range(D):
      dis_sq += ( listA[idx1][idx3] - listA[idx2][idx3] )** 2
    dis = float(dis_sq ** (1/2))
    if dis - int(dis) == 0:
      cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import math

n, d = map(int, input().split())
x = [tuple(map(int, input().split())) for i in range(n)]
count = 0
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():
      count += 1

print(count)

Submission status: Accepted

Solution code:
import numpy as np
import cmath
N, D = map(int,input().split())
zas = []
for i in range(0,N):
    za = input().split()
    zai = [int(s) for s in za]
    zai = np.array(zai)
    zas.append(zai)

count = 0
for j in range(0,N-1):
    for k in range(j+1,N):
        zad = zas[j]-zas[k]
        za2 = zad*zad
        zasq = (np.sum(za2))**0.5
        if(zasq.is_integer()):
            count = count + 1

print(count)

Submission status: Accepted

Solution code:
import numpy as np

N, D = map(int, input().split())
table = [[int(i) for i in input().split()] for n in range(N)]

count = 0
for i in range(N):
    a = np.array(table[i])
    for j in range(i+1, N):
        b = np.array(table[j])
        u = b - a
        if np.linalg.norm(u).is_integer():
            count += 1

print(count)

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
import itertools
N,D = [int(x) for x in stdin.readline().rstrip().split()]
data = []
for _ in range(N):
    data.append([int(x) for x in stdin.readline().rstrip().split()] + [_])

ans = 0
for j in list(itertools.product(data,repeat=2)):
    tot = 0
    #print(j)
    for k,l in zip(j[0][:D] , j[1][:D]):
        tot += abs(k-l)**2
        #print(tot)
    if j[0][-1] < j[1][-1]:
        if np.sqrt(tot).is_integer():
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math
z=[]
ans=0
sumsum=0
N,D=(int(x) for x in input().split())
for i in range(N):
    a=input().split()
    #print(a)
    z.append(a)
#print(z)

for i in range(N):
    for j in range(i,N):
        for k in range(D):
            sumsum=sumsum+(int(z[i][k])-int(z[j][k]))**2
        if sumsum!=0 and math.sqrt(sumsum)%1==0:
            ans=ans+1
        sumsum=0

print(ans)

Submission status: Accepted

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


from sys import stdin
import math
N,D  = [int(x) for x in stdin.readline().rstrip().split()]

all_point = []
total_sq = 0
cnt = 0

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

for i in range(N):
    for j in range(i+1,N):
        total_sq = 0
        for k in range(D):
            total_sq += (all_point[i][k] - all_point[j][k])**2
        distance = math.sqrt(total_sq)
        if math.floor(distance) == math.ceil(distance):
            cnt += 1

print(cnt)

Submission status: Accepted

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

list = []
for i in range(N):
    list.append(input().split(" "))

count = 0
for i in range(N-1):
    for j in range(i+1,N):
        distance = 0
        for k in range(D):
            distance += (int(list[i][k]) - int(list[j][k]))**2
        distance = distance ** 0.5
        if(distance - int(distance)==0):
            count += 1

print(count)

Submission status: Accepted

Solution code:
import math

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

ans=0

for i in range(n-1):
    for k in range(i+1,n):
        temp=0.0
        for j in range(d):
            temp+=(dl[i][j]-dl[k][j])*(dl[i][j]-dl[k][j])
        tempr=math.sqrt(temp)
        if tempr.is_integer():
            ans+=1

print(ans)

Submission status: Accepted

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

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

for i in range(N):
  for j in range(N):
    distance = np.linalg.norm(X[i] - X[j])
    if distance.is_integer():
      counter += 1

print(int((counter-N)/2))

Submission status: Accepted

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

Submission status: Accepted

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

import math

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# list = list(map(int, input().split()))

def func(I,J,D):
    tmp = 0
    for x in range(D):
        tmp = tmp + (I[x]-J[x]) * (I[x]-J[x])
    return tmp

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


ans = 0
tmp = 0
for i in range(N):
    for j in range(i+1,N):
        if float.is_integer(math.sqrt(func(X[i],X[j],D))):
            ans = ans+1

print(ans)

Submission status: Accepted

Solution code:
import math
N,D = map(int,input().split())
X=[[Xi for Xi in map(int,input().split())] for j 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 math.floor(math.sqrt(dist))**2 == dist:
            count+=1
print(count)

Submission status: Accepted

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

mylist = []
for i in range(N):
  mylist += [input().split()]

cnt = 0
for i in range(0, N):
  for j in range(0, N):
    if i != j and i < j:
      mysum = 0
      for k in range(D):
        mysum += (int(mylist[i][k])-int(mylist[j][k]))**2
      #print(math.sqrt(mysum))
      if (math.sqrt(mysum)).is_integer():
      	cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np

list1 = list(map(int, input().split())) 
s = [list(map(int, input().split()))  for i in range(list1[0])]

dist = 0
num = 0

for a in range(list1[0]):
    for b in range(a+1,list1[0]):
        X = np.array(s[a])
        Y = np.array(s[b])
        dist = np.linalg.norm(X-Y, ord=2)
        if (dist.is_integer()):
            num = num + 1

print(num)

Submission status: Accepted

Solution code:
import math
N,D = [int(i) for i in input().split()]
X = [input().split() for i in range(N)]
cnt = 0
for i in range(N-1):
    for j in range(i+1,N):
        d = 0
        for k in range(D):
            d += (int(X[i][k])-int(X[j][k]))**2
        d = math.sqrt(d)
        if d%1==0:
            cnt+=1
print("{}".format(cnt))

Submission status: Accepted

Solution code:
from sys import stdin
import math
 

N, D = [int(x) for x in stdin.readline().rstrip().split()]

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

count = 0
for i in range(0,N-1):
    for j in range(i+1,N):
        leng = 0
        for k in range(0,D):
            dist = X[i][k] - X[j][k]
            leng += (dist*dist)
        if leng == 1:
            count += 1
        else:
            for n in range(1,leng):
                if leng == n*n:
                    count += 1

    
print(count)

Submission status: Accepted

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

import numpy as np
def dist(X, Y, D):
    s2 = 0
    for i in range(D):
        s2 += (X[i] - Y[i]) * (X[i] - Y[i])
    s1 = int(np.sqrt(s2))
    if s2 == s1 * s1:
        return True
    return False

c = 0
for i in range(N):
    for j in range(i+1, N):
        if dist(data[i], data[j], D):
            c += 1
print("{}".format(c))

Submission status: Accepted

Solution code:
def distance(a, b):
    s = 0
    for i in range(len(a)):
        s += (a[i] - b[i]) ** 2

    return s ** 0.5

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

X = []

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

count = 0

for i in range(N):
    for j in range(i+1, N):
        if distance(X[i], X[j]).is_integer():
            count += 1

print(count)

Submission status: Accepted

Solution code:
n, d = map(int, input().split())
l = []
for _ in range(n):
    li = list(map(int, input().split()))
    l.append(li)
ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        dis = 0
        for di in range(d):
            dis += abs(l[j][di] - l[i][di]) ** 2
        dis_t = dis ** 0.5
        if dis_t.is_integer():
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math

n,d=map(int, input().split())
x=[list(map(int,list(input().split()))) for i in range(n)]
pot = 0
count = 0

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

print(count)

Submission status: Accepted

Solution code:
import bisect
import sys
import math

verbose = False


def get_iv():
    args = sys.stdin.readline()
    argv = args.split()
    iargv = [int(arg) for arg in argv]
    return iargv


def get_fv():
    args = sys.stdin.readline()
    argv = args.split()
    iargv = [float(arg) for arg in argv]
    return iargv


def calc_dist(Lhs, Rhs):
    dist = 0
    for off in range(len(Lhs)):
        dx = Lhs[off] - Rhs[off]
        dist += dx * dx
    dist = math.sqrt(dist)
    return dist


def is_int(fl):
    ifl = int(fl + .5)
    df = abs(ifl - fl)
    return df < 1e-4


def num_sqare(N, X):
    rv = 0
    for i in range(N):
        for j in range(i + 1, N):
            dist = calc_dist(X[i], X[j])
            if is_int(dist):
                rv += 1
    return rv


def main():
    specs = get_iv()
    N = specs[0]
    D = specs[1]
    X = []
    for i in range(N):
        v = get_iv()
        X.append(v)
    rv = num_sqare(N, X)
    print(rv)


if __name__ == '__main__':
    main()
    # mock()

Submission status: Accepted

Solution code:
import numpy as np
N, D = [int(i) for i in input().split()]

list_coord = list()
for i in range(N):
  list_coord.append([int(i) for i in input().split()])
arr_coord = np.array(list_coord)

cnt = 0
for i in range(N):
    for j in range(N-i-1):
        a = np.array(list_coord[i])
        b = np.array(list_coord[N-j-1])
        dist = (abs(np.sum((a-b)**2)))**0.5
        #print(a, b, dist)
        if dist.is_integer():
            cnt+=1
            
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
  sum=0
  N,D=map(int,input().split())
  box=[]
  for i in range(N):
    box.append(list(map(int,input().split())))
  for i in range(N):
    for j in range(i+1,N):
    	sum+=check(box[i],box[j])
  print(sum)

def check(a,b):
  sum=0
  for i in range(len(a)):
    sum+=(a[i]-b[i])**2
  sum=sum**(1/2)
  if sum%1==0:
    return 1
  else:
    return 0
main()

Submission status: Accepted

Solution code:
import itertools

def kyori(Y,Z):
    sum = 0
    for i in range(D):
        sum+= (Y[i]-Z[i])**2
    return pow(sum,0.5)

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

candidList = list(itertools.combinations(X,2))
ans=0
for cand in candidList:
    if float.is_integer(kyori(cand[0],cand[1])):
        ans+=1
    else:
        continue

print(ans)

Submission status: Accepted

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

row = list()
count = 0
for i in range(N):
  x = [int(_) for _ in input().split()]
  if i == 0:
    row.append(x)
  else:
    for j in range(len(row)):
      dist = 0
      for k in range(D):
        dist += (row[j][k]-x[k])**2
      if (dist**0.5)-int(dist**0.5)==0:
      	count += 1
    row.append(x)
      
print(count)

Submission status: Accepted

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

n,d = [int(c) for c in input().split(' ')]

points = []
for i in range(n):
    p = [int(c) for c in input().split(' ')]
    points.append(p)

num_int = 0

for i in range(n):
    for j in range(n):
        if i != j:
            y = numpy.array(points[i])
            z = numpy.array(points[j])
            
            u = y - z
            
            dist = numpy.linalg.norm(u)

            if dist.is_integer():
                num_int += 1

print(num_int // 2)

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
import math

N, D = [int(x) for x in stdin.readline().rstrip().split()]

X = list()
for y in range(N):
    X.append([int(z) for z in stdin.readline().rstrip().split()])

count = 0

for i in range(N):
    for j in range(N):
        if i >= j:
            continue
            
        # 平方和の取り方
        # [分散, 標準偏差ぐらいまでの統計 \- Qiita](https://qiita.com/tiny/items/aefc87f7fec913864623)
        s = sum((X[i][d] - X[j][d])**2 for d in range(D))
        distance = math.sqrt(s)

        # [Pythonで数値が整数か小数かを判定 \| note\.nkmk\.me](https://note.nkmk.me/python-check-int-float/)
        if distance.is_integer():
            count += 1

print(count)

Submission status: Accepted

Solution code:
from math import sqrt

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

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

result = 0

for i in range(n):
    for j in range(i + 1, n):
        distance = 0
        for k in range(d):
            distance += abs(x[i][k] - x[j][k]) ** 2
        else:
            if distance == 0 or sqrt(distance).is_integer():
                result += 1

print(result)

Submission status: Accepted

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

def dist(arr1,arr2):
    tmp = 0
    for i in range(D):
        tmp += (arr1[i] - arr2[i])**2

    return math.sqrt(tmp)

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

count = 0
for i in range(N-1):
    for j in range(i+1,N):
        a = dist(array[i],array[j])
        if a//1 == a:
            count += 1

print(count)

Submission status: Accepted

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

points = []
tmp_p  = []

for i in range(N):
    tmp_p = list(map(int, input().split()))
    points.append(tmp_p)

points_arr = np.array(points)

# print(points_arr)

param_result = 0
for param_start in range(N):
    # print("****************************")

    for param_end in range(N):

        if  param_start >= param_end:
            # print(param_start)
            # print(param_end)
            # print("PASS: s > e")
            pass

        else:
            # print(param_start)
            # print(param_end)

            dist = points_arr[param_start,] - points_arr[param_end,]
            res = np.linalg.norm(dist)
            # print(res)

            if res.is_integer() is True:
                # print("is int")
                param_result += 1
            else:
                # print("is float")
                pass

print(param_result)

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(n-1):
    for j in range(i+1, n):
        x_diff = []
        for k in range(len(x[i])):
            x_diff.append(x[i][k]-x[j][k])
        sq_x_diff = [i ** 2 for i in x_diff]
        sum_ = sum(sq_x_diff)**0.5
        if sum_.is_integer():
            cnt += 1
print(cnt)

Submission status: Accepted

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

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

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

ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        dis = np.array(xl[i])-np.array(xl[j])
        squ = np.square(dis)
        su = np.sum(squ)
        sqr = np.sqrt(su)
        if sqr.is_integer():
            ans += 1

print(ans)

Submission status: Accepted

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

print(count)

Submission status: Accepted

Solution code:
#B
import numpy as np

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

for i in range(n):
    x_ = list(map(int, input().split()))
    x.append(x_)
    
is_integer = 0
x = np.asarray(x)

for j in range(0,n,1):
    for i in range(0,j,1):
        diff  = (sum((x[i] - x[j]) ** 2)) ** (1 / 2)
        if diff.is_integer():
            is_integer += 1
            
print(is_integer)

Submission status: Accepted

Solution code:
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 k in range(n):
    for j in range(k+1,n):
        dist=0
        for i in range(d):
            dist+=(x[k][i]-x[j][i])**2
        val=dist**0.5-dist**0.5//1
        if val==0:
            cnt+=1
print(cnt)

Submission status: Accepted

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


def xcheck(n):
	
    m = int(n**.5)
    return 1 if abs(m*m - n) < 1e-6 else 0
#	if(1):
#		#兵法数なら
#		return 1
#	return 0

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

#listx = [[0]*d]*n
listx = [[0 for i in range(d)] for j in range(n)]

for i in range(n):
	tmp = input().split()
	hoge = list(map(lambda a: int(a), tmp))
	#print(hoge)
	for j in range(d):
		listx[i][j] = hoge[j]

sum = 0
for i in range(n):
	for j in range(i+1,n):
#		print("{} {}".format(i,n))
		tmp=0
		for k in range(d):
#			print(pow((listx[i][k]-listx[j][k]),2))
			tmp += pow((listx[i][k]-listx[j][k]),2)
#			print("{} {} tmp {}".format(listx[i][k],listx[j][k],tmp))

#		print("tmp")
#		print(tmp)
#		print(xcheck(tmp))
		sum += xcheck(tmp)

print(sum)




#print(min(n*a,b))

#print(n)
#print(a)
#print(b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

def distance(a, b):
    dis = 0
    for d in range(D):
        dis += (a[d] - b[d])**2
    return np.sqrt(dis)

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

ans = 0
for i in range(N):
    for j in range(i+1, N):
        if(i == j):
            continue
        dis = distance(points[i], points[j])
        ans += (dis % 1) == 0.0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

N,D=map(int, input().split())
S = []
for _ in range(N):
    S.append(list(map(int, input().split())))
x=0
S=np.array(S)
for i in range(N):
    for j in range(i):
        t=np.linalg.norm(S[i]-S[j])
        if t == int(t):
            x+=1      
print(x)

Submission status: Accepted

Solution code:
import math

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

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

tmp = 0
cnt = 0

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

print(cnt)

Submission status: Accepted

Solution code:
import math

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


all_list = []

for i in range(n):
    x = input()
    x = x.split(' ')

    # x = list(x)
    # print(x)
    x = [float(v) for v in x] # to float

    all_list.append(x)  # list of list

# print(all_list)

cnt = 0

for i in range(n):
    target = all_list[i]

    for j in range(n - (i + 1)):
        target2 = all_list[j + i + 1]

        # sum_1 = [u ** 2 + v ** 2 for u, v in zip(target, target2)]
        sum_1 = [(target[q] - target2[q]) ** 2 for q in range(d)]
        sum_2 = sum(sum_1)
        dis = math.sqrt(sum_2)

        # print('---')
        # print(target)
        # print(target2)

        if dis.is_integer():
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
n,D=map(int,input().split())
a = [input().split() for l in range(n)]
c=0
d=0
for i in range(n):
  for j in range(i+1,n):
    d=0
    for t in range(D):
      d=d+(int(a[i-1][t-1])-int(a[j-1][t-1]))**2
    if np.sqrt(d)%1==0:
      c=c+1
print(c)

Submission status: Accepted

Solution code:
# 全部やる
import numpy as np
import itertools
N,D = map(int,input().split())
X = [np.array(input().split(), dtype=np.int64) for _ in range(N)]

answer = 0
for u,v in itertools.combinations(X,2):
  d = ((u-v) * (u-v)).sum()
  dd = int(round(d**.5))
  if d == dd*dd:
    answer += 1

print(answer)

Submission status: Accepted

Solution code:
import numpy as np
n,d = map(int,input().split())
list=[list(map(int,input().split())) for i in range(n)]
arr_list = np.array(list)
count = 0
for i in range(n):
    for j in range(i+1,n):
        if(i != j):
            distance = 0.0
            for k in range(d):
                distance += (arr_list[i][k] - arr_list[j][k])**2
            if(distance > 0):
                result = np.sqrt(distance)
                if(result.is_integer()):
                    count += 1
print(count)

Submission status: Accepted

Solution code:
import math
N,D=map(int,input().split())
points = []
num = 0
for n in range(N):
    p = [ int(i) for i in input().split()]
    points.append(p)

for i in range(len(points)):
    for j in range(len(points) - i - 1):
        sum = 0
        for k in range(D):
            sum += (points[i][k]-points[i+j+1][k])**2
        if float.is_integer(math.sqrt(sum)):
            num += 1
print(num)

Submission status: Accepted

Solution code:
import math
N,D = map(int,input().split())
ans = 0
X_list = []
for a in range(N):
    X_list.append(list(map(int,input().split())))
for i in range(N):
    for j in range(i+1,N):
        rutononaka = 0
        for d in range(D):
            rutononaka += (X_list[i][d]-X_list[j][d])**2
        distance = math.sqrt(rutononaka)
        if distance == (distance//1):
            ans += 1
print(ans)

Submission status: Accepted

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

A = []
for i in range(n):
    for k in range(i + 1, n):
        tmp = 0
        for j in range(d):
            tmp += (L[i][j] - L[k][j]) ** 2
        A.append(pow(tmp, 0.5))

ans = 0

for i in A:
    if i.is_integer():
        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()))
import math
cnt=0
for i, p in enumerate(x):
    for q in range(i+1, n):
        dist=0
        sum=0
        for j in range(d):
            sum+=(p[j]-x[q][j])**2
        dist=math.sqrt(sum)
        if dist.is_integer():
            cnt+=1
print(cnt)

Submission status: Accepted

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

cnt=0
for j in range(N-1):
  for k in range(j+1,N):
    wa=0
    for l in range(D):
      wa += (X[j][l]-X[k][l])**2
    result=wa**(1/2)
    if result.is_integer():
      cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
import math
import itertools

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

X = [[0]*(D+1)]*(N+1)

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

def distance(x, y):
    dis = 0
    for d in range(D):
        dis += abs(x[d] - y[d]) ** 2
    
    return math.sqrt(dis).is_integer()
    
distance(X[1], X[2])

count = 0

for c in itertools.combinations(list(range(N)), 2):
    if distance(X[c[0]], X[c[1]]):
        count += 1
        
print(count)

Submission status: Accepted

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

import sys
import math

input = sys.stdin.readline

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

    n = 0
    for i in range(len(X)):
        for j in range(i+1, len(X)):
            s = 0
            for k in range(D):
                s += (X[i][k] - X[j][k]) ** 2
            if math.sqrt(s).is_integer():
                n += 1
    print(n)

main()

Submission status: Accepted

Solution code:
_input = [i for i in open(0).read().split('\n') if i]
n, d = [int(i) for i in _input[0].split()]
x_list = [[int(i) for i in x.split()]for x in _input[1:]]
x_list2 = x_list[:]

import math

count = 0
for x1 in x_list:
    for x2 in x_list2:
        dist = math.sqrt(sum((x1[i]-x2[i])**2 for i in range(d)))
        if int(dist) == 0:
            continue
        if dist.is_integer():
            count += 1

print(count//2)

Submission status: Accepted

Solution code:
import math
n,d = map(int,input().split())
li = []
li2 = []
cnt = 0
for i in range(n):
    li.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 += (li[i][k] - li[j][k]) ** 2
            li2.append(x)
for a in li2:
    for i in range(1,a//2 + 2):
        if a == i**2:
            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)]

import numpy as np

res=0

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

print(res)