#include <iostream>
using namespace std;
int a[100], dp[100];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
dp[0] = a[0];
for (int i = 1; i < n; i++) {
dp[i] = max(a[i], a[i] + dp[i-1]);
}
int ans = 0;
for (int i = 1; i < n; i++) {
if (dp[ans] < dp[i]) ans = i;
}
printf("%d\n", dp[ans]);
return 0;
}
/********************
6
-2 11 -4 13 -5 -2
输出 20
*********************/