1 #include<bits/stdc++.h>
2 #define ll long long
3 using namespace std;
4 const int INF = 1e9;
5 const int N = 1e5 + 10;
6 int a[N];
7 int n;
8
9 int main(){
10 scanf("%d",&n);
11 for(int i = 1 ; i <= n ; i++){
12 scanf("%d",&a[i]);
13 }
14 ll ans = 0;
15 for(int now = 0 ; now < 31 ; now++){
16 ll cur = 0;
17 ll best = 0;
18 for(int i = 1 ; i <= n ; i++){
19 int val = (a[i] > now ? -INF : a[i]);
20 cur += val;
21 best = min(best, cur);
22 ans = max(ans, (cur - best) - now);
23 }
24 }
25 printf("%lld
",ans);
26
27 return 0;
28 }