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

Solution (Python):
import math
n, d = map(int, input().split())
a = []
ans = 0
x = 0
if d ==1:
  for i in range(n):
    a.append(int(input()))
  for i in range(n):
    for j in range(i,n):
      if math.sqrt((a[i]-a[j])**2)%1==0 and math.sqrt((a[i]-a[j])**2)!=0:
        ans += 1
else:
  for i in range(n):
    a.append(list(map(int, input().split())))
  for i in range(n):
    for j in range(i, n):
      x = 0
      for k in range(d):
        x += (a[i][k] - a[j][k]) **2
      if math.sqrt(x)%1 == 0 and math.sqrt(x) != 0:
        ans += 1
print(ans)

Solution (Python):

import math
N,D = map(int,input().split())
x = []
dis = []
cnt = 0

for i in range(N):
    x.append(list(map(int,input().split())))
    
for i in range(N-1): 
    for j in range(i+1,N): 
        num = 0
        for m in range(D):
            num += (x[i][m]-x[j][m])*(x[i][m]-x[j][m])
        dis.append(num)
        
for i in dis:
    if int(math.sqrt(i)) == math.sqrt(i):
        cnt += 1
        
print(cnt)

Solution (Python):
from itertools import combinations
import math


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

xn = []
for i in range(n):
  x = [int(num) for num in input().split()]
  xn.append(x)
  
answer =  0
for i,j in combinations(range(n),2):
    sum = 0.0
    for k in range(d):
        sum += (xn[i][k]-xn[j][k])**2
    if math.sqrt(sum).is_integer():
        answer += 1
 
print(answer)

Solution (Python):
N,D=map(int,input().split())
res = 0
List = []
for i in range (N):
  List.append(list(map(int, input().split())))
  
def calcDist(ListX,a,b):
  n = 0
  for k in range(D):
    x = ListX[a][k] - ListX[b][k]
    n += x*x
  n = n ** 0.5
  nn = int(n)
  if n-nn > 0:
    return False
  else:
    return True

for i in range(N):
  for j in range(N):
    if i == j:
      pass
    else:
      if calcDist(List,i,j):
        res += 1
res = res //2
print(res)

Solution (Python):
from itertools import combinations
from math import sqrt

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

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

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

l = len(X)
cnt = 0

for i in range(l):
    for j in range(i+1, l):
        distance = sum((X[i][d]-X[j][d])**2 for d in range(d))**0.5
        if distance == int(distance):
            cnt += 1
        else:
            continue
            
print(cnt)

Solution (Python):
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):
    s = 0
    for k in range(d):
      s += abs(x[i][k] - x[j][k])**2
    s = s**0.5
    if s.is_integer(): ans += 1
print(ans)

Solution (Python):
N, D = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        d = sum(abs(a[i][k] - a[j][k]) ** 2 for k in range(D)) ** 0.5
        cnt += d % 1 == 0
print(cnt)

Solution (Python):
import numpy as np
import math
n,d = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(n)]
count_true = 0
for i in range(n):
  for j in range(i+1,n):
    a = 0
    for k in range(d):
      a += pow((x[i][k]-x[j][k]),2)
    a = math.sqrt(a)
    b = int(a)
    if a == b :
      count_true += 1
        
print(count_true)

Solution (Python):
import math

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

arr=[list(map(int,input().split())) for i in range(N)]
count=0

def dis(x,y):
    a=0
    for i in range(len(x)):
        a+=(x[i]-y[i])*(x[i]-y[i])
    return math.sqrt(a)
    
for i in range(N-1):
    for j in range(i+1,N):
        if dis(arr[i],arr[j])%1==0:
            count+=1

print(count)

Solution (Python):
n, d = map(int, input().split())
p = [[int(j) for j in input().split()] for i in range(n)]
cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        dist = 0
        for k in range(d):
            dist += (p[i][k] - p[j][k])**2
        if int(dist**0.5) == dist**0.5:
            cnt += 1
print(cnt)

Solution (Python):
import math

def main():
    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(N - 1):
        for j in range(i + 1, N):
            t = 0
            for k in range(D):
                t = t + ((x[i][k] - x[j][k]) ** 2)
            t = math.sqrt(t)
            if t.is_integer() == True:
                count += 1
    print(count)
