program sample
    implicit none
  
    integer(8) :: i,j,m,n,s,t,u
    integer(8),allocatable :: a(:),y(:)
  
    read(*,*) n
    allocate(a(n))
    read(*,*)a
    s=sum(a)
    t=0
    u=s

    do i=1,n
        t=u
        !t=t+a(i)
        u=u-2*a(i)


        if (u<0)then
            if (abs(u)>t)then
                write(*,*)t
            else
                write(*,*)abs(u)
            end if
            exit
        end if
    end do

  
    stop
end program sample
  

