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: Runtime Error

Solution code:
import numpy as np

S      = input()
S      = S.split()
N      = int(S[0])
D      = int(S[1])
matrix = np.zeros([N, D])
count  = 0


for i in range(0, N, 1):
    X_vector = input()
    for j in range(0, D, 1):
        matrix[i][j] = int(X_vector[j])

for i in range(0, N, 1):
    a_vector = matrix[i]
    for j in range(i+1, N, 1):
        b_vector = matrix[j]
        length = np.linalg.norm(b_vector-a_vector)
        if float(length) / float(length) == 0.0:
            count++

print(count)

Submission status: Runtime Error

Solution code:
import math
N,D = map(int,input().split())
3 2
X = [list(map(int,input().split())) for i in range(N)]
1 2
5 5
-2 8

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

print(ans)

Submission status: Runtime Error

Solution code:
N,D =map(int,input().split())
X=[]
cnt = 0
for i in range(N):
  X.append(list(map(int,input().split())))
 
for j in range(N):
  A = X(j)
  for k in range(j,N):
    B = X(k)
    for l in range(D):
        a = (A(D)-B(D))**2
        E.append(a)
        F = sqrt(sum(E))
        G = int(F**.5)
        if abs(G*G-C)<1e-6:
            cnt +=1
 
print(cnt)

Submission status: Runtime Error

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

for j in range(N):
  A = X(j)
  for k in range(j,N):
    B = X(k)
    for l in range(D):
        a = (A(D)-B(D))**2
        E.append(a)
        F = sqrt(sum(E))
        G = int(F**.5)
        if abs(G*G-C)<1e-6:
            cnt +=1

print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def main(n,d, input_data):
    #input_data = np.array(input_data)
    row_list = [x for x in range(n)]
    row_comb = list(itertools.combinations(row_list, 2))
    count = 0
    for tup in row_comb:
        if (2 <= n <= 10 ) and (1 <= d <= 10) :
            #if input_data[tup[0]] != input_data[tup[1]]:
            num_list = [(input_data[tup[0]][x]-input_data[tup[1]][x])**2 for x in range(d)]
            distance = sum(num_list)
            memory = [x for x in range(distance+1)]
            for x in memory:
                if x**2 == distance:
                    count += 1
    return  count


if __name__ == '__main__':
    '''
    s1 = list(map(int, input().split()))
    s2 = [list(map(int, input().split())) for i in range(s1[0])]
    huga = main(s1[0],s1[1], s2)
    print(huga)
    '''
    N = list(map(int, input().split()))
    # 2次元配列
    grid = []
    for i in range(N[0]):
        array = list(map(int, input().strip().split()))
        grid.append(array)
        
    huga = main(N[0],N[1], grid)
    print(huga)

Submission status: Runtime Error

Solution code:
def main(n,d, input_data):
    #input_data = np.array(input_data)
    row_list = [x for x in range(n)]
    row_comb = list(itertools.combinations(row_list, 2))
    count = 0
    for tup in row_comb:
        if (2 <= n <= 10 ) and (1 <= d <= 10) :
            #if input_data[tup[0]] != input_data[tup[1]]:
            num_list = [(input_data[tup[0]][x]-input_data[tup[1]][x])**2 for x in range(d)]
            distance = np.sqrt(sum(num_list))
            if distance == round(distance):
                    count += 1
    return  count


if __name__ == '__main__':
    '''
    s1 = list(map(int, input().split()))
    s2 = [list(map(int, input().split())) for i in range(s1[0])]
    huga = main(s1[0],s1[1], s2)
    print(huga)
    '''
    N = list(map(int, input().split()))
    # 2次元配列
    grid = []
    for i in range(N[0]):
        array = list(map(int, input().strip().split()))
        grid.append(array)
        
    huga = main(N[0],N[1], grid)
    print(huga)

Submission status: Runtime Error

Solution code:
def main(n,d, input_data):
    input_data = np.array(input_data)
    row_list = [x for x in range(n)]
    row_comb = list(itertools.combinations(row_list, 2))
    count = 0
    for tup in row_comb:
        if (2 <= n <= 10 ) and (1 <= d <= 10) :
            #if input_data[tup[0]] != input_data[tup[1]]:
            num_list = [(input_data[tup[0]][x]-input_data[tup[1]][x])**2 for x in range(d)]
            distance = np.sqrt(sum(num_list))
            if distance == round(distance):
                    count += 1
    return  count