main()

Solution (Python):
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):
        dist = 0
        for k in range(d):
            dist += (x[i][k] - x[j][k]) ** 2
        dist **= 0.5
        if dist.is_integer():
            ans += 1
print(ans)

Solution (Python):
import math

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

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

def dist(a,b):
    cnt = 0
    for i in range(len(a)):
        cnt += (a[i]-b[i])**2
    return math.sqrt(cnt)

ans = 0
    
for i in range(n):
    for j in range(i+1,n):
        if dist(l[i],l[j])%1 == 0:
            ans+=1
print(ans)

Solution (Python):
import math
a,b=map(int, input().split()) 
x=[list(map(int,input().split()))for _ in range(a)]
c = 0

for i in x:
    for j in x:
        ans = 0
        for k in range(b):
            ans += abs(i[k]-j[k])**2
        q = math.sqrt(ans)
        if q.is_integer() == True:
            c += 1
d = (c-a)//2
print(d)

Solution (Python):


import sys
from math import sqrt
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

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


def check_bi(Y, Z):
    sum_ = 0
    for y, z in zip(Y, Z):
       sum_ += (y-z)**2

    for i in range(int(sqrt(sum_))+1):
        if i * i == sum_:
            return True
    return False


count = 0
for i, x in enumerate(X[:len(X)-1]):
    for y in X[i+1:]:
        count += check_bi(x, y)

print(count)

Solution (Python):
N,D=map(int,input().split())
X=[list(map(int,input().split())) for i in range(N)]
l=len(X)
c=0
for i in range(l):
 for j in range(i+1,l):
  t=sum((X[i][d]-X[j][d])**2for d in range(D))**0.5
  c+=t==int(t)
print(c)

Solution (Python):
N,D=map(int,input().split())
X=[list(map(int,input().split())) for i in range(N)]
l=len(X)
cnt=0
for i in range(l):
 for j in range(i+1,l):
  t=sum((X[i][d]-X[j][d])**2for d in range(D))**0.5
  cnt+=t==int(t)
print(cnt)

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

Solution (Python):
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):
  for j in range(i+1, n):
    a = x[i]
    b = x[j]
    z = 0
    for k in range(d):
      z += (a[k] - b[k]) ** 2
    if math.sqrt(z) % 1 == 0:
      cnt += 1
print(cnt)

Solution (Python):
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
c = 0
for i in range(N):
  for j in range(i+1, N):
    c += (sum((X[i][p]-X[j][p])**2 for p in range(D))**.5).is_integer()
print(c)

Solution (Python):
import sys
import itertools
N,D = map(int,input().split())
array = [ list(map(int,input().split())) for x in range(N) ]

if not ( 2 <= N <= 10 and 1 <= D <= 10 ): sys.exit()
for I in array:
    if not ( -20 <= min(I) and max(I) <= 20 ): sys.exit()

count = 0
for I in list(itertools.combinations(array,2)):
    tmp_distance = 0
    for J in range(D):
        tmp_distance += abs(I[0][J] - I[1][J]) ** 2
    distance = tmp_distance ** 0.5 
    if distance.is_integer(): count += 1

print(count)

Solution (Python):
import math

n, d = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
c = 0
for i in range(n):
    for j in range(n):
        x = 0
        for k in range(d):
            x += (l[i][k] - l[j][k])**2
        y = math.sqrt(x)
        if y != 0 and y.is_integer():
            c += 1
