import scala.io.StdIn object Main extends App { def proc(n: Int, v: Array[Int]): Int = { val dp: Array[Array[Int]] = Array.fill(n + 3, 2)(0) (0 until n) foreach { i => dp(i + 1)(1) = (dp(i)(0) + v(i)) max dp(i)(1) dp(i + 2)(0) = dp(i)(0) + v(i) max dp(i + 2)(0) dp(i + 3)(0) = dp(i)(0) + v(i) } dp(n).max } val n: Int = StdIn.readInt() val v: Array[Int] = StdIn.readLine().split(" ").map(_.toInt) val result: Int = proc(n, v) println(result) }