program Iron_Bar_Cutting
  implicit none
  integer :: n, i
  integer(8) :: a(200000) = 0_8, l = 0_8, r, m
  read(*,*) n
  read(*,*) a(1:n)
  r = sum(a(1:n))
  m = r
  do i = 1, n
    l = l+a(i)
    r = r-a(i)
    m = min(m,abs(r-l))
  end do
  write(*,'(i0)') m
end program Iron_Bar_Cutting