#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; constexpr int INF = 1001001001; // constexpr int mod = 1000000007; // constexpr int mod = 998244353; template inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector c(N); for(int i = 0; i < N; ++i) cin >> c[i]; sort(begin(c), end(c)); ll ans = 0, a = 0, b = 0; // a, -b for(int i = 0; i < N / 2; ++i) b += c[i]; for(int i = N / 2; i < N; ++i) a += c[i]; ans = abs(a) - abs(b); // a, b reverse(begin(c), end(c)); a = 0, b = 0; for(int i = 0; i < N; ++i){ if(i % 2 == 0) a += c[i]; else b += c[i]; } chmin(ans, abs(a) - abs(b)); // -a, b ll score = 0; a = 0, b = 0; for(int i = 0; i < N / 2; ++i) b += c[i]; for(int i = N / 2; i < N; ++i) a += c[i]; score = abs(a) - abs(b); // -a, -b reverse(begin(c), end(c)); a = 0, b = 0; for(int i = 0; i < N; ++i){ if(i % 2 == 0) a += c[i]; else b += c[i]; } chmin(score, abs(a) - abs(b)); chmax(ans, score); cout << ans << endl; return 0; }