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):
N, D = map(int, input().split())
X = [list(map(float, input().split())) for i in range(N)]

cnt = 0
for i in range(N-1):
  for j in range(N-i-1):
    jj = j+i+1
    dis = 0.0
    for k in range(D):
      dis += (X[i][k] - X[jj][k])**2
    dis = dis**0.5
    if dis.is_integer():
      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):
        dis = 0
        for k in range(d):
            dis += (x[i][k]-x[j][k])**2
        if math.sqrt(dis) % 1 == 0:
            cnt += 1
print(cnt)

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

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

Solution (Python):
n,D = map(int,input().split())
X  =[]
for _ in range(n):
    x = list(map(int,input().split()))
    X.append(x)
ans = 0
for i in range(n):
    for j in range(i+1,n):
        val = 0
        for d in range(D):
            val += (X[i][d]-X[j][d])**2
        val = val**0.5
        if val.is_integer():
            ans += 1
print(ans)

Solution (Python):
n,d=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
t=0
for i in range(n):
  for j in range(i+1,n):
    s=0
    for b,c in zip(a[i],a[j]):
      s+=(b-c)**2
    if s**0.5==int(s**0.5):
      t+=1

print(t)

Solution (Python):
import math


def calc_distance(Y, Z):
    temp = 0
    for y, z in zip(Y, Z):
        temp += (y-z)**2
    return temp


def is_integer(num):
    for k in range(1, num+1):
        if k*k == num:
            return True
    else:
        return False


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

Solution (Python):
n, d = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
t = 0
for i in range(n):
  for j in range(i+1, n):
    s = 0
    for b, c in zip(a[i], a[j]):
      s += (b - c) ** 2
    if s ** 0.5 == int(s ** 0.5):
      t += 1
print(t)

Solution (Python):
import sys
n,d = map(int, sys.stdin.readline().rstrip("\n").split())
x = [ [int(s) for s in line.split()] for line in sys.stdin ]
ans = 0
l = [False]*20001
for m in range(1,142):
    l[m*m] = True
for i in range(n):
    for j in range(i+1,n):
        distance = 0
        for dim in range(d):
            distance += (x[i][dim] - x[j][dim])**2
        if l[distance]:
            ans += 1
print(ans)

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

count = 0
for i in range(n):
    for j in range(i + 1, n):
        norm = 0
        for k in range(d):
            diff = abs(X[i][k] - X[j][k])
            norm += diff * diff
        can = False
        for k in range(1, norm + 1):
            if(k * k == norm):
                can = True
        if(can):
            count += 1

print(count)

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

for i in range(n):
    xi = [int(s) for s in input().split()]
    x.append(xi)

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

Solution (Python):
import math
N, D = map(int, input().split( ))
A = []
def d(a,b):
  s = 0
  for i in range(len(a)):
    s += (a[i] - b[i])**2
  return math.sqrt(s)

for _ in range(N):
  A.append(list(map(int, input().split( ))))
ans = 0
for i in range(N):
  for j in range(i+1,N):
    s = d(A[i],A[j])
    if s.is_integer():
      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 n in range(N):
  for m in range(n+1,N):
    dis = 0
    for d in range(D):
      dis += (a[n][d]-a[m][d])**2
    if math.sqrt(dis) == int(math.sqrt(dis)):
      ans += 1
print(ans)

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

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


s_list=[]

for i in range(n-1):
    for j in range(i+1, n):
        
        sum=0
        for k in range(d):
            sum+=(a[i][k]-a[j][k])**2
        s_list.append(sum)
        

num=int(max(s_list)**(1/2))

count=0
for i in range(num+1):
    for j in s_list:
        if j==i**2:
            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)]

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
from math import ceil, floor, log2,sqrt

from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations




