def c_be_together(N, A):

    a_sum = sum(A)

    option = (a_sum // N, (a_sum + N - 1) // N)

    ans = float('inf')

    for opt in option:

        ans = min(ans, sum([(a - opt)**2 for a in A]))

    return ans



N = int(eval(input()))

A = [int(i) for i in input().split()]

print((c_be_together(N, A)))
def c_be_together(N, A):

    a_sum = sum(A)

    option = (a_sum // N, (a_sum + N - 1) // N)  # 平均値の小数切り捨て|切り上げ

    ans = min(sum([(a - opt)**2 for a in A]) for opt in option)  # コストを計算

    return ans



N = int(eval(input()))

A = [int(i) for i in input().split()]

print((c_be_together(N, A)))
def c_be_together(N, A):
    a_sum = sum(A)
    option = (a_sum // N, (a_sum + N - 1) // N)
    ans = float("inf")
    for opt in option:
        ans = min(ans, sum([(a - opt) ** 2 for a in A]))
    return ans


N = int(eval(input()))
A = [int(i) for i in input().split()]
print((c_be_together(N, A)))

def c_be_together(N, A):
    a_sum = sum(A)
    option = (a_sum // N, (a_sum + N - 1) // N)  # 平均値の小数切り捨て|切り上げ
    ans = min(sum([(a - opt) ** 2 for a in A]) for opt in option)  # コストを計算
    return ans


N = int(eval(input()))
A = [int(i) for i in input().split()]
print((c_be_together(N, A)))

-    option = (a_sum // N, (a_sum + N - 1) // N) -    ans = float("inf") -    for opt in option: -        ans = min(ans, sum([(a - opt) ** 2 for a in A])) +    option = (a_sum // N, (a_sum + N - 1) // N)  # 平均値の小数切り捨て|切り上げ +    ans = min(sum([(a - opt) ** 2 for a in A]) for opt in option)  # コストを計算