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 numpy as np
import itertools

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

i = 1
sq = []
while i**2 <= 40**2*10:
    sq.append(i**2)
    i += 1

cnt = 0
l = [int(i) for i in range(n)]
for v in itertools.combinations(l, 2):
    i, j = v[0], v[1]
    sub = x[i] - x[j]
    dist = sum(sub**2)
    if dist in sq:
        cnt += 1
print(cnt)

Solution (Python):
def resolve():
    N, D = list(map(int, input().split()))
    X = [list(map(int, input().split())) for _ in range(N)]
    cnt = 0
    import itertools
    for i, j in itertools.combinations(list(range(N)), 2):
        dist = 0
        for d in range(D):
            dist += (X[i][d] - X[j][d])**2
        dist = dist**(0.5)
        if dist == int(dist):
            cnt += 1
    print(cnt)
    
if '__main__' == __name__:
    resolve()

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

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):
import sys
sys.setrecursionlimit(10**7) 
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right

from collections import deque, defaultdict


from collections import Counter

from itertools import accumulate,combinations,permutations

from heapq import heapify,heappop,heappush


from functools import reduce,lru_cache

from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    

    
    N, D = map(int, input().split())
    
    
    S = tuple(tuple(map(int, input().split())) for i in range(N)) 
    ans=0
    for i in range(N):
        for j in range(i+1,N):
            si=S[i]
            sj=S[j]
            dis=0
            for k in range(D):
                dis+=(si[k]-sj[k])**2
            if round(dis**0.5)**2==dis:
                ans+=1
    print(ans)





if __name__ == "__main__":
    main()

Solution (Python):

import sys
from collections import deque, defaultdict
from math import sqrt, factorial





def d(a, b):
    ans = 0
    n = len(a)
    for i in range(n):
        ans += (a[i] - b[i]) ** 2
    return int(ans**0.5) == ans**0.5

def solve():
    n, _ = [int(x) for x in input().split()]
    ans = 0
    points = []
    for _ in range(n):
        arr = [int(x) for x in input().split()]   
        points.append(arr)
    for i in range(n):
        for j in range(i+1, n):
            ans += d(points[i], points[j])
    print(ans)

t = 1

for case in range(1,t+1):
    ans = solve()




"""

4
1 2
2 4
1 3
3
2 2 4
4 5 6

6
1 2
2 3
3 4
4 5
4 6
3
3 5 6
2 17 31 5 11

"""

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

for i in range(N):
  for j in range(i):
    d = sum([(X[i][d]-X[j][d])**2 for d in range(D)])**0.5
    if d.is_integer():
      a+=1

print(a)

Solution (Python):
import sys
import itertools
import math
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, d = map(int, input().split())
    x = []
    for _ in range(n):
        x.append(list(map(int, input().split())))
    ans = 0
    for comb in itertools.combinations(range(n), 2):
        dis = 0
        for i, j in zip(x[comb[0]], x[comb[1]]):
            dis += (i - j)**2
        if str(math.sqrt(dis)).split('.')[-1] == '0':
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

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

Solution (Python):
def f(x,y):
    A=0
    for i in range(len(x)):
        A+=(x[i]-y[i])*(x[i]-y[i])
    return A

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

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

S=set()
k=0
L=4*M*M*D
while k*k<=L:
    S.add(k*k)
    k+=1
    
K=0
for i in range(N):
    for j in range(i+1,N):
        K+=(f(X[i],X[j]) in S)
print(K)

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

Solution (Python):
import numpy as np
N,D = (int(x) for x in input().split())
X = np.zeros((N,D),dtype=int)
for I in range(0,N):
    X[I,:] = np.array([int(x) for x in input().split()],dtype=int)
    
Count = 0
for I in range(0,N-1):
    for II in range(I+1,N):
        if np.linalg.norm(X[I,:]-X[II,:]).is_integer():
            Count += 1
print(Count)

Solution (Python):

import numpy as np