def solve():
    N, D = MI()
    X = []
    for i in range(N):
        X.append(LI())
        
    
    ans = 0
    for i, j in product(range(N), repeat=2):
        if i == j:
            continue
        Y = X[i]
        Z = X[j]
        dist = 0
        for d in range(D):
            dist += (Y[d] - Z[d])**2
        sq = sqrt(dist)
        
        if dist % sq == 0:
            ans += 1
    print(ans // 2)

if __name__ == '__main__':
    solve()

Solution (Python):
r=input().split()
N=int(r[0])
D=int(r[1])
d=[[int(s) for s in input().split()] for i in range(N)]
ans=0
for i in range(N-1):
    for j in range(i+1,N):
        dis=0
        for k in range(D):
            dis+=(d[i][k]-d[j][k])**2
        ans_pre=dis**(1/2)
        if type(ans_pre)==int or ans_pre.is_integer()==True:
            ans+=1
print(ans)

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    def calc(p, q):
        res = 0
        for i in range(D):
            res += (X[p][i] - X[q][i]) ** 2
        return res

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

    sq = set(x ** 2 for x in range(1000))
    
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            d = calc(i, j)
            if d in sq:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readlines
from math import sqrt

def isSquare(n):
    m = int(sqrt(n))
    for x in range(m-2, m+2):
        if x**2 == n:
            return True

def getDistance(xi, xj, dimention):
    d = 0
    for i in range(dimention):
        d += (xi[i] - xj[i])**2
    return d

def main():
    lines = input()

    n, d = list(map(int, lines[0].split()))
    x = []
    for i, xi in enumerate(lines[1:]):
        x.append(list(map(int, xi.split())))

    cnt = 0

    for i, xi in enumerate(x):
        for j, xj in enumerate(x[i+1:]):
            dist = getDistance(xi, xj, d)
            if isSquare(dist):
                cnt += 1
    print(cnt)

main()

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readlines
from math import sqrt

def isSquare(n):
    m = int(sqrt(n))
    for x in range(1, m+1):
        if x**2 == n:
            return True

def getDistance(xi, xj, dimention):
    d = 0
    for i in range(dimention):
        d += (xi[i] - xj[i])**2
    return d

def main():
    lines = input()

    n, d = list(map(int, lines[0].split()))
    x = []
    for i, xi in enumerate(lines[1:]):
        x.append(list(map(int, xi.split())))

    cnt = 0

    for i, xi in enumerate(x):
        for j, xj in enumerate(x[i+1:]):
            dist = getDistance(xi, xj, d)
            if isSquare(dist):
                cnt += 1
    print(cnt)

main()

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readlines
from math import sqrt

def isSquare(n):
    m = int(sqrt(n))
    for x in range(1, m+1):
        if x**2 == n:
            return True

def getDistance(xi, xj, dimention):
    d = 0
    for i in range(dimention):
        d += (xi[i] - xj[i])**2
    return d

def main():
    lines = input()

    n, d = list(map(int, lines[0].split()))
    x = []
    for i, xi in enumerate(lines[1:]):
        x.append(list(map(int, xi.split())))

    cnt = 0

    for i, xi in enumerate(x):
        for j, xj in enumerate(x[i+1:]):
            dist = getDistance(xi, xj, d)
            if isSquare(dist):
                cnt += 1
    print(cnt)

main()

Solution (Python):
a,n = map(int,input().split())
point = []
for i in range(a):
  linea = list(map(int,input().split()))
  point.append(linea)

counta = 0
for j in range(a):
  for k in range(j+1,a):
    dist = 0
    for l in range(n):
      dist += (point[j][l] - point[k][l])**2

    if dist**0.5 == int(dist**0.5):
      counta += 1

print(counta)

Solution (Python):

import math

def get_dist(x, y, d):
    dist = 0
    for i in range(d):
        dist += (x[i] - y[i]) ** 2

    return math.sqrt(dist)


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

cnt = 0
for i in range(N):
    for j in range(i+1, N, 1):
        x = X_list[i]
        y = X_list[j]
        num = get_dist(x, y, D)
        if(num.is_integer()):
            cnt += 1

print(cnt)

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


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


for j in range(n):
    for k in range(j + 1, n):
        c = 0
        for l in range(d):
            c += (num_list[j][l] - num_list[k][l]) ** 2
    
        if (int(c**0.5))**2 == c :
            cnt += 1
        
print(cnt)

Solution (Python):
from math import sqrt
n, d = map(int, input().split())

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


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


ans = 0
for i in range(n):
    for j in range(i+1, n):
        dist = ds(vs[i], vs[j])
        if dist == int(dist):
            ans += 1

print(ans)

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

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

ans = 0
for i in range(n):
    for j in range(i+1,n):
        temp = 0
        for y,z in zip(range(d),range(d)):
            temp += (total[i][y] - total[j][z])**2
        if temp**0.5 == int(temp**0.5):
            ans += 1

print(ans)

Solution (Python):
import numpy as np
import math
n,d = map(int, input().split())
x = np.array(list(input().split() for _ in range(n)), dtype=int)
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        s = math.sqrt(sum((x[i]-x[j])**2))
        if s.is_integer():
            ans += 1
print(ans)

Solution (Python):
import math
import numpy as np
n, d = map(int,input().split())
a=[]
for i in range(n):
  a.append(list(map(int, input().split())))
ans=0
mat= np.array(a, dtype=object)
for i in range(n-1):
  for j in range(i+1,n):
    x= (mat[i]-mat[j])**2
    hei=math.sqrt(sum(x))
    if int(hei)==hei:
      ans+=1
      
print(ans)

Solution (Python):
def good_distance():
    N, D = input().split()
    N = int(N)
    D = int(D)
    P = list()
    for a in range(N):
        P.append(list())
        P[a] = input().split()
    for a in range(N):
        for b in range(D):
            P[a][b] = int(P[a][b])
    print()
    result = cal_good_distance(P, D)
    print(result)

def cal_good_distance(x, D):
    count = 0
    count_a = 0
    for a in x:
        if count_a == len(x):
            break
        for b in range(count_a+1, len(x)):
            distance = 0
            for i in range(D):
                distance = distance + (x[count_a][i] - x[b][i])**2
            distance = distance ** (1/2)
            try:
                if isinstance(distance, int) or distance.is_integer():
                    count += 1
            except AttributeError:
                pass
        count_a += 1
    return count

good_distance()

Solution (Python):
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(N):
        sum = 0.0
        if i != j:
            for k in range(len(X[i])):
                sum += (X[i][k] - X[j][k])**2
        sum = sum**0.5
        if sum.is_integer() and sum!=0.0:
            cnt += 1
print(cnt//2)

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



lis = []
for i in range(n):
    for j in range(i + 1, n):
        
        lis1 = []
        for k in range(d):
            l_x = (x[i][k] - x[j][k]) ** 2
            lis1.append(l_x)
        lis.append(sum(lis1) ** 0.5)

ans = 0
for i in range(len(lis)):
    if lis[i].is_integer() == True:
        ans += 1

print(ans)

Solution (Python):
n, d = map(int, input().split())
ar = []
count = 0
for i in range(n):
  ar.append(list(map(int, input().split())))
  
for i in range(n):
  for j in range(n):
    s = 0
    if i == j:
      break
    else:
      for k in range(d):
        s += (ar[i][k] - ar[j][k])**2
      f = s**(1/2)
      if f.is_integer(): 
        count +=1
print(count)

Solution (Python):
from itertools import combinations

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

combi = list(combinations(range(N), 2))

ans = 0
for Y, Z in combi:
    dist = 0
    for i in range(D):
        dist += (X[Y][i] - X[Z][i])**2
    if dist**0.5 <= int(dist**0.5):
        ans += 1

print(ans)

Solution (Python):
import math

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

cnt=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 = math.sqrt(dis)

    if dis==math.floor(dis):
      cnt+=1
print(cnt)

Solution (Python):
import math
N, D = map(int, input().split())
X = []
for n in range(N):
    l = list(map(int, input().split()))
    X.append(l)

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

ans = 0

for i in range(N-1):
    for j in range(i + 1, N):
        d = distance(X[i], X[j])
        if d.is_integer():
            ans += 1
        else:
            pass

print(ans)

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

Solution (Python):
import numpy as np
from itertools import combinations
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
cnt = 0

for i, j in combinations(X, 2):
    cnt += (sum(dif**2 for dif in np.array(i) - np.array(j))**.5).is_integer()
print(cnt)

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

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))

