program prob2
    implicit none
    integer::N, ans, i, j, ansi
    integer, allocatable::a(:)
    read(*,*) N
    allocate(a(N))
    read(*,*) a
    ans = dot_product(a,a)
    do i = -100, 100
        ansi = 0
        do j = 1, N
            ansi = ansi + (a(j) - i)**2
        end do
        if(ansi < ans) then
            ans = ansi
        end if
    end do
    write(*,*) ans

    deallocate(a)
    stop
end program prob2