Problem:
Score : 600 points

Problem Statement

Given is an integer sequence A_1, ..., A_N of length N.

We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from this sequence so that no two adjacent elements are chosen.

Find the maximum possible sum of the chosen elements.

Here \lfloor x \rfloor denotes the greatest integer not greater than x.

Constraints

2 \leq N \leq 2\times 10^5

|A_i|\leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

Print the maximum possible sum of the chosen elements.

Sample Input 1

6
1 2 3 4 5 6

Sample Output 1

12

Choosing 2, 4, and 6 makes the sum 12, which is the maximum possible value.

Sample Input 2

5
-1000 -100 -10 0 10

Sample Output 2

0

Choosing -10 and 10 makes the sum 0, which is the maximum possible value.

Sample Input 3

10
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

Sample Output 3

5000000000

Watch out for overflow.

Sample Input 4

27
18 -28 18 28 -45 90 -45 23 -53 60 28 -74 -71 35 -26 -62 49 -77 57 24 -70 -93 69 -99 59 57 -49

Sample Output 4

295

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j, k) for (int i = j; i < k; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 60);

vi a;
map<pair<int, int>, int> memo;

int solve(int l, int r) {
    // auto it = memo.find(make_pair(l, r));
    auto it = memo.find({l, r});
    if (it != memo.end()) return it->second;

    int N = r - l;
    vi vl(N), vr(N);
    vl[0] = a[l];
    vl[1] = a[l + 1];
    vr[N - 1] = a[r - 1];
    vr[N - 2] = a[r - 2];
    for (int i = l + 2; i < N; i++) {
        vl[i] += vl[i - 2] + a[i];
    }
    for (int i = N - 3; i >= l; i--) {
        vr[i] += vr[i + 2] + a[i];
    }

    if (N % 2 == 0) {
        return memo[{l, r}] = max(vl[N - 2], vl[N - 1]);
    }

    int ans = max(max(vl[N - 3], vl[N - 2]), max(vr[3], vr[2]));
    rep(i, 2, N - 2) {
        if (i % 2 == 0) {
            int l = max(vl[i - 2], vl[i - 1]);
            int r = max(vr[i + 1], vr[i + 2]);
            chmax(ans, l + r);
            debug2(l, r);
        } else {
            chmax(ans, solve(l, i - 1) + vr[i + 1]);
            chmax(ans, vl[i - 1] + solve(l + 1, r));
        }
        // debug2(i, ans);
    }
    return memo[{l, r}] = ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int N;
    cin >> N;
    a = vi(N);
    rep(i, 0, N) cin >> a[i];

    cout << solve(0, N) << endl;
    return 0;
}