
object Main extends App {

  import scala.io.StdIn._
  val n = readLine.trim.toInt
  val peaces = Array.tabulate(n){_ ⇒ readLine.trim.toLong}
  println(
    calMax(peaces)
  )
  def calMax(peaces: Array[Long]): Long = {
    val n = peaces.length
    def searchIOITurn(from: Int, to: Int)(implicit memo: Array[Array[Option[Long]]]): Long = {
      memo(from)(to) match {
        case Some(r) ⇒ r
        case None if from == to ⇒ 0.also{it ⇒ memo(from)(to) = Some(it)}
        case None ⇒
          (if (peaces(from) < peaces(to)) searchJOITurn(from, (to + n - 1) % n)
          else searchJOITurn((from + 1) % n, to)).also{it ⇒ memo(from)(to) = Some(it)}
      }
    }
    def searchJOITurn(from: Int, to: Int)(implicit memo: Array[Array[Option[Long]]]): Long = {
      memo(from)(to) match {
        case Some(r) ⇒ r
        case None if from == to ⇒  peaces(from).also{it ⇒ memo(from)(to) = Some(it)}
        case None ⇒ List(searchIOITurn((from + 1) % n, to) + peaces(from), searchIOITurn(from, (to + n - 1) % n) + peaces(to)).max.also{it ⇒ memo(from)(to) = Some(it)}
      }
    }
    implicit val memo = Array.tabulate(n){_ ⇒ Array.tabulate(n){_ ⇒ None: Option[Long]}}
    (0 until n).map{it ⇒ searchIOITurn((it + 1) % n, (it + n - 1) % n) + peaces(it)}.max
  }

  implicit class ScopeFunc[T](val value: T) {
    def let[A](func: T ⇒ A): A = func(value)
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}

/*
 */
