import java.util.* fun main(args: Array) { val n = readLine()!!.toInt() val v = readLine()!!.split(" ").map { it.toInt() } val flag = arrayOfNulls(n) val task = Stack() task.add(0) while (task.isNotEmpty()) { val current = task.pop() if(current == v.lastIndex) { flag[current] = v[current] continue } if(current == v.lastIndex - 1) { flag[current] = Math.max(v[current], v[current+1]) continue } if(flag[current + 1] == null) { task.add(current) task.add(current + 1) continue } if(flag[current + 2] == null) { task.add(current) task.add(current + 2) continue } flag[current] = Math.max(flag[current+1]!!, flag[current+2]!! + v[current]) } println(flag[0]!!) }