#include #include #include #include #include #include #include #include #include using namespace std; template istream& operator>>(istream& is, pair& a){ return is >> a.first >> a.second; } template ostream& operator<<(ostream& os, pair& a){ return os << a.first << " " << a.second; } template istream& operator>>(istream& is, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) is >> vc[i]; return is; } template ostream& operator<<(ostream& os, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) os << vc[i] << endl; return os; } #define ForEach(it,c) for(__typeof (c).begin() it = (c).begin(); it != (c).end(); it++) #define ALL(v) (v).begin(), (v).end() #define UNQ(s) { sort(ALL(s)); (s).erase( unique( ALL(s)), (s).end());} typedef pair< double , double > Pi; typedef pair< double , Pi > Pii; int main(){ int N; cin >> N; vector< int > V(N); cin >> V; vector< int > dp(N); for(int i = 0; i < N; i++){ dp[i] = V[i]; } for(int i = 0; i < N; i++){ for(int j = N - 1; j > i + 1; j--){ dp[j] = max( dp[j], dp[i] + V[j]); } } cout << *max_element(ALL(dp)) << endl; }