#include <bits/stdc++.h>
using namespace std;
int maxSum(int arr[], int n){
int maxi=INT_MIN;
int sum=0;
for(int i=0;i<n;i++){
sum+=arr[i];
maxi=max(maxi,sum);
if(sum<0)sum=0;
}
return maxi;
}
int main() {
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
int sum =maxSum(arr,n);
cout<<sum<<" ";
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWF4U3VtKGludCBhcnJbXSwgaW50IG4pewoJaW50IG1heGk9SU5UX01JTjsKCWludCBzdW09MDsKCQoJZm9yKGludCBpPTA7aTxuO2krKyl7CgkJc3VtKz1hcnJbaV07CgkJCW1heGk9bWF4KG1heGksc3VtKTsKCQkJaWYoc3VtPDApc3VtPTA7CgkJfQoJcmV0dXJuIG1heGk7Cn0KCmludCBtYWluKCkgewoJaW50IG47CgljaW4+Pm47CglpbnQgYXJyW25dOwoJZm9yKGludCBpPTA7aTxuO2krKyl7CgkJY2luPj5hcnJbaV07Cgl9CiAgICBpbnQgc3VtID1tYXhTdW0oYXJyLG4pOwoJY291dDw8c3VtPDwiICI7CglyZXR1cm4gMDsKfQ==