#include <iostream>
using namespace std;
const int N = 1e6+10;
int a[N], dp[N];
int main(){
int n;
cin >> n;
for (int i = 1; i <= n; i ++ ) cin >> a[i];
dp[1] = a[1];
dp[0] = -2e9;
for (int i = 2; i <= n; i ++ ){
dp[i] = max(dp[i-1]+a[i], a[i]);
}
int ans = -2e9;
for (int i = 1; i <= n; i ++ ){
ans = max(ans, dp[i]);
}
cout << ans << endl;
return 0;
}