#include namespace { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic pop using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; VI a(n); rep(i, n) cin >> a[i]; constexpr ll INF = 1002003004005006007; if (n % 2) { int m = n / 2; ll ans = INF; ll now = accumulate(a.begin(), a.begin() + m, 0LL); rep(i, m + 1) { now += a[i + m]; chmin(ans, now); now -= a[i]; } cout << ans << '\n'; return 0; } int m = n / 2; VL accmf(n + 1, INF), accmb(n + 1, INF), accm1f(n + 1, INF), accm1b(n + 1); { ll now = accumulate(a.begin(), a.begin() + m - 1, 0LL); ll acc = INF; for(int i = 0; i + m - 1 < n; i++) { now += a[i + m - 1]; chmin(acc, now); accmf[i] = acc; now -= a[i]; } } { ll now = accumulate(a.end() - (m - 1), a.end(), 0LL); ll acc = INF; for(int i = n - m; i >= 0; i--) { now += a[i]; chmin(acc, now); accmb[i] = acc; now -= a[i + m - 1]; } } m++; { ll now = accumulate(a.begin(), a.begin() + m - 1, 0LL); ll acc = INF; for(int i = 0; i + m - 1 < n; i++) { now += a[i + m - 1]; chmin(acc, now); accm1f[i] = acc; now -= a[i]; } } { ll now = accumulate(a.end() - (m - 1), a.end(), 0LL); ll acc = INF; for(int i = n - m; i >= 0; i--) { now += a[i]; chmin(acc, now); accm1b[i] = acc; now -= a[i + m - 1]; } } m--; ll ans = 0; for(int i = 0; i < n - 1; i++) { if (i < m - 1) { chmax(ans, min(accm1f[i], accmb[i + 2])); } else if (i == m - 1) { chmax(ans, accm1f[i]); } else { chmax(ans, min(accmf[i - m], accm1b[i - m + 1])); } } cout << ans << '\n'; }