from itertools import combinations
import math

def main():
    n, d = Input()
    x = [mapt(int, input().split()) for _ in range(n)]
    
    comb = list(combinations(x,2))
    
    ans = 0
    for a, b in comb:
        r = 0
        for y, z in zip(a, b):

            r += abs(y-z)**2
            
        r = math.sqrt(r)
        if (r*2)%2==0:
            ans += 1
    print(ans)

main()

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

for i in range(n):
    xi = [int(s) for s in input().split()]
    x.append(xi)

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

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

Solution (Python):
squares = set({})
for i in range(1,130):
    squares.add(i**2)

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

ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        sum = 0
        for k in range(D):
            sum += (X[i][k]-X[j][k])**2
        if sum in squares:
            ans += 1

print(ans)

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):
        norm = 0
        for k in range(d):
            diff = abs(x[i][k] - x[j][k])
            norm += diff ** 2

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

print(ans)

Solution (Python):
n,d=map(int,input().split())
x= [list(map(int, input().split())) for i in range(n)]
lis=list(i**2 for i in range(0,128))
ans=0
for i in range(n):
    for k in range(i+1,n):
        check=0
        for j in range(d):
            check+=(x[i][j]-x[k][j])**2
        if check in lis:
            ans+=1
print(ans)

Solution (Python):
n,d=map(int,input().split())
x=[list(map(int, input().split())) for i in range(n)]
count=0
ans=0
for i in range(n):
    for z in range(i+1,n):
        for c in range(d):
            ans+=(x[i][c]-x[z][c])**2
        if (ans**0.5)%1==0:
            count+=1
        ans=0
