#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; int V[1005]; int dp[1005]; int main(){ int N; cin >> N; rep(i,N){ cin >> V[i]; dp[i] = V[i]; } rep(i,N){ rep(j,i-1){ dp[i] = max(dp[i], dp[j]+V[i]); } } int ret = 0; rep(i,N){ ret = max(ret, dp[i]); } cout << ret << endl; return 0; }