#include #define rep(i, n) for (int i = 0; i < (int) n; i++) using ll = long long; using namespace std; const long long INF = 1ll << 60; void chmax(ll &x, ll y) { x = max(x, y); } int main() { ll n; cin >> n; deque c; rep(i, n) { ll ci; cin >> ci; c.push_back(ci); }; ll ans = -INF; // big big { deque ci = c; vector score(2, 0); rep(i, n) { score[i % 2] += ci.front(); ci.pop_front(); } chmax(ans, abs(score[0]) - abs(score[1])); } // big small { deque ci = c; vector score(2, 0); rep(i, n) { if (i % 2) { score[i % 2] += ci.front(); ci.pop_front(); } else { score[i % 2] += ci.back(); ci.pop_back(); } } chmax(ans, abs(score[0]) - abs(score[1])); } // small big { deque ci = c; vector score(2, 0); rep(i, n) { if (i % 2) { score[i % 2] += ci.back(); ci.back(); } else { score[i % 2] += ci.front(); ci.pop_front(); } } chmax(ans, abs(score[0]) - abs(score[1])); } // small small { deque ci = c; vector score(2, 0); rep(i, n) { score[i % 2] += ci.back(); ci.pop_back(); } chmax(ans, abs(score[0]) - abs(score[1])); } cout << ans << endl; }