#line 1 "main.cpp" #include #include #include using namespace std; using lint = long long; constexpr lint INF = 1LL << 60; void solve() { int n; cin >> n; vector xs(n); for (auto& x : xs) cin >> x; sort(xs.begin(), xs.end()); lint ans = -INF; for (int q = 0; q < 2; ++q) { lint mi = INF; { lint a = 0, b = 0; for (int i = 0; i < n; ++i) { (i % 2 == 0 ? a : b) += xs[i]; } mi = min(mi, abs(a) - abs(b)); } { lint a = 0, b = 0; int l = 0, r = n - 1; while (l <= r) { a += xs[l++]; if (l > r) break; b -= xs[r--]; } mi = min(mi, abs(a) - abs(b)); } ans = max(ans, mi); reverse(xs.begin(), xs.end()); } cout << ans << "\n"; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }