N = int(eval(input()))

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

ave = sum(a)/N

ave = round(ave)

sum = 0

for i in a:

    sum += (i-ave)**2

print(sum)

n=int(eval(input()))

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



ave = round(sum(a)/n)

cost=0

for i in range(n):

    cost+=(a[i]-ave)**2

print(cost)

N = int(eval(input()))
a = list(map(int, input().split()))
ave = sum(a) / N
ave = round(ave)
sum = 0
for i in a:
    sum += (i - ave) ** 2
print(sum)

n = int(eval(input()))
a = list(map(int, input().split()))
ave = round(sum(a) / n)
cost = 0
for i in range(n):
    cost += (a[i] - ave) ** 2
print(cost)

-N = int(eval(input())) +n = int(eval(input())) -ave = sum(a) / N -ave = round(ave) -sum = 0 -for i in a: -    sum += (i - ave) ** 2 -print(sum) +ave = round(sum(a) / n) +cost = 0 +for i in range(n): +    cost += (a[i] - ave) ** 2 +print(cost)