n, d = map(int, input().split())
x = [np.array([*map(int, input().split())]) for _ in range(n)]
c = 0
for i in range(n):
    for j in range(i + 1, n):
        c += np.linalg.norm(x[i] - x[j]).is_integer()
print(c)

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

Solution (Python):
import math

def get_distance(l1, l2):
    dis = 0
    for i in range(len(l1)):
        dis += (l1[i]-l2[i]) ** 2
    return math.sqrt(dis)

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

for n in range(N-1):
    for d in range(n+1, N):
        dis = get_distance(X[n], X[d])
        if dis.is_integer():
            ans += 1

print(ans)

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

def dist_squere(x, y):
    d = 0
    for i,j in zip(x,y):
        d += (i-j)**2
    return d**.5

from itertools import combinations

ans = 0
for x,y in combinations(X, 2):
    if dist_squere(x, y).is_integer():
        ans += 1

print(ans)

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

def dist_squere(x, y):
    d = 0
    for i,j in zip(x,y):
        d += (i-j)**2
    return d

squares = set([i*i for i in range(10000)])
def is_square(x):
    return x in squares

from itertools import combinations

ans = 0
for x,y in combinations(X, 2):
    if is_square(dist_squere(x, y)):
        ans += 1

print(ans)

Solution (Python):
n, d = map(int, input().split())
x = []
sum_ = 0
count = 0

for ni in range(n):
    e = list(map(int, input().split()))
    x.append(e)

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

print(count)

Solution (Python):
def lin(x,y):
    return np.sqrt(sum((x-y)**2))

from itertools import combinations as cb
n,d = map(int,input().split())
import numpy as np

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

cnt = 0
for a,b in cb(range(n),2):
    
    if lin(x[a],x[b]).is_integer():
        cnt += 1

print(cnt)

Solution (Python):
import numpy as np
N,D = list(map(int,input().split()))
 
lis =[list(map(int,input().split())) for i in range(N)]
lis_np = np.array(lis)
counter = 0
for i in range(N-1):
    for j in range(i+1,N):
        kyori = (sum((lis_np[:][i] - lis_np[:][j])**2))**0.5
        if kyori == int(kyori):
            counter += 1
        
print(counter)

Solution (Python):
import math

n,d = map(int,input().split())
ans = 0
li=[list(map(int,input().split())) for i in range(n)]

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

print(ans)

Solution (Python):
n,d = [int(z) for z in input().split()]
p=[]
for g in range(n):
      p.append([int(z) for z in input().split()])
c=0

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

for j in range(n):
      for k in range(j+1,n):
            z = dist(p[j],p[k])
            
            if (type(z)==float)or(type(z)==int):
                       if (z%1==0):
                             c+=1
print(c)

Solution (Python):
from decimal import Decimal
import math
n,d=map(int,input().split())
x=[]
ans=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):
        tmp=0
        for k in range(d):
            tmp+=(x[i][k]-x[j][k])**2
        tt=math.sqrt(tmp)
        if tt==int(tt):
            ans+=1
print(ans)

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

for _ in range(N):
    line = tuple(map(int, input().split()))
    coordinates.append(line)

count = 0
for i in range(N):
    for j in range(i+1, N):

        total = 0
        for y, z in zip(coordinates[i], coordinates[j]):
            total += abs(y - z) ** 2
    
        for k in range(1, total+1):
            if k * k == total:
                count += 1

print(count)

Solution (Python):
import math
a,b=map(int,input().split())
c=[]
for _ in range(a):
    c.append(list(map(int,input().split())))
ans=0
for i in range(a):
    for j in range(i):
        n=c[i]
        m=c[j]
        result=[(x-y)**2 for (x,y) in zip(n,m)]
        if math.sqrt(sum(result))%1==0:
            ans+=1
print(ans)

Solution (Python):
N,D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]
count = 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==int(s)):
            count+=1
print(count)

