import Foundation
let n = Int(readLine()!)!
var stairs: [Int] = []
(0..<n).forEach { _ in
let stair = Int(readLine()!)!
stairs.append(stair)
}
func solution() {
if isOnenTwo() { return }
var dp: [Int] = Array(repeating: 0, count: n)
dp[0] = stairs[0]
dp[1] = stairs[0] + stairs[1]
dp[2] = max(stairs[0] + stairs[2], stairs[1] + stairs[2])
for i in (3..<n) {
dp[i] = max(dp[i-3] + stairs[i-1] + stairs[i], dp[i-2] + stairs[i])
}
print(dp.last!)
}
func isOnenTwo() -> Bool {
if n == 1 {
print( stairs[0] )
return true
}
if n == 2 {
print( stairs[0] + stairs[1] )
return true
}
return false
}
solution()
참고 : https://www.acmicpc.net/problem/2579