program prob6
    implicit none
    integer :: N
    integer, allocatable :: a(:)
    integer :: i, j
    integer :: ans, tmp
    read(*,*) N
    allocate(a(N))
    
    read(*,*) a
    
    ans = 4000005
    do i = -100, 100
        tmp = 0
        do j = 1, N
            tmp = tmp + (a(j) - i) * (a(j) - i)
        end do
        ans = min(tmp, ans)
    end do
    write(*,*) ans
    
    deallocate(a)
 
    stop
contains
end program prob6