program main
  implicit none
  integer :: i, j, N
  integer,allocatable,dimension(:, :) :: v, dp
  logical,dimension(3, 3) :: f
  f = .true.
  do i = 1,3
    f(i, i) = .false.
  enddo

  read*, N
  allocate(dp(3, N), v(3, N))
  do i = 1, N
    read*, v(:, i)
  end do

  dp(:, 1) = v(:, 1)
  do i = 2, N
    do j = 1, 3
      dp(j, i) = maxval(pack(dp(:, i-1), f(:, j))) + v(j, i)
    enddo
  enddo
  print*, maxval(dp(:, N))
end