print(c//2)

Solution (Python):
N, D = map(int, input().split())
coordinates = []
c_append = coordinates.append
count = 0

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

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

print(count)

Solution (Python):
import math
N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
num = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        A, B = X[i], X[j]
        d = math.sqrt(sum([(A[k] - B[k]) ** 2 for k in range(D)]))
        if abs(d - int(d)) < 10 ** (-4):
            num += 1
print(num)

Solution (Python):
n, d = map(int,input().split())
points = []

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

def distance(a, b):
  dist = 0
  
  for a, b in zip(a, b):
    dist += (a - b) ** 2

  if dist == 0:
    return False
  return int(dist ** 0.5) ** 2 == dist

count = 0

for pa in points:
  for pb in points:
    if distance(pa, pb):
      count += 1

print(count // 2)

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

points = []

for _ in range(n):
    points.append(list(map(int, input().split())))

def distance(a, b):
    dist = 0

    for a, b in zip(a, b):
        dist += (a - b) ** 2

    if dist == 0:
        return False

    return int(dist ** 0.5) ** 2 == dist

count = 0

for pa in points:
    for pb in points:
        if distance(pa, pb):
            count += 1

print(count // 2)

Solution (Python):
n, d = map(int, input().split())
ans = 0
a = [list(map(int, input().split())) for i in range(n)]
import math
for i in range(n-1):
    for j in range(i+1, n):
        dist = math.sqrt(sum([(a[i][k]-a[j][k])**2 for k in range(d)]))
        if (int(dist) == dist):
            ans += 1
print(ans)

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

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

def isSquare(x):
  f = 1
  while f * f <= x:
    if f * f == x:
      return True
    else:
      f += 1
  return False
  
def calcSquareOfDistance(p1,p2,dimension):
  s = 0
  for i in range(dimension):
    s += (p1[i] - p2[i])**2
  return s

def judge(p1,p2,dimension):
  return isSquare(calcSquareOfDistance(p1,p2,dimension))

ans = 0
for i in range(N-1):
  for j in range(i+1,N):
    if judge(a[i],a[j],D):
      ans += 1
print(ans)

Solution (Python):
import itertools
import numpy as np

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

ans = 0
for d_list in list(itertools.combinations(Dist, 2)):
  x = np.array(d_list[0])
  y = np.array(d_list[1])
  tmp = 0
  for i in (x-y):
    tmp += i*i
  k = tmp**0.5
  if k == int(k):
    ans += 1

print(ans)

Solution (Python):
import math
N,D = map(int,input().split())
X = []
for i in range(N):
  X.append(list(map(int,input().split())))
ans = 0
for i in range(N):
  for j in range(i+1,N):
    now = 0
    dis = 0
    for k in range(D):
      now += (X[i][k]-X[j][k])**2
    dis = math.sqrt(now)
    if dis%1 == 0:
      ans += 1
print(ans)

Solution (Python):
n,d = map(int,input().split())
dots = []
ans = 0
for _ in range(n):
  t = list(map(int,input().split()))
  if len(dots)!=0:
    for l in dots:
      a = [(y-z)**2 for y,z in zip(t,l)]
      if ((sum(a))**.5).is_integer():
        ans += 1
  dots.append(t)
print(ans)

Solution (Python):
import math
n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
cnt = 0

def distance(list1, list2) :
    dist = 0
    for i in range(len(list1)) :
        dist += (list1[i] - list2[i]) ** 2
    return math.sqrt(dist)

for i in range(n) :
    for j in range(i+1,n) :
        if i != j :
            if int(distance(x[i], x[j])) == distance(x[i], x[j]) :
                cnt += 1
print(cnt)

Solution (Python):
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+1,n):
        z = 0
        for k in range(d):
            z += (x[i][k]-x[j][k])**2
        z = z**0.5
        if z.is_integer():
            ans += 1
print(ans)

Solution (Python):
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):
        count = 0
        for y in range(d):
            count += abs(x[i][y]-x[j][y])**2

        if (count**0.5) % 1 == 0:
            ans += 1

print(ans)

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







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



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

print(count)

Solution (Python):
import math
n,d = map(int,input().split())
x = [0] * n
ans = 0
for i in range(n):
    x[i] = list(map(int,input().split()))
for i in range(n):
    for j in range(i+1,n):
        l = math.sqrt(sum((x[i][f] - x[j][f])**2 for f in range(d)))
        if l%1 == 0:
            ans += 1
print(ans)

Solution (Python):
(n,d),*xx = [list(map(int, s.split())) for s in open(0)]

from itertools import combinations

ans = 0
for i, j in combinations(range(n),2):
    s = sum((a-b)**2 for a,b in zip(xx[i],xx[j]))
    if s == round(s**0.5)**2:
        ans += 1

print(ans)

Solution (Python):
from math import sqrt
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):
        dis = 0
        for d in range(D):
            dis += (X[j][d] - X[i][d]) ** 2
        if sqrt(dis).is_integer():
            cnt += 1
