from collections import defaultdict





def main():

    n = int(eval(input()))

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

    ans = 10 ** 20

    for x in range(-100, 101):

        ans = min(ans, sum([(x - a) ** 2 for a in l]))



    print(ans)



if __name__ == '__main__':

    main()

from collections import defaultdict





def main():

    N = int(eval(input()))

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



    ans = 10 ** 10

    for m in range(min(a_list), max(a_list) + 1):

        cost = sum((m - a) ** 2 for a in a_list)

        ans = min(ans, cost)

    print(ans)





if __name__ == '__main__':

    main()

from collections import defaultdict


def main():
    n = int(eval(input()))
    l = list(map(int, input().split()))
    ans = 10**20
    for x in range(-100, 101):
        ans = min(ans, sum([(x - a) ** 2 for a in l]))
    print(ans)


if __name__ == "__main__":
    main()

from collections import defaultdict


def main():
    N = int(eval(input()))
    a_list = list(map(int, input().split()))
    ans = 10**10
    for m in range(min(a_list), max(a_list) + 1):
        cost = sum((m - a) ** 2 for a in a_list)
        ans = min(ans, cost)
    print(ans)


if __name__ == "__main__":
    main()

-    n = int(eval(input())) -    l = list(map(int, input().split())) -    ans = 10**20 -    for x in range(-100, 101): -        ans = min(ans, sum([(x - a) ** 2 for a in l])) +    N = int(eval(input())) +    a_list = list(map(int, input().split())) +    ans = 10**10 +    for m in range(min(a_list), max(a_list) + 1): +        cost = sum((m - a) ** 2 for a in a_list) +        ans = min(ans, cost)