program main
 implicit none
 integer*8 n,s1,s2,ans,tmp,i
 integer*8, allocatable :: w(:)
 read(*,*) n
 allocate(w(1:n))
 read(*,*)w
 s1=0
 s2=0
 do i=1,n
  s1 = s1 + w(i)
 end do
 ans = s1
 tmp = ans
 do i=1,n
  s2 = s2 + w(i)
  s1 = s1 - w(i)
  tmp = s1 - s2
  if (tmp < 0) then
   if(abs(tmp) < ans) then
    ans = abs(tmp)
   end if
   exit
  end if
  ans = tmp
 end do
 write(*,*) ans
end program main