print(cnt)

Solution (Python):
import math
n,d = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(n)]
count = 0
for i in range(n-1):
    for j in range(i+1,n):
        ans = 0
        for k in range(d):
            ans += (x[i][k]-x[j][k])**2
        if math.sqrt(ans).is_integer() == True:
            count += 1
print(count)

Solution (Python):
import math

def main():
    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+1, N):
            v = sum((y - z) ** 2 for y, z in zip(X[i], X[j]))
            dist = round(math.sqrt(v))
            if v == dist ** 2:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n,d =map(int,input().split())
    X = []
    for i in range(n):
        tmp = [int(i) for i in input().split()]
        X.append(tmp)
    ans = 0
    for i in range(n):
        for j in range(i+1,n):
            s = 0
            for k in range(d):
                s += (X[i][k]-X[j][k])**2
            s = s**0.5
            
            if s.is_integer():
                ans += 1
    print(ans)
main()

Solution (Python):
import math

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

Solution (Python):
import math
n,d=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
cnt=0
for i in range(0,len(l)-1):
    for j in range(i+1,len(l)):
        sum_num=0
        for k in range(d):
            sum_num+=(l[i][k]-l[j][k])**2
        sum_num=math.sqrt(sum_num)
        if int(sum_num)==sum_num:
            cnt+=1
print(cnt)

Solution (Python):
from itertools import combinations
N, D = map(int, input().split())
X = [tuple(map(int, input().split())) for _ in range(N)]
res = 0
for i, j in combinations(list(range(N)), 2):
    tmp = sum((y - z) ** 2 for y, z in zip(X[i], X[j]))
    tmp **= 0.5
    if tmp == int(tmp):
        res += 1
print(res)

Solution (Python):

import math
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, d = LI()
x = LIR(n)
ans = 0
dists = []
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
        for l in range(1, dis + 1):
            if l ** 2 == dis:
                ans += 1
                break
print(ans)

Solution (Python):

import math
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, d = LI()
x = LIR(n)
ans = 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
        dis = math.sqrt(dis)
        if float(dis).is_integer():
            ans += 1
print(ans)

Solution (Python):
import sys, os, math, bisect, itertools, collections, heapq, queue

from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def calcTwoPointDistance(x1, y1, x2, y2):
    return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, D = il()
    XY = [il() for _ in range(N)]

    ret = 0
    for x, y in itertools.combinations(XY, 2):
        tmp = 0
        for d in zip(x, y):
            tmp += abs(d[0] - d[1])**2

        if (tmp ** 0.5).is_integer():
            ret += 1
    print(ret)


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import combinations
import math
n,d=map(int,input().split())
X=[list(map(int,input().split())) for _ in range(n)]
cnt=0
for perm in list(combinations(range(n),2)):
    d=sum(map(lambda x: (x[0]-x[1])**2,zip(X[perm[0]],X[perm[1]])))
    if d==int(math.sqrt(d))**2:
        cnt+=1
print(cnt)

Solution (Python):
from itertools import combinations
import math
N, D = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
for perm in list(combinations(range(N), 2)):
    d = sum(map(lambda x: (x[0] - x[1]) ** 2, zip(X[perm[0]], X[perm[1]])))
    if d == int(math.sqrt(d)) ** 2:
        cnt += 1
print(cnt)

Solution (Python):
import math
N,M=list(map(int,input().split()))
all=[list(map(int,input().split())) for k in range(N)]
cnt=0
for i in range(N-1):
  for t in range(i+1,N):
    ans=0
    for h in range(M):
      ans+=(all[i][h]-all[t][h])**2
    ans=math.sqrt(ans)
    if ans%1==0:
      cnt+=1
print(cnt)

Solution (Python):
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

N, D = rl()
X = []
for i in range(N):
	X.append(rl())