print(count)

Solution (Python):
n,d=[int(x) for x in input().split()]
x=[]
for i in range(n):
  X=[int(x) for x in input().split()]
  x.append(X)
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
    for l in range(181):
      if dis==l**2:
        ans+=1
        break
print(ans)

Solution (Python):
from math import sqrt


def calc_distance(Y, Z):
    return sqrt(sum((y - z) ** 2 for y, z in zip(Y, Z)))


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):
        distance = calc_distance(X[i], X[j])
        cnt += distance.is_integer()
print(cnt)

Solution (Python):
import math
from itertools import combinations
N,D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]

combination = list(combinations(range(N),2))

cnt = 0
for i,j in combination:
  distance = 0
  for k in range(D):
    distance += abs(X[i][k] - X[j][k]) ** 2
  distance = math.sqrt(distance)
  if distance == math.floor(distance):
    cnt += 1
    
print(cnt)

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

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(i+1,N):
        dist = 0
        for p in range(D):
            dist += (X[i][p]-X[j][p])*(X[i][p]-X[j][p])
        dist = math.sqrt(dist)
        if dist == int(dist):
            ans+=1
                
print(ans)

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

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

Solution (Python):
import math
from itertools import combinations
n, d = map(int, input().split())

def is_distance_int(y, z):
    ans = 0
    for i, j in zip(y, z):
        ans += (i-j)**2
    for k in range(1, ans+1):
        if k**2 == ans:
            return 1
    return 0

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

c = [i for i in range(n)]
c = combinations(c, 2)

ans = 0
for i, j in c:
    ans += is_distance_int(x[i], x[j])

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

print(ans)

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):
        num = 0
        for k in range(d):
            num += (x[i][k] - x[j][k])**2
        for l in range(200):
            if num == l**2:
                ans += 1
print(ans)

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

for n in range(N):
  x = list(map(int,input().split()))
  X.append(x)
  
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 
    if (distance**0.5).is_integer():
      count += 1
      
print(count)

Solution (Python):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy


import heapq
sys.setrecursionlimit(10**6)

INF = 10**18
import bisect
import statistics
mod = 10**9+7


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

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

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

ans = 0
for i in range(N):
    for j in range(i+1,N):
        d = 0
        for k in range(D):
            d += (x[i][k] - x[j][k])**2
        if abs(math.sqrt(d) - int(math.sqrt(d))) < 10**(-9):

            ans += 1
print(ans)

Solution (Python):
n,d = map(int, input().split())
x = [[] for g in range(n)]
c = 0
ans = 0
for h in range(n):
  x[h] = list(map(int, input().split()))
for i in range(0,n-1):
  for j in range(i+1,n):
    for k in range(d):
      c += (x[i][k] - x[j][k])**2
    if (c**0.5).is_integer():
      ans += 1
    c = 0
