def abss(x, y):

    return abs(x-y)**2



def main():

    N = int(eval(input()))

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

    ans = 10000000

    min_l = min(l)

    max_l = max(l)

    for y in range(min_l, max_l+1):

        temp = 0

        for x in l:

            temp += abss(x, y)

        ans = min(ans, temp)

    print(ans)



if __name__ == '__main__':

    main()
def main():

    N = int(eval(input()))

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

    ans = 10000000

    min_l = min(l)

    max_l = max(l)

    for y in range(min_l, max_l+1):

        temp = 0

        for x in l:

            temp += (x - y) ** 2

        ans = min(ans, temp)

    print(ans)



if __name__ == '__main__':

    main()
def abss(x, y):
    return abs(x - y) ** 2


def main():
    N = int(eval(input()))
    l = list(map(int, input().split()))
    ans = 10000000
    min_l = min(l)
    max_l = max(l)
    for y in range(min_l, max_l + 1):
        temp = 0
        for x in l:
            temp += abss(x, y)
        ans = min(ans, temp)
    print(ans)


if __name__ == "__main__":
    main()

def main():
    N = int(eval(input()))
    l = list(map(int, input().split()))
    ans = 10000000
    min_l = min(l)
    max_l = max(l)
    for y in range(min_l, max_l + 1):
        temp = 0
        for x in l:
            temp += (x - y) ** 2
        ans = min(ans, temp)
    print(ans)


if __name__ == "__main__":
    main()

-def abss(x, y): -    return abs(x - y) ** 2 - - -            temp += abss(x, y) +            temp += (x - y) ** 2