import scala.io.StdIn object Main { def main(args: Array[String]): Unit = { val n = StdIn.readInt val v = StdIn.readLine.split(' ').map(_.toInt) val dp = Array.fill(n)(0) for (i <- (0 until n)) { var sushi = v(i) if (i - 1 >= 0) sushi = Math.max(sushi, dp(i - 1)) if (i - 2 >= 0) sushi = Math.max(sushi, dp(i - 2) + v(i)) dp(i) = Math.max(dp(i), sushi) } println(dp(n - 1)) } }