Solution (Python):
def main():
    import math
    n, d = map(int, input().split())
    inlis = []
    for i in range(n):
        inlis.append(list(map(int, input().split())))
    
    ans = 0
    for i in range(n):
        for j in range(n):
            if i < j:
                dist = 0
                for k in range(d):
                    dist += (inlis[i][k] - inlis[j][k])**2
                if (dist ** 0.5).is_integer():
                    ans += 1
    print(ans)
if __name__ == "__main__":
    main()

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

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

print(ans)

Solution (Python):
import math
N,D=map(int,input().split())
cord=[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):
        distance=math.sqrt(sum((cord[i][s]-cord[j][s])**2 for s in range(D)))
        if distance-int(distance)<=0.0001:
            ans+=1

print(ans)

Solution (Python):
import itertools
import math

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

ans = 0
for i in itertools.combinations(x, 2):
    length = 0
    for j in range(d):
        length += (i[0][j] - i[1][j]) ** 2
    if math.sqrt(length) % 1 == 0:
        ans += 1
print(ans)

Solution (Python):
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):
        a = 0
        for l in range(D):
            a += (X[i][l] - X[j][l])**2
        a = a ** 0.5
        if a.is_integer():
            cnt += 1
        
print(cnt)

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

a = 0
cnt = 0
for i in range(N-1):
    for j in range(i+1, N):
        for l in range(D):
            a += (X[i][l] - X[j][l])**2
        a = a ** 0.5
        if a.is_integer():
            cnt += 1
        a = 0

print(cnt)

Solution (Python):
def distance(a,b):
    return abs((a-b)**2)

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-1):
    for j in range(i+1,n):
        current = 0
        for k in range(d):
            current += distance(x[i][k],x[j][k])
        current = math.sqrt(current)
        if float.is_integer(current):
            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):
    t = 0
    for k in range(d):
      t += (x[i][k]-x[j][k])**2
    t = t**0.5
    if t.is_integer():
      ans += 1
print(ans)

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

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

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-1):
    for j in range(i+1, n):
        y = 0
        for k in range(d):
            y += (x[i][k] - x[j][k])**2

        y = math.sqrt(y)
        if y.is_integer():
            ans += 1
print(ans)

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

Solution (Python):
n, d = map(int, input().split())
sqs = set([i ** 2 for i in range(500)])
lst = []
for i in range(n):
  temp = list(map(int, input().split()))
  lst.append(temp)
cnt = 0
for i in range(n - 1):
  for j in range(i + 1, n):
    nrm = 0
    for k in range(d):
      nrm += (lst[i][k] - lst[j][k]) ** 2
    if nrm in sqs:
      cnt += 1
print(cnt)

Solution (Python):
def resolve():
    import math
    N, D = [int(i) for i in input().split()]
    X = [list(map(int, input().split())) for _ in range(N)]
    cnt = 0
    for i in range(N):
        for j in range(i + 1, N):
            sumA = 0
            for k in range(D):
                sumA += (X[j][k] - X[i][k])**2
            if math.sqrt(sumA).is_integer():
                cnt += 1
    print(cnt)


resolve()

Solution (Python):
import math

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

print(cnt)

Solution (Python):
import numpy as np
N,D=map(int,input().split())
X=[np.array(input().split(),dtype=np.int64) for _ in range(N)]
ans=0
for i in range(N):
    for j in range(i+1,N):
        d=((X[i]-X[j])*(X[i]-X[j])).sum()
        dd=int(round(d**.5))
        if d==dd*dd:
            ans +=1
print(ans)

Solution (Python):
import math

def gooddistance(l1, l2):
    calc = []
    
    for i in range(len(l1)):
        calc.append((l1[i] - l2[i])**2)

    if math.sqrt(sum(calc)).is_integer():
        return 1
    else:
        return 0

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

for i in range(n):
    for j in range(i+1,n):
       count += gooddistance(lst[i],lst[j])

print(count)

Solution (Python):
n,d=[int(x) for x in input().rstrip().split()]

l=[]
for i in range(n):
  X=[int(x) for x in input().rstrip().split()]
  l.append(X)

