#include<bits/stdc++.h>
using namespace std;
int sum, n, a[1000009], a1[1000009];
int duyet , duyet1, maxn , maxn1 , ans;
void inp(){
cin >> n;
for (int i = 1; i <= n; i++){
cin >> a[i];
a1[i] = (-1) * a[i];
sum += a[i];
}
}
int kadane(){
for (int i = 1; i <= n; i++){
duyet += a[i];
if (duyet < 0){
duyet = 0;
}
maxn = max (maxn, duyet);
}
int tong1 = maxn;
for (int i = 1; i <= n; i++){
duyet1 += a1[i];
if (duyet1 < 0){
duyet1 = 0;
}
maxn1 = max (maxn1, duyet1);
}
int tong2 = sum - ((-1)*maxn1);
if (maxn1 + sum == 0){
return tong1;
}
ans = max (tong1, tong2);
return ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
freopen("CAU3.INP", "r", stdin);
freopen("CAU3.OUT", "w", stdout);
inp();
cout << kadane();
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKaW50IHN1bSwgbiwgYVsxMDAwMDA5XSwgYTFbMTAwMDAwOV07CmludCBkdXlldCAsIGR1eWV0MSwgbWF4biAsIG1heG4xICwgYW5zOwp2b2lkIGlucCgpewogICAgY2luID4+IG47CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyBpKyspewogICAgICAgIGNpbiA+PiBhW2ldOwogICAgICAgIGExW2ldID0gKC0xKSAqIGFbaV07CiAgICAgICAgc3VtICs9IGFbaV07CiAgICB9Cn0KaW50IGthZGFuZSgpewogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKXsKICAgICAgICBkdXlldCArPSBhW2ldOwogICAgICAgIGlmIChkdXlldCA8IDApewogICAgICAgICAgICBkdXlldCA9IDA7CiAgICAgICAgfQogICAgICAgIG1heG4gPSBtYXggKG1heG4sIGR1eWV0KTsKICAgIH0KICAgIGludCB0b25nMSA9IG1heG47CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyBpKyspewogICAgICAgIGR1eWV0MSArPSBhMVtpXTsKICAgICAgICBpZiAoZHV5ZXQxIDwgMCl7CiAgICAgICAgICAgIGR1eWV0MSA9IDA7CiAgICAgICAgfQogICAgICAgIG1heG4xID0gbWF4IChtYXhuMSwgZHV5ZXQxKTsKICAgIH0KICAgIGludCB0b25nMiA9IHN1bSAtICgoLTEpKm1heG4xKTsKICAgIGlmIChtYXhuMSArIHN1bSA9PSAwKXsKICAgICAgICByZXR1cm4gdG9uZzE7CiAgICB9CiAgICBhbnMgPSBtYXggKHRvbmcxLCB0b25nMik7CiAgICByZXR1cm4gYW5zOwp9CmludCBtYWluKCl7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAgIGNpbi50aWUoMCk7IGNvdXQudGllKDApOwogICAgZnJlb3BlbigiQ0FVMy5JTlAiLCAiciIsIHN0ZGluKTsKICAgIGZyZW9wZW4oIkNBVTMuT1VUIiwgInciLCBzdGRvdXQpOwogICAgaW5wKCk7CiAgICBjb3V0IDw8IGthZGFuZSgpOwogICAgcmV0dXJuIDA7Cn0K