print(ans)

Solution (Python):



import math



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


def dis(Y,Z):
    ans = 0
    for i in range(D):
        ans += (Y[i] - Z[i])**2
    return math.sqrt(ans)

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

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

print(ans)

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-1):
    for j in range(i+1, N):
        d = 0
        for k in range(D):
            d += (X[i][k] - X[j][k])**2
        ans += math.sqrt(d).is_integer()
print(ans)

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-1):
    for j in range(i+1, N):
        d = 0
        for k in range(D):
            d += (X[i][k] - X[j][k])**2
        ans += math.sqrt(d).is_integer()

print(ans)

Solution (Python):
N,D=map(int,input().split())
A=[]
for i in range(N):
  A.append(list(map(int,input().split())))
sum=0
count=0
for i in range(N):
  for j in range(i+1,N):
    for k in range(D):
      sum+=(A[i][k]-A[j][k])**2
    sum=(sum)**0.5
    if sum.is_integer():
      count+=1
    sum=0
print(count)

Solution (Python):



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


from itertools import combinations

ans =0

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

c=list(combinations(ls,2))


for i in range (len(c)):
    a=f(c[i][0],c[i][1],D)
    if a==a//1:
        ans+=1
    

print(ans)

Solution (Python):
import math
N,D = map(int,input().split())
X = [[int(i) for i in input().split()] for _ in range(N)]
ans = 0
for i in range(N-1) :
    xi = X[i]
    for j in range(i+1,N) :
        xj = X[j]
        d2 = 0
        for k in range(D) :
            d2 += abs(xi[k]-xj[k])**2
        d = int(math.sqrt(d2))
        if d ** 2 == d2 :
            ans += 1

print(ans)

Solution (Python):
n,d=map(int,input().split())
a=[]
for _ in range(n):
  w=list(map(int,input().split()))
  a.append(w)
  
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    c=0
    for f in range(d):
      c+=(a[i][f]-a[j][f])**2
      
    for r in range(0,151):
      if c==r**2:
        ans+=1
        
print(ans)

Solution (Python):




import math

def distance_square(x, y, d):
    z = 0
    for i in range(d):
        z += (x[i] - y[i]) ** 2
    return z

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

res = 0
for i in range(num):
    for j in range(i):
        z = distance_square(points[i], points[j], dim)
        if z == int(math.sqrt(z)) ** 2:
            res += 1

print(res)

Solution (Python):
from math import sqrt as r
from itertools import combinations as C

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

L = list(C(list(range(N)), 2))


def dis(a, b):
    ans = 0
    for i in range(D):
        ans += (X[a][i] - X[b][i])**2
    return r(ans)


ans = 0

for l in L:
    ans_ = dis(l[0], l[1])
    if str(ans_)[-1] == "0":
        ans += 1

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

for i in range(0, n):
  for j in range(i+1, n):
    
    D = math.sqrt(sum((x[i][k] - x[j][k])**2 for k in range(d)))
    if D.is_integer() == True:
      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(0, n):
  for j in range(i+1, n):
    D = []
    for k in range(d):
        D.append((x[i][k] - x[j][k])**2)
    D = math.sqrt(sum(D))
    if isinstance(D, int) == True or D.is_integer() == True:
      cnt += 1

print(cnt)

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

ans = 0
for i,a in enumerate(X[:-1]):
    for b in X[i+1:]:
        d = 0
        for x,y in zip(a,b):
            d += (x-y)**2
        if d**0.5 - int(d**0.5) < 10e-10:
            ans += 1
print(ans)

Solution (Python):
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,d=mp()
l=[]
for i in range(n):
    l.append(lmp())
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        a=0
        for k in range(d):
            a+=(l[i][k]-l[j][k])**2
        if (a ** .5).is_integer():
            ans+=1
print(ans)

Solution (Python):
import math

N,D = map(int,input().split())
x = []
count = 0

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

for i in range(N):
    for j in range(i+1,N):
        Distance = 0
        for k in range(D):
            Distance += (x[i][k] - x[j][k])**2
        
        if math.sqrt(Distance) == int(math.sqrt(Distance)):
            count += 1
            
print(count)