program candy
  implicit none

  integer :: n, i, k
  integer, allocatable :: a(:,:), tot(:)

  read(*,*) n

  allocate(a(n,2))
  read(*,*) a

  allocate(tot(n))

  do i = 1, n
     tot(i) = 0
  end do

  do i = 1, n
     do k = 1, i
        tot(i) = tot(i) + a(k,1)
     end do

     do k = i, n
        tot(i) = tot(i) + a(k,2)
     end do

  end do

  write(*,*) maxval(tot)

end program candy

     

  

  