def check(x, y):
	d = 0
	for i in range(D):
		d += (x[i]-y[i])**2
	d = d**0.5
	if d == int(d):
		return True
	return False

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

Solution (Python):

import math 

N,D=map(int,input().split())
a=[]
ans=0
for _ in range(N):
    tmp=list(map(int,input().split()))
    a.append(tmp)
for i in range(N-1):
    for k in range(i+1,N):
        dst=0
        for j in range(D):
            dst+=(a[i][j]-a[k][j])**2
        dst=math.sqrt(dst)
        if dst== int(dst):
            ans+=1
print(ans)

Solution (Python):
n, d = map(int, input().split())
distances = [list(map(int, input().split())) for _ in range(n)]
ans = 0

for i in range(n):
    for j in range(i + 1, n):
        diff_total = 0
        for k in range(d):
            diff = abs(distances[i][k] - distances[j][k])
            diff_total += diff * diff

        flag = False
        for k in range(diff_total + 1):
            if (k * k) == diff_total:
                flag = True
        if flag:
            ans += 1
print(ans)

Solution (Python):
import math
N, D = map(int,input().split())
X = []
for i 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):
    dst = 0
    for k in range(D):
      dst += (X[i][k]-X[j][k])**2
    dst = math.sqrt(dst)
    if dst == int(dst):
      count+=1
print(count)

Solution (Python):
n, d = map(int, input().split())
lst = []
for _ in range(n):
  x = list(map(int, input().split()))
  lst.append(x)
ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    dist = 0
    for k in range(d):
      dist += (lst[i][k] - lst[j][k])**2
    j = 1
    while j**2 <= dist:
      if j**2 == dist:
        ans += 1
        break
      j += 1
print(ans)

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

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

sq = set()
for i in range(1, 1000):
  sq.add(i**2)

def foo(x,y):
  t = 0
  for i, j in zip(X[x], X[y]):
    t += (i - j) * (i - j)
  if t in sq:
    return 1
  else:
    return 0
    
ans = 0

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

print(ans)

Solution (Python):









import sys
import math
import itertools
input = sys.stdin.readline

N, D = map(int, input().split())
P = []
for i in range(N):
    P.append(list(map(int, input().split())))
ans = 0
for c in itertools.combinations(range(N), 2):
    i = c[0]
    j = c[1]
    dis = 0
    for k in range(D):
        dis += (P[j][k] - P[i][k])**2
    if math.sqrt(dis) == int(math.sqrt(dis)):
        ans += 1
print(ans)

Solution (Python):
import math


def input2():
	return map(int,input().split())


def input_array():
	return list(map(int,input().split()))

def euclid(y,z,d):
	result=0
	for i in range(d):
		result+=(y[i]-z[i])**2
	return math.sqrt(result)


n,d=input2()
X=[input_array() for _ in range(n)]

count=0
for i in range(n):
	for j in range(i+1,n):
		distance=euclid(X[i],X[j],d)
		if (distance%1) == 0:
			count+=1
print(count)

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

for i in range(n):
    for j in range(i+1,n):
        t = 0
        for k in range(d):
            t += abs(x[i][k] - x[j][k]) ** 2
        l.append(t)

l.sort()
i = 1
while i ** 2 <= l[-1]:
    o.append(i ** 2)
    i += 1

p = 0
for i in range(len(o)):
    p += l.count(o[i])

print(p)

Solution (Python):
import numpy as np

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

X = np.array(X)
for k in range(N):
    for l in range(k+1, N):
        Xd = X[k] - X[l]
        dis = np.linalg.norm(Xd, ord=2)

        if dis.is_integer():
            cnt += 1

print(cnt)

Solution (Python):
n, d = map(int, input().split())
x = list(list(map(int, input().split())) for _ in range(n))

ans = 0
for i in range(len(x)):
    for j in range(i+1, len(x)):
        dist = sum((x-y)**2 for x, y in zip(x[i], x[j]))**0.5
        if dist.is_integer(): ans += 1

print(ans)

Solution (Python):
import sys
import numpy as np
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))

n, _ = rm()
li = np.array([np.array(rl()) for _ in range(n)])
cnt = 0
for i in range(n):
  for j in range(i):
    a = sum((li[i] - li[j]) ** 2)**0.5
    if a - a//1 == 0:
      cnt += 1