if __name__ == '__main__':
    s1 = list(map(int, input().split()))
    s2 = [list(map(int, input().split())) for i in range(s1[0])]
    huga = main(s1[0],s1[1], s2)
    print(huga)

Submission status: Runtime Error

Solution code:
import pandas as pd
import numpy as np

N, D = map(int, input().split(" "))
data = pd.DataFrame()
a = 0
for i in range(N):
    data[i] = list(map(int, input().split(" ")))
for i, j in data.iteritems():
    for k, l in data.iteritems():
        if i < k:
            if np.sqrt(sum((j - l)**2))%1 == 0:
                a += 1
print(a)

Submission status: Runtime Error

Solution code:
def main(n,d, input_data):
    input_data = np.array(input_data)
    row_list = [x for x in range(n)]
    row_comb = list(itertools.combinations(row_list, 2))
    count = 0
    for tup in row_comb:
        if (2 <= n <= 10 ) and (1 <= d <= 10) :
            #if input_data[tup[0]] != input_data[tup[1]]:
            num_list = [(input_data[tup[0]][x]-input_data[tup[1]][x])**2 for x in range(d)]
            distance = np.sqrt(sum(num_list))
            if distance == round(distance):
                    count += 1
    return  count

if __name__ == '__main__':
    s1 = list(map(int, input().split()))
    s2 = [list(map(int, input().split())) for i in range(s1[0])]
    huga = main(s1[0],s1[1], s2)
    print(huga)

Submission status: Runtime Error

Solution code:
def main(n,d, input_data):
    input_data = np.array(input_data)
    row_list = [x for x in range(n)]
    row_comb = list(itertools.combinations(row_list, 2))
    count = 0
    for tup in row_comb:
        if (2 <= n <= 10 ) and (1 <= d <= 10) :
            if input_data[tup[0]] != input_data[tup[1]]:
                num_list = [(input_data[tup[0]][x]-input_data[tup[1]][x])**2 for x in range(d)]
                distance = np.sqrt(sum(num_list))
                if distance == round(distance):
                        count += 1
    return  count

if __name__ == '__main__':
    s1 = list(map(int, input().split()))
    s2 = [list(map(int, input().split())) for i in range(s1[0])]
    huga = main(s1[0],s1[1], s2)
    print(huga)

Submission status: Runtime Error

Solution code:
def main(n,d, input_data):
    input_data = np.array(input_data)
    row_list = [x for x in range(n)]
    row_comb = list(itertools.combinations(row_list, 2))
    count = 0
    for tup in row_comb:
        if (2 <= n <= 10 ) and (1 <= d <= 10) :
            num_list = [(input_data[tup[0]][x]-input_data[tup[1]][x])**2 for x in range(d)]
            distance = np.sqrt(sum(num_list))
            if distance == round(distance):
                    count += 1
    return  count

if __name__ == '__main__':
    s1 = list(map(int, input().split()))
    s2 = [list(map(int, input().split())) for i in range(s1[0])]
    huga = main(s1[0],s1[1], s2)
    print(huga)

Submission status: Runtime Error

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

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

ans=0
for i in range(N-1):
    for j in range(i+1,N):
        if distance(P[i],P[j]).is_integer():
            ans+=1

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
n,d = map(int, input().split())
l=[]
for i in range(n):
  l.append(list(map(int, input().split())))
count = 0
for i in range(n):
  for j in range(i+1,n):
    distance_a = 0
    for k in range(d):
      distance_k= l[i][k]-l[j][k]
      distance_a +=distance_k**2
    distance = np.sqrt(distance_a)
    if distance = int:
      count += 1
print(count)

Submission status: Runtime Error

Solution code:
def dist(a, b):
  res = 0
  for i in range(D):
    res += (a[i] - b[i]) ** 2
    res = res ** 0.5

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

Submission status: Runtime Error

