#include #include #include #include #include #include #include #include using namespace std; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) typedef long long ll; int main() { int N; cin >> N; int v[N]; rep(i, N) { cin >> v[i]; } ll dp[N+1]; fill(dp, dp+N+1, 0); dp[0] = 0; dp[1] = v[0]; REP(i, 2, N+1) { rep(j, i-1) { dp[i] = max(dp[i], dp[j] + v[i-1]); } } cout << dp[N] << endl; return 0; }