print(cnt)

Solution (Python):
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n, _ = rm()
li = np.array([np.array(rl()) for _ in range(n)])
cnt = 0
for i in range(n):
  for j in range(i):
    a = sum((li[i] - li[j]) ** 2)**0.5
    if a - a//1 == 0:
      cnt += 1
print(cnt)

Solution (Python):
import math
N,D = map(int,input().split())
Xs = [list(map(int,input().split()))for i in range(N)]
c = 0
for i in range(N-1):
  X1 = Xs[i]
  for j in range(i+1,N):
    X2 = Xs[j]
    su = 0
    for k in range(D):
      su += abs(X1[k]-X2[k]) **2
    distance = math.sqrt(su)
    if distance.is_integer():
      c+=1
print(c)

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, D = LI()
    X = [LI() for _ in range(N)]

    MAX_DIST = 16000
    square_num = set()
    i = 1
    while i ** 2 <= MAX_DIST:
        square_num.add(i ** 2)
        i += 1

    ans = 0
    for i, j in itertools.combinations(range(N), 2):
        if sum([(k - l) ** 2 for k, l in zip(X[i], X[j])]) in square_num:
            ans += 1

    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):
import numpy as np
import math
from collections import Counter

def cumsum(x):
    return list(np.cumsum(x))

def cumsum_number(N,K,x):
    ans=[0]*(N-K+1)
    number_cumsum = cumsum(x)
    number_cumsum.insert(0,0)
    for i in range(N-K+1):
        ans[i]=number_cumsum[i+K]-number_cumsum[i]
    return ans
"""
int 
float 


list0 = [] 
list0 = [1,2,3,4] 
list0 = [0]*10 
list1= [i for i in range(10)] 
list1 = list(map(int, input().split()))　
number=[int(input()) for i in range(int(input()))] 
list1 = list1 + [6, 7, 8] 
list2.append(34) 
list.insert(3,10) 
len(list4) 
max(sa) 
list5.count(2) 
list1.sort() 
list1.sort(reverse=True)  
set(list1) 
sum([2,3,   ,3]) 

number=Counter(list) 

abs(a) 
max(a,b) min(a,b) 
text1 = text1.replace("34","test") 
sorted(S) 
exit(0) 

cumsum(リスト) 
cumsum_number(N,K,x) 

alphabet={0:"A",1:"B",2:"C",3:"D",4:"E",5:"F",6:"G",7:"H",8:"I",9:"J",
          10:"K",11:"L",12:"M",13:"N",14:"O",15:"P",16:"Q",17:"R",18:"S",19:"T",
          20:"U",21:"V",22:"W",23:"X",24:"Y",25:"Z",}
print(*S,sep="") 

math.floor() 
math.ceil() 
"""
def dist(a,b):
    res = 0
    for i in range(D):
        res += (a[i]-b[i])**2
    res = res**0.5
    return res

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):
        if dist(X[i],X[j]).is_integer():
            ans+=1
print(ans)

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

Solution (Python):
import math
n,d=map(int,input().split())
x=[]
for _ in range(n):
    x.append(list(map(int,input().split())))
ans=0
i=0
for i in range(n-1):
    for j in range(i+1,n):
        l2=0
        for k in range(d):
            l2+=(x[i][k]-x[j][k])**2
        if math.ceil(math.sqrt(l2))==math.floor(math.sqrt(l2)):
            ans+=1
print(ans)

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

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

Solution (Python):
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n,d = i2()
x = []
for i in range(n):
	a = intl()
	x.append(a)

def dist(a,b,d):
	dist = 0
	for i in range(d):
		dist += (a[i] - b[i])**2
	return dist		

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

Solution (Python):
import numpy as np
n, d = map(int, input().split())
x = [np.array(list(map(int, input().split()))) for _ in range(n)]
cnt = 0
for i in range(len(x)-1):
  x_i = x[i]
  for j in x[i+1:]:
    m = x_i - j
    if float(np.linalg.norm(m)).is_integer():
      cnt += 1
print(cnt)