Solution code:
5 1
1
2
3
4
5

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<vector>
#include<cmath>

int main(){
	int n, d;
	std::cin >> n >> d;
	
	std::vector<std::vector<int>> x;
	
	for(int i = 0; i < n; ++i)
	{
		std::vector<int> temp;
		for(int j = 0; j < d; ++j)
		{
			int input;
			std::cin >> input;
			temp.push_back(input);
		}
		x.push_back(temp);
	}
	
	int count = 0;
	for (int i = 0; i < n - 1; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			int sum = 0;
			for (int k = 0; k < d; k++)
			{
				sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
			}
			if (int(std::sqrt(sum))*std::sqrt(sum) == sum)
			{
				++count;
			}
		}
	}
	std::cout << count << std::endl;
}

Submission status: Runtime Error

Solution code:
from math import sqrt
n, d = map(int,input().split())
x = []
for i in range(n):
    xx = list(map(int,input(),split()))
    x.append()
sum = 0
count = 0
for i in range(n):
    for j in range(n):
        if i == j:
            break
        for z in range(d):
            sum = sum + (x[i][d]- x[j][d])**2
            if z == d - 1:
                sum = sqrt(sum)
            if sum % 1 == 0:
                count += 1

print(count // 2)

Submission status: Runtime Error

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] = map(int, input().split())
 
result = 0
for i in range(n):
  for j in range(1,n):
    diff = map(lambda x: x*x, x[i]-x[j])
    calc = math.sqrt(sum(diff))
    if calc.is_integer():
      result +=1
print(result)

Submission status: Runtime Error

Solution code:
import sys
import math
N,D=map(int,sys.stdin.readline().split())
x=[]
count=0
for i in range(N):
    x.append(map(int,sys.stdin.readline().split()))
for i in range(N):
    for j in range(n-1):
        if j>=i:
            k=j+1
        else:
            k=j
        diff=math.sqrt(sum([(a-b)**2 for a,b in x[i],x[k]]))
        if diff-int(diff)==0:
            count+=1
print(count)

Submission status: Runtime Error

Solution code:
N, D = map(int, input().split())
X = []
for i in range(N):
    xi = [int(x) for x in stdin.readline().rstrip().split()]
    X.append(xi)
    
is_int = 0
for i in range(N-1):
    for j in range(i+1, N):
        l1 = np.array(X[i])
        l2 = np.array(X[j])
        d = math.sqrt(sum((l1-l2)**2))
        if isinstance(d, int):
            is_int += 1
print(is_int)

Submission status: Runtime Error

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

is_int = 0
for i in range(N-1):
    for j in range(N-i):
        d = sqrt(sum((X[i]-X[j])**2))
        if isinstance(d, int):
            is_int += 1
print(is_int)

Submission status: Runtime Error

Solution code:
import math
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[B])
        if isinstance(D):
            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)
    return sum

Submission status: Runtime Error

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(n):
    if answer[l].is_integer()==True:
        count=count+1
print(count)

Submission status: Runtime Error

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(n):
    if answer[l].is_integer()==True:
        count=count+1
print(count)

Submission status: Runtime Error

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=[]
if d==1:
  count=combinations(n,2)
  count = int(count)
else:
  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])**2
        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(n):
    if answer[l].is_integer()==True:
      count=count+1
print(count)

Submission status: Runtime Error

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=[]
if d==1:
  count=combinations(n,2)
  count = int(count)
else:
  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])**2
        t.append(c)
        if k==d-1:
          a.append(sum(t))
  answer=list(map(lambda x:pow(x,0.5),a))
  count=0
  for l in range(n):
    if answer[l].is_integer()==True:
      count=count+1
print(count)

Submission status: Runtime Error

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=[]
if d==1:
  count=combinations(n,2)
  count=int(count)
else:
  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(n):
    if answer[l].is_integer()==True:
      count=count+1
print(count)

Submission status: Runtime Error

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=[]
if d==1:
  count=combinations(n,2)
  count = int(count)
else:
  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(n):
    if answer[l].is_integer()==True:
      count=count+1
print(count)

Submission status: Runtime Error

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=[]
if d==1:
  count=combinations(n,2)
  count = int(count)
