#include<iostream>
#include<cstdio>
#include<algorithm>
typedef long long LL;
using std::max;
const int N=1e5+3;
const LL INF = 0x3fffffffffffffff;
LL a[N], f[N][10];
void Test()
{
freopen("temp\\in.txt", "r", stdin);
}
int main()
{
// Test();
int n;
scanf("%d", &n);
for(int i=1; i<=n; i++)
scanf("%lld", &a[i]);
f[1][1] = a[1];
f[1][5] = -a[1];
f[2][1] = -INF;
f[2][2] = f[1][1] - a[2];
f[2][3] = f[1][1];
f[2][3+1] = f[1][5] + a[2];
f[2][3+2] = -INF;
f[2][3+3] = f[1][5];
f[2][6+1] = f[1][9] + a[2];
f[2][6+2] = f[1][9] - a[2];
f[2][6+3] = -INF;
for(int i=3; i<n; i++)
{
for(int j=0; j<=6; j+=3)
{
// choose
f[i][j+1] = max(f[i-1][j+2], f[i-1][j+3]);
f[i][j+1] += a[i];
// unchoose
f[i][j+2] = max(f[i-1][j+1], f[i-1][j+3]);
f[i][j+2] -= a[i];
// ignore
f[i][j+3] = max(f[i-1][j+1], f[i-1][j+2]);
}
}
f[n][1] = -INF;
f[n][2] = f[n-1][3] - a[n];
f[n][3] = f[n-1][2];
f[n][3+1] = f[n-1][3+3] + a[n];
f[n][3+2] = -INF;
f[n][3+3] = f[n-1][3+1];
f[n][6+1] = f[n-1][6+2] + a[n];
f[n][6+2] = f[n-1][6+1] - a[n];
f[n][6+3] = -INF;
LL ans = -INF;
for(int i=1; i<=9; i++)
ans = max(ans, f[n][i]);
// for(int i=1; i<=n; i++)
// {
// for(int j=1; j<=9; j++)
// printf("%d ", f[i][j]);
// putchar('\n');
// }
printf("%lld", max(ans, 0));
return 0;
}