N = int(eval(input()))

a = sorted(map(int, input().split()))

cost = 10**9



for y in range(a[0], a[-1]+1):

    cost = min(cost, sum([(x-y)**2 for x in a]))

print(cost)
N = int(eval(input()))

A = [int(i) for i in input().split()]

che1 = sum(A)//N

che2 = sum(A)//N + 1

ans1 = 0

ans2 = 0



for i in A:

    ans1 += (i-che1)**2

    ans2 += (i-che2)**2

    

print((min(ans1, ans2)))
N = int(eval(input()))
a = sorted(map(int, input().split()))
cost = 10**9
for y in range(a[0], a[-1] + 1):
    cost = min(cost, sum([(x - y) ** 2 for x in a]))
print(cost)

N = int(eval(input()))
A = [int(i) for i in input().split()]
che1 = sum(A) // N
che2 = sum(A) // N + 1
ans1 = 0
ans2 = 0
for i in A:
    ans1 += (i - che1) ** 2
    ans2 += (i - che2) ** 2
print((min(ans1, ans2)))

-a = sorted(map(int, input().split())) -cost = 10**9 -for y in range(a[0], a[-1] + 1): -    cost = min(cost, sum([(x - y) ** 2 for x in a])) -print(cost) +A = [int(i) for i in input().split()] +che1 = sum(A) // N +che2 = sum(A) // N + 1 +ans1 = 0 +ans2 = 0 +for i in A: +    ans1 += (i - che1) ** 2 +    ans2 += (i - che2) ** 2 +print((min(ans1, ans2)))