#include using namespace std; #define rep(i,n) for(int (i) = 0 ; (i) < (int)(n) ; (i)++) #define REP(i,a,b) for(int (i) = a ; (int)(i) <= (int)(b) ; (i)++) #define all(n) (n).begin(),(n).end() typedef long long ll; typedef vector Vi; typedef vector VVi; typedef pair Pii; typedef vector VPii; int main(){ ll N; cin >> N; ll dp[1010]; for(int i = 0 ; i < N ; i++){ ll v; cin >> v; dp[i] = v; for(int j = 0 ; j < i-1 ; j++){ dp[i] = max(dp[j]+v,dp[i]); } } ll ans = 0; for(int i = 0 ; i < N ; i++) ans = max(ans,dp[i]); cout << ans << endl; }