#include <iostream>
using namespace std;
int subsequence( int A[], int N);
int main()
{
int a[100], n;
cin>>n;
for(int i = 0; i < n; i++)
cin>>a[i];
cout<<subsequence(a, n)<<"\n";
}
int subsequence(int A[], int N)
{
//子序列和如果是正数,则对于下一个数是加,继续下一个循环
//子序列和如果是负数,则对于下一个数必然是减,则这个序列都可以扔掉了
int maxSum = 0;
int ThisSum = 0;
for( int i = 0; i < N ; i++)
{
ThisSum += A[i];
if(ThisSum > maxSum)
maxSum = ThisSum;
else if(ThisSum < 0)
ThisSum = 0;
}
return maxSum;
}