else:
  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(n):
    if answer[l].is_integer()==True:
      count=count+1
      print(count)
print(count)

Submission status: Runtime Error

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=[]
if d==1:
  count=combinations(n,2)
  count=int(count)
else:
  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(n):
    if answer[l].is_integer()==True:
      count=count+1
print(count)

Submission status: Runtime Error

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=[]
if d==1:
  count=combinations(n,2)
  int(count)
else:
  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(n):
    if answer[l].is_integer()==True:
      count=count+1
      print(count)
print(count)

Submission status: Runtime Error

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: Runtime Error

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


def get_distance(x1, y1, x2, y2):
    d = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
    return d

ans = 0
for i in range(len(c)):
  C_x1 = c[i][0][0]
  C_x2 = c[i][1][0]
  C_y1 = c[i][0][1]
  C_y2 = c[i][1][1]
  d = get_distance(C_x1,C_y1,C_x2,C_y2)
  if d.is_integer():
    ans = ans+1

print(ans)

Submission status: Runtime Error

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


def get_distance(x1, y1, x2, y2):
    d = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
    return d

ans = 0
for i in range(len(c)):
  C_x1 = c[i][0][0]
  C_x2 = c[i][1][0]
  C_y1 = c[i][0][1]
  C_y2 = c[i][1][1]
  d = get_distance(C_x1,C_y1,C_x2,C_y2)
  if type(d):
    ans = ans+1

print(ans)

Submission status: Runtime Error

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=[]
if d==1:
  count=combinations(n,2)
else:
  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(n):
    if answer[l].is_integer()==True:
      count=count+1
print(count)

Submission status: Runtime Error

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=[]
if d==1:
  count=combinations(n,2)
else:
  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(n):
    if answer[l].is_integer()==True:
      count=count+1
print(count)

Submission status: Runtime Error

Solution code:
n,d=input().split()
n=int(n)
d=int(d)
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(n):
  if answer[l].is_integer()==True:
    count=count+1
print(count)

Submission status: Runtime Error

Solution code:
n,d=input().split()
n=int(n)
d=int(d)
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))
print(answer)
count=0
for l in range(n):
  if answer[l].is_integer()==True:
    count=count+1
print(count)

Submission status: Runtime Error

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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,d=map(int,input().split())
ans=0
l=[]
for i in range(n):
  l.append(list(map(int,input().split())))
for i in range(n):
  x=l[i]
  sum=0
  for j in range(i,n):
    y=l[j]
    for k in range(d):
      sum+=(x[k]-y[k])^2
  s=sum^(1/2)
  if s.is_integer():
    ans+=1
  sum=o
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
    N,D =map(int, input().split())
    all_list = [list(map(int, input().split())) for i in range(N)]
    #>>>4
    count = 0
    for n in range (N):
        for nn in range(N):
            distance = 0
            for d in range(D):
                kou = (all_list[n][d] - all_list[nn][d])**2
                distance += kou
            for s in range(250):
                if distance == s**2:
                    count += 1
                    break
    print(round((count - N) / 2) +)

Submission status: Runtime Error

Solution code:
count = 0
    for n in range (N):
        for nn in range(N):
            distance = 0
            for d in range(D):
                kou = (all_list[n][d] - all_list[nn][d])**2
                distance += kou
            for s in range(250):
                if distance == s**2:
                    count += 1
                    break
    print(round((count - N) / 2))

Submission status: Runtime Error

Solution code:
import numpy as np
import math
n,d=[int(i) for i in inpput().split()]
x=[]
for _ in range(n):
  x.append(np.array([int(i) for i in input().split()]))
def dis(x,y):
  return int(np.sum((x-y)**2))
def iss(x):
  a=round(math.sqrt(x))
  return a**2==x
k=0
for i in range(n):
  for j in range(i+1,n):
    if iss(dis(x[i],x[j])):
      k+=1
print(k)

Submission status: Runtime Error

Solution code:
a,b = input().split(' ')

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

count = 0
for j in range(int(a)):
  for k in range(int(a)):
    if j > k:
    ans = 0
    for l in rnage(int(b)):
      ans = ans + (int(c[j][l]) ** 2 - int(c[k][l]) ** 2) ** 0.5

    if ans = int(ans):
      count = count + 1

