#include using namespace std; #define N 100005 typedef long long ll; typedef unsigned long long ull; ll n, a[N], s[2], ans = LONG_LONG_MIN, s1, s2; int main() { #ifndef ONLINE_JUDGE freopen("admin.in", "r", stdin); // freopen("admin.out", "w", stdout); #endif scanf("%lld", &n); for (int i = 1; i <= n; i++) scanf("%lld", a + i); sort(a + 1, a + 1 + n); if (n == 1) return printf("%lld", abs(a[1])), 0; int l, r, now; s1 = s2 = LONG_LONG_MAX; if (a[1] < 0) { if (a[2] < 0) { s[0] = s[1] = 0; now = 0; for (int i = 1; i <= n; i++, now ^= 1) s[now] += a[i]; s1 = abs(s[0]) - abs(s[1]); } if (a[n] >= 0) { s[0] = s[1] = 0; l = 1, r = n, now = 0; while (l <= r) { if (!(now & 1)) s[0] += a[l++]; else s[1] += a[r--]; now ^= 1; } s2 = abs(s[0]) - abs(s[1]); } } if (s1 == s2 && s1 == LONG_LONG_MAX) s1 = s2 = 0; ans = max(ans, min(s1, s2)); s1 = s2 = LONG_LONG_MAX; if (a[n] >= 0) { if (a[1] < 0) { s[0] = s[1] = 0; l = 1, r = n, now = 0; while (l <= r) { if (!(now & 1)) s[0] += a[r--]; else s[1] += a[l++]; now ^= 1; } s1 = abs(s[0]) - abs(s[1]); } if (a[n - 1] >= 0) { s[0] = s[1] = 0; now = 0; for (int i = n; i >= 1; i--, now ^= 1) s[now] += a[i]; s2 = abs(s[0]) - abs(s[1]); } } if (s1 == s2 && s1 == LONG_LONG_MAX) s1 = s2 = 0; ans = max(ans, min(s1, s2)); printf("%lld", ans); return 0; }