program Issho
    implicit none
    integer(4):: n, am
    integer(4), allocatable:: a(:)

    read*, n
    allocate(a(n))
    read*, a(:)

    print*, min(sum((sum(a)/n - a)**2), sum((sum(a)/n+1 - a)**2))

end program Issho