      PROGRAM IronBarCutting
      implicit none
      integer(16) :: n,ans
      integer(16),allocatable :: a(:)
      integer(16) :: len,cutP,i,left,right,llen,rlen
      
      read*,n
      allocate( a(n) )
      read*,a(:)
      
      len = sum( a(:) )
      
      
      left = 1; right = n;
      llen = a(1); rlen = a(n);
      do i = 1,n-2
        if( llen>rlen )then
          right = right - 1
          rlen = rlen + a(right)
        else
          left = left + 1
          llen = llen + a(left)
        end if
      end do
      
      ans = abs( llen - rlen )
      
      
      print*,ans
      
      END PROGRAM