n = int(eval(input()))

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



p_min = min(ps)

p_max = max(ps)



a = 999999999999999999999



for i in range(p_min, p_max+1):

    b = sum([abs(p-i)**2 for p in ps])

    a = min(a, b)



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

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

 

p_avg = round(sum(ps)/len(ps))

 

print((sum([abs(p-p_avg)**2 for p in ps])))
n = int(eval(input()))
ps = list(map(int, input().split()))
p_min = min(ps)
p_max = max(ps)
a = 999999999999999999999
for i in range(p_min, p_max + 1):
    b = sum([abs(p - i) ** 2 for p in ps])
    a = min(a, b)
print(a)

n = int(eval(input()))
ps = list(map(int, input().split()))
p_avg = round(sum(ps) / len(ps))
print((sum([abs(p - p_avg) ** 2 for p in ps])))

-p_min = min(ps) -p_max = max(ps) -a = 999999999999999999999 -for i in range(p_min, p_max + 1): -    b = sum([abs(p - i) ** 2 for p in ps]) -    a = min(a, b) -print(a) +p_avg = round(sum(ps) / len(ps)) +print((sum([abs(p - p_avg) ** 2 for p in ps])))