Problem: 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?

Submission attempts (in order):
n , d =map(int,input().split())
import sys
import math
 
a = [map(int,input().split()) for l in range(n)]
count = 0
 
for i in range(n):
  for j in range(n):
    if i == j:
      count += 0
    else:
      d = math.sqrt((a[i][0] - a[j][0]) ** 2 + (a[i][1] - a[j][1]) ** 2 +(a[i][2] - a[j][2]) ** 2  +(a[i][3] - a[j][3]) ** 2  + (a[i][4] - a[j][4]) ** 2)
      d = float(d)
      if d.is_integer():
        count += 1
print(count)

n , d =map(int,input().split())
import sys
import numpy as np
 
a = [[int(c) for c in l.strip()] for l in sys.stdin]
a_ = np.array(a)
count = 0
 
for i in range(n):
  for j in range(n):
    if i == j:
      count += 0
    else:
      u = a[i] - a[j]
      norm = numpy.linalg.norm(u)
      if norm.is_integer():
        count += 1
print(count)

n , D =map(int,input().split())
import sys
import math

a = [input().split() for l in range(n)]
count = 0
 
for i in range(n):
  for j in range(n):
    if i == j:
      count += 0
    else:
      x = []
      for c in range(D):
        x.append((int(a[i][c]) - int(a[j][c])) ** 2)
      d = math.sqrt(sum(x))
      d = float(d)
      if d.is_integer():
        count += 1
print(count/2)

n , D =map(int,input().split())
import sys
import math

print(n)
a = [input().split() for l in range(n)]
print(a)
count = 0
 
for i in range(n):
  for j in range(n):
    if i == j:
      count += 0
    else:
      x = []
      for c in range(D):
        x.append((int(a[i][c]) - int(a[j][c])) ** 2)
      d = math.sqrt(sum(x))
      d = float(d)
      if d.is_integer():
        count += 1
print(count/2)

n , d =map(int,input().split())
import sys
import numpy

a = [[int(c) for c in l.strip()] for l in sys.stdin]
a_ = np.array(a)
count = 0

for i in range(n):
  for j in range(n):
    if i == j:
      count += 0
    else:
      u = a[i] - a[j]
      norm = numpy.linalg.norm(u)
      if norm.is_integer():
        count += 1
print(count)


n , d =map(int,input().split())
import sys
import math
 
a = [[int(c) for c in l.strip()] for l in sys.stdin]
count = 0
 
for i in range(n):
  for j in range(n):
    if i == j:
      count += 0
    else:
      d = math.sqrt((a[i][0] - a[j][0]) ** 2 + (a[i][1] - a[j][1]) ** 2 +(a[i][2] - a[j][2]) ** 2  +(a[i][3] - a[j][3]) ** 2  + (a[i][4] - a[j][4]) ** 2)
      d = float(d)
      if d.is_integer():
        count += 1
print(count)

n , D =map(int,input().split())
import math
 
a = [input().split() for l in range(n)]
count = 0
 
for i in range(n):
  for j in range(n):
    if i == j:
      count += 0
    else:
      x = []
      for c in range(D):
        x.append((int(a[i][c]) - int(a[j][c])) ** 2)
      d = math.sqrt(sum(x))
      d = float(d)
      if d.is_integer():
        count += 1
print(int(count/2))

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

Runtime Error

Accepted