N=int(eval(input()))

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



ave=round(sum(a)/len(a))



cost=0

for i in a:

    cost+=(i-ave)**2

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

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



ave=round(sum(a)/len(a))



cost=0

for i in a:

    cost+=(ave-i)**2

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

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

-N = int(eval(input())) +n = int(eval(input())) -    cost += (i - ave) ** 2 +    cost += (ave - i) ** 2