print(count)

Submission status: Runtime Error

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

for i in range(n):
    for j in range(i+1,n):
        dis=0
        for k in range(d):
            dis = (L[i][k]-L[j][k])**2
        dis = dis**0.5
        if(dis == int(dis):
            ans +=1
print(ans)

Submission status: Runtime Error

Solution code:
import math
n, d = [int(i) for i in input().split()]
dot = []
for _ in range(n):
  zahyo = list(map(int, input().split()))
  dot.append(zahyo)
cnt = 0
for i in range(n-1):
  for j in range(i+1, n):
    for k in range(d):
      test += pow(dot[i][k] - dot[j][k], 2)
    test_a = float(math.sqrt(test))
    test_b = int(math.sqrt(test))
    if(test_a == test_b):
      cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
import math
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):
        res = 0
        for z in range(d):
            res += (x[i][z]-x[j][z])**2
        if math.sqrt(res)**2==res:
            cnt += 1
print(cnt)

Submission status: Runtime Error

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

rows = []
for _ in range(d):
    row = list(map(int, input().split()))
    rows.append(row)

from itertools import permutations

count = 0
for tup in permutations(list(range(len(rows)))):
    c = 0
    x = rows[tup[0]]
    y = rows[tup[1]]
    for _x, _y in zip(x, y):
        c += (_x - _y) ** 2

    root = int(pow(c, 1 / 2))
    dm = divmod(c, root)
    if dm[0] == root and dm[1] == 0:
        count += 1

print(count)

Submission status: Runtime Error

Solution code:
n, d = map(int, input())

rows = []
for _ in range(d):
  row = list(map(int, input().split()))
  rows.append(row)

from itertools import permutations

count = 0
for tup in permutations(list(range(len(rows)))):
  c = 0
  x = rows[tup[0]]
  y = rows[tup[1]]
  for _x, _y in zip(x, y):
    c += (_x - _y) ** 2
  
  root = int(pow(c, 1/2))
  dm = divmod(c, root)
  if dm[0] == root and dm[1] == 0:
    count += 1

print(count)

Submission status: Runtime Error

Solution code:
n, d = map(int, input())

rows = []
for _ in range(d):
  row = list(map(int, input().split()))
  rows.append(row)

from itertools import permutations

count = 0
for tup in permutations(list(range(len(rows)))):
  c = 0
  x = rows[tup[0]]
  y = rows[tup[1]]
  for _x, _y in zip(x, y):
    c += (_x - _y) ** 2
  
  root = int(pow(c/2))
  dm = divmod(c, root)
  if dm[0] == root and dm[1] == 0:
    count += 1

print(count)

Submission status: Runtime Error

Solution code:
import math


def is_distance_integer(p1, p2):
    n = len(p1)

    total = 0
    for i in range(n):
        total += ((p1[i] - p2[i])**2)

    dist = math.sqrt(total)

    return (dist**2) == total


def count_pairs(points):
    cnt = 0
    n = len(points)

    for i in range(n):
        for j in range(i + 1, n):
            if is_distance_integer(points[i], points[j]):
                cnt += 1

    return cnt


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

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

    ans = count_pairs(points)

    print(ans)


main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

counter = 0

for i in range(n):
    for j in range(n):
        ans = np.sum((s[i] - s[j]) ** 2)
        if ans == int(ans):
            counter += 1

print(counter)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

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

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

# print(grid)
cnt = 0
grid2 = list(itertools.combinations(grid, 2))
for i in grid2:
    x = numpy.array(i[0])
    y = numpy.array(i[1])
  #  print(x, y)
    dis = numpy.linalg.norm(y - x)
    # print(dis)
    if (dis.is_integer()):
        #print(dis)
        cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:

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

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

# print(grid)
cnt = 0
grid2 = list(itertools.combinations(grid, 2))
for i in grid2:
    x = numpy.array(i[0])
    y = numpy.array(i[1])
  #  print(x, y)
    dis = numpy.linalg.norm(y - x)
    # print(dis)
    if (dis.is_integer()):
        #print(dis)
        cnt += 1