ans=0
for i in range(n):
  ni=l[i]
  for j in range(i+1,n):
    nj=l[j]
    now=0
    for s in range(d):
      now+=(ni[s]-nj[s])**2
    now=now**0.5
    if now.is_integer():
        ans+=1
print(ans)

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

from math import sqrt
ans=0

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

print(ans)

Solution (Python):
import math

N, D = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(N)]
counter = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        temp = 0
        for k in range(D):
            temp += ((x[i][k] - x[j][k]) ** 2)
        temp = math.sqrt(temp)
        if temp.is_integer():
            counter += 1
print(counter)

Solution (Python):
import numpy as np
N,D=map(int,input().split())
X=[np.array(input().split(),dtype=np.int64) for _ in range(N)]
ans=0
for i in range(N):
    for j in range(i+1,N):
        d=((X[i]-X[j])*(X[i]-X[j])).sum()
        dd=int(round(d**.5))
        if d==dd*dd:
            ans +=1
print(ans)

Solution (Python):
import math
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):
        sum  = 0
        if i != j:
            for k in range(d):
                sum += (l[i][k] -l[j][k]) ** 2
            dis = math.sqrt(sum)
            if dis % 1 == 0:
                ans += 1
print(ans)

Solution (Python):
import math
from math import fabs
def main(inp1, inp2, X):
    FinalValue = 0
    for all in range(inp1+1):
        for iterater in range(all + 1, inp1):
            var = 0.0
            for rangeinp2 in range(inp2):
                var += fabs( (int(X[all][rangeinp2]) - int(X[iterater][rangeinp2]))**2 )
            var = var ** 0.5
            varint=int(var)
            if var==varint:
                FinalValue += 1
    return FinalValue
inp1, inp2 = map(int, input().split())
X = [input().split() for _ in range(inp1)]
print(main(inp1, inp2, X))

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

res = 0
for i in range(N - 1):
    for k in range(i + 1, N):
        ans = 0.0
        for j in range(D):
            ans += abs( (int(X[i][j]) - int(X[k][j]))**2 )
    
        ans = ans ** (1/2)
        if ans.is_integer():
            res += 1

print(res)

Solution (Python):

url = "https://atcoder.jp//contests/abc133/tasks/abc133_b"
import itertools
def main():
    n,d = list(map(int, input().split()))
    lis = []
    for i in range(n):
        t = list(map(int, input().split()))
        lis.append(t)
    count = 0
    for i in range(len(lis)):
        for j in range(i+1, len(lis)):
            if i == j:
                continue
            if float.is_integer(ret(lis[i], lis[j])):
                count += 1
    print(count)


import math
def ret(a,b):
    retval = 0
    idx = 0
    while True:
        if idx == len(a):
            break
        retval += abs(a[idx]-b[idx])**2
        idx += 1
    return math.sqrt(retval)

if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def distance2_nd(p, q):
    return sum((px - qx) ** 2 for px, qx in zip(p, q))


