N = int(eval(input()))

X = sorted(list(map(int,input().split())))

ans = float("inf")

for e in range(min(X),max(X)+1):

    temp = 0

    for f in X:

        temp += (f-e)**2

    ans = min(ans,temp)

print(ans)

N = int(eval(input()))

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

ans = 10**9

for k in range(min(X),max(X)+1):

    temp = 0

    for e in X:

        temp += (k-e)**2

    ans = min(temp,ans)

print(ans)

N = int(eval(input()))
X = sorted(list(map(int, input().split())))
ans = float("inf")
for e in range(min(X), max(X) + 1):
    temp = 0
    for f in X:
        temp += (f - e) ** 2
    ans = min(ans, temp)
print(ans)

N = int(eval(input()))
X = list(map(int, input().split()))
ans = 10**9
for k in range(min(X), max(X) + 1):
    temp = 0
    for e in X:
        temp += (k - e) ** 2
    ans = min(temp, ans)
print(ans)

-X = sorted(list(map(int, input().split()))) -ans = float("inf") -for e in range(min(X), max(X) + 1): +X = list(map(int, input().split())) +ans = 10**9 +for k in range(min(X), max(X) + 1): -    for f in X: -        temp += (f - e) ** 2 -    ans = min(ans, temp) +    for e in X: +        temp += (k - e) ** 2 +    ans = min(temp, ans)