n = int(eval(input()))

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



f = 10**100



for p in range(min(x), max(x) + 1):

    l = [(x[i] - p)**2 for i in range(n)]

    f1 = sum(l)

    f = min(f, f1)



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

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



x_mean = sum(x)/n

p1 = int(x_mean)

p2 = p1 + 1



if abs(x_mean - p1) > abs(x_mean - p2):

    p = p2

else:

    p = p1



ans = 0

for i in range(n):

    ans += (x[i]-p)**2

print(ans)
n = int(eval(input()))
x = list(map(int, input().split()))
f = 10**100
for p in range(min(x), max(x) + 1):
    l = [(x[i] - p) ** 2 for i in range(n)]
    f1 = sum(l)
    f = min(f, f1)
print(f)

n = int(eval(input()))
x = list(map(int, input().split()))
x_mean = sum(x) / n
p1 = int(x_mean)
p2 = p1 + 1
if abs(x_mean - p1) > abs(x_mean - p2):
    p = p2
else:
    p = p1
ans = 0
for i in range(n):
    ans += (x[i] - p) ** 2
print(ans)

-f = 10**100 -for p in range(min(x), max(x) + 1): -    l = [(x[i] - p) ** 2 for i in range(n)] -    f1 = sum(l) -    f = min(f, f1) -print(f) +x_mean = sum(x) / n +p1 = int(x_mean) +p2 = p1 + 1 +if abs(x_mean - p1) > abs(x_mean - p2): +    p = p2 +else: +    p = p1 +ans = 0 +for i in range(n): +    ans += (x[i] - p) ** 2 +print(ans)