      program ans2
      implicit none
      integer(16),allocatable,dimension(:) :: A
      integer(16) :: N
      integer(16) :: i
      integer(16) :: total
      integer(16) :: to1,to2
      integer :: one
      integer(16) :: ans
 
      total = 0
      to1 = 0
      to2 = 0
      one = 0

      read(*,*) N
      allocate(A(N))
      read(*,*) (A(i),i=1,N)
      
      do i=1,N
        total = total + A(i)
      end do

      do i=1,N
        to1 = to1 + A(i)
        if(to1 > total/2) exit
        to2 = to1
      end do
      if(mod(total,2) == 1) one = 1
      
      if((to1-total/2) > (total/2-to2)) then
        ans = total/2 - to2 + one
      else
        ans = to1 - total/2 - one
      end if
      
      write(*,*) ans
      end program ans2