a = int(eval(input()))

ar = list(map(int,input().split(" ")))

br = []

for i in range(min(ar),max(ar)+1):

    count = 0

    for r in ar:

        count += (i - r) ** 2

    br.append(count)

print((min(br)))
a = int(eval(input()))

ar = list(map(int,input().split(" ")))

b = 10 ** 9

for i in range(min(ar),max(ar) + 1):

    count = 0

    for r in ar:

        count += (r - i) ** 2

    if b > count:

        b = count

print(b)
a = int(eval(input()))
ar = list(map(int, input().split(" ")))
br = []
for i in range(min(ar), max(ar) + 1):
    count = 0
    for r in ar:
        count += (i - r) ** 2
    br.append(count)
print((min(br)))

a = int(eval(input()))
ar = list(map(int, input().split(" ")))
b = 10**9
for i in range(min(ar), max(ar) + 1):
    count = 0
    for r in ar:
        count += (r - i) ** 2
    if b > count:
        b = count
print(b)

-br = [] +b = 10**9 -        count += (i - r) ** 2 -    br.append(count) -print((min(br))) +        count += (r - i) ** 2 +    if b > count: +        b = count +print(b)