import numpy as np



N = int(eval(input()))

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

cost = float("inf")

for i in range(max(X) - min(X) + 1):

    p = min(X) + i

    cost = min(np.sum((X - p) ** 2), cost)

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

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

if N == 1:

    print((0))

else:

    r = X[-1] - X[0]

    ans = float("inf")

    for i in range(r + 1):

        R = X[0] + i

        hp = 0

        for j in range(N):

            hp = hp + (R - X[j]) ** 2



        ans = min(hp, ans)



    print(ans)

import numpy as np

N = int(eval(input()))
X = np.array(list(map(int, input().split())))
cost = float("inf")
for i in range(max(X) - min(X) + 1):
    p = min(X) + i
    cost = min(np.sum((X - p) ** 2), cost)
print(cost)

N = int(eval(input()))
X = sorted(list(map(int, input().split())))
if N == 1:
    print((0))
else:
    r = X[-1] - X[0]
    ans = float("inf")
    for i in range(r + 1):
        R = X[0] + i
        hp = 0
        for j in range(N):
            hp = hp + (R - X[j]) ** 2
        ans = min(hp, ans)
    print(ans)

-import numpy as np - -X = np.array(list(map(int, input().split()))) -cost = float("inf") -for i in range(max(X) - min(X) + 1): -    p = min(X) + i -    cost = min(np.sum((X - p) ** 2), cost) -print(cost) +X = sorted(list(map(int, input().split()))) +if N == 1: +    print((0)) +else: +    r = X[-1] - X[0] +    ans = float("inf") +    for i in range(r + 1): +        R = X[0] + i +        hp = 0 +        for j in range(N): +            hp = hp + (R - X[j]) ** 2 +        ans = min(hp, ans) +    print(ans)