#include<iostream>
using namespace std;
int n, j, sum, max;
int main()
{
cin >> n >> max;
sum = max;
while (--n)
{
cin >> j;
sum = sum > 0 ? sum : 0;
sum += j;
max = max > sum ? max : sum;
}
cout << max;
}
#include<iostream>
using namespace std;
int n, j, sum, max;
int main()
{
cin >> n >> max;
sum = max;
while (--n)
{
cin >> j;
sum = sum > 0 ? sum : 0;
sum += j;
max = max > sum ? max : sum;
}
cout << max;
}