#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, s = 0, mn = 0, mx = 0;
cin >> n;
while(--n)
{
int a;
cin >> a;
s += a;
mn = min(mn, s);
mx = max(mx, s);
}
cout << mx - mn + min(mx, -mn) << "\n";
return 0;
}