#include using namespace std; using int64 = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; if (!(cin >> N)) return 0; const long long INF = (1LL<<62); long long Pmin = INF, Pmax = -INF; // 非負の最小・最大 long long S = 0; // 負の絶対値合計 long long a1 = 0, a2 = 0; // 負の絶対値の最大・次点 int p = 0, m = 0; // 非負/負 の個数 for (int i = 0; i < N; ++i) { long long x; cin >> x; if (x >= 0) { ++p; Pmin = min(Pmin, x); Pmax = max(Pmax, x); } else { ++m; long long a = -x; S += a; if (a >= a1) { a2 = a1; a1 = a; } else if (a > a2) { a2 = a; } } } long long S_edges = 0; if (m == 0) { // 非負のみ S_edges = (p >= 2 ? Pmax - Pmin : 0); } else if (p == 0) { // 負のみ(全枝が根から伸びる) S_edges = S; } else { // 負も非負もある:根から負枝合計 S と正枝の端 Pmax までを含む S_edges = S + Pmax; } long long D = 0; // 直径 if (m >= 2) D = max(D, a1 + a2); // 負最大2本の先端間 if (p >= 1) D = max(D, a1 + Pmax); // 負最大と正の最大 if (p >= 2) D = max(D, Pmax - Pmin); // 正の区間の端同士(※ここは差です) long long ans = 2 * S_edges - D; cout << ans << '\n'; return 0; }