def isqrt(n):
    if n > 0:
        x = 1 << (n.bit_length() + 1) // 2
        y = (x + n // x) // 2
        while y < x:
            x = y
            y = (x + n // x) // 2
        return x
    elif n == 0:
        return 0
    else:
        raise ValueError("isqrt() argument must be nonnegative")


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

    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            d2 = distance2_nd(X[i], X[j])
            di = isqrt(d2)
            if di * di == d2:
                ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import math
def gooddistance(l1, l2):
    calc = []
    for i in range(len(l1)):
        calc.append((l1[i] - l2[i])**2)

    if math.sqrt(sum(calc)).is_integer():
        return 1
    else:
        return 0

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

for i in range(N):
    for j in range(i+1,N):
       cnt += gooddistance(lis[i],lis[j])

print(cnt)

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

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):
    for j in range(n):
        if i == j: continue
        counter = 0
        for k in range(d):
            diff = abs(x[i][k] - x[j][k])
            counter += diff ** 2
        ok = False
        for k in range(10000):
            if k * k == counter: ok = True
        if ok: ans += 1
print(ans // 2)

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

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

def dstnc(X, Y):
    res = 0
    for l, x in enumerate(X):
        res += (x - Y[l])**2
    return res


ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        su = dstnc(A[i], A[j])**0.5
        if str(su)[-1] == "0" and str(su)[-2] == ".":
            ans += 1
print(ans)

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

Solution (Python):
import math
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
ans = 0
cal = 0
for i in range(n):
  for j in range(i+1, n):
    for k in range(d):
      de = abs(x[i][k] - x[j][k])
      cal += de**2
    if math.sqrt(cal)%1==0:
      ans += 1
    cal = 0
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-1):
    for j in range(i+1, N):
        total = 0
        for k in range(D):
            total += (X[i][k]-X[j][k])**2
        total = math.sqrt(total)
        if total%1 == 0:
            ans += 1
print(ans)

Solution (Python):
N,D=map(int,input().split())
X=[[0]*D for i in range(N)]
for i in range(N):
  X[i]=list(map(int,input().split()))
ans=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
    flag=False
    for k in range(Norm+1):
      if k*k==Norm:
        flag=True
    if flag==True:
      ans+=1
print(ans)

Solution (Python):
import numpy as np
N, D = map(int,input().split())
LX = [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):
        LXP = np.array(LX[i])
        LXQ = np.array(LX[j])
        ans = (float(np.sqrt(sum((LXP - LXQ) ** 2))))
        if ans.is_integer():
            cnt += 1

print(cnt)

Solution (Python):
import numpy as np
from itertools import combinations
N,D=map(int,input().split())
X=[list(map(int,input().split())) for i in range(N)]
count=0
for x,y in combinations(X,2):
    r = np.sqrt(sum(abs(np.array(x)-np.array(y))**2))
    if r.is_integer() == True:
        count += 1
print(count)

Solution (Python):
import numpy as np
from itertools import combinations
 
n, d = map(int, input().split())
x = np.empty((n, d), dtype=np.int64)
for i in range(n):
    x[i] = [int(i) for i in input().split()] 
res = 0
for i, j in combinations(range(n), 2):
    if (np.sum((x[i]-x[j])**2)**0.5).is_integer():
        res += 1
print(res)

Solution (Python):
import numpy as np
from itertools import combinations

n, d = map(int, input().split())
x = np.empty((n, d), dtype=np.int64)
for i in range(n):
    x[i] = [int(i) for i in input().split()]

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

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):
  for j in range(i + 1, n):
    tmp = 0.0
    for k in range(d):
      tmp += (X[j][k] - X[i][k]) ** 2
    tmp = math.sqrt(tmp)
    if tmp.is_integer():
      count += 1
print(count)

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

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

Solution (Python):
import itertools
N, D = map(int, input().split())
count = 0
 
X = []
for i in range(N):
    X.append(list(map(int, input().split())))

for i in list(itertools.combinations(X, 2)):
    f = 0
    for j in range(D):
        f += (i[0][j]-i[1][j])**2
    f **= 0.5
    if f.is_integer():
        count += 1
print(count)

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

Solution (Python):
def solve():
    n, d = map(int, input().split())
    x = [list(map(int, input().split())) for _ in range(n)]
    count = 0
    for i in range(n):
        for j in range(n):
            dis2 = 0
            if i != j:
                for k in range(d):
                    dis2 += (x[i][k] - x[j][k]) ** 2
                if (dis2 ** 0.5).is_integer():
                    count += 1
    print(count//2)


if __name__ == '__main__':
    solve()

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

def f(A,B):
  D = 0
  for i in range(d):
    D += (A[i]-B[i])**2
  if math.sqrt(D) == math.floor(math.sqrt(D)):
    return(1)
  else:
    return(0)
ans = 0  
for i in range(n-1):
  for j in range(i+1,n):
    ans += f(X[i],X[j])
 
print(ans)

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