#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef pair<int, int> PII;
typedef double db;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
VI a(n);
FOR (i, 0, n)
cin >> a[i];
vector<VL> mx(4, VL(n));
FOR (rev, 0, 2)
{
FOR (minus, 0, 2)
{
LL s = 0;
FOR (i, 0, n)
{
s = max(0ll, s);
s += a[i];
mx[rev * 2 + minus][i] = s;
a[i] *= -1;
}
}
reverse(ALL(a));
}
reverse(ALL(mx[2]));
reverse(ALL(mx[3]));
FOR (i, 0, n)
{
mx[1][i] *= -1;
mx[3][i] *= -1;
}
LL ans = 0;
FOR (i, 0, n - 1)
{
FOR (j, 0, 4)
{
FOR (k, j + 1, 4)
{
ans = max(ans, abs(mx[j][i] - mx[k][i + 1]));
}
}
}
cout << ans << '\n';
return 0;
}
fuck