#include using namespace std; typedef long long ll; typedef vector VI; typedef vector VVI; typedef vector VL; typedef vector VVL; typedef pair PII; #define FOR(i, a, n) for (int i = (int)a; i < (int)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define MOD 1000000007 #define INF 1000000000 #define PI 3.14159265359 #define EPS 1e-12 int dp[1010]; int main(void) { int n, v[1010] = {0}; cin >> n; REP(i, n) cin >> v[i]; if(n == 1) {cout << v[0] << endl; return 0;} else if(n == 2) {cout << max(v[0], v[1]) << endl; return 0;} dp[0] = v[0]; dp[1] = v[1]; FOR(i, 2, n) { int m = -INF; REP(j, i-1) { m = max(m, dp[j]); } dp[i] = max(m + v[i], dp[i-1]); } cout << dp[n-1] << endl; return 0; }