program probC
  implicit none
  integer*8,allocatable :: ame(:,:)
  integer*8 N,j,tot,i

  read(*,*) N
  allocate(ame(0:n+1,2))
  ame=0

  read(*,*) ame(1:n,1)
  read(*,*) ame(1:n,2)


  tot=0
  do j=1,n
     tot=tot+ame(j,1)
     if(sum(ame(j+1:n,1))>=sum(ame(j:n-1,2))) then
     else
        tot=tot+sum(ame(j:n-1,2))
        exit
     end if
  end do
  tot=tot+ame(n,2)
  
  write(*,*) tot
  
end program probC