import Foundation
let N = Int(readLine()!)!
let cards = readLine()!.components(separatedBy: " ").map { Int($0)! }
var dp = [Int](repeating: 0, count: N+1)
for i in 1..<N+1 {
for j in 1..<i+1 {
dp[i] = max(dp[i], dp[i-j]+cards[j-1])
}
}
print(dp[N])