include <bits/stdc++.h>

using namespace std;

int main()
{
int N;
cin>>N;
vector<int> arr(N);
for(int i=0;i<N;i++)
cin>>arr[i];
int tmp = arr[0];
int m = arr[0];
for(int i=1;i<N;i++)
{
tmp = max(arr[i],tmp+arr[i]);
m = max(m,tmp);
}
cout<<m<<endl;
return 0;
}</int>