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;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}

const int MAX_N = 2e5 + 10;
ll pref[MAX_N];
ll suf[MAX_N];
ll arr[MAX_N];
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n;

vector<int> got;
ll bigbig = -mod;
void bigans(int curr, int sum) {
    if(curr > n) {
        if((sum > bigbig && got.size() == n / 2)) {
            bigbig = sum;
            cout << sum << endl;
            for(auto it : got) {
                cout << it << " ";
            }
            cout << endl;
        }
        return;
    }
    got.push_back(curr);
    bigans(curr + 2, sum + arr[curr]);
    got.pop_back();
    bigans(curr + 1, sum);

}

ll dp[MAX_N][4];

signed main() {
    cin >> n;
    for(int i = 1; i <= n; i ++) {
        cin >> arr[i];
    }
    ll cnt[2];
    cnt[0] = cnt[1] = 0;
    for(int i = 1; i <= n; i ++) {
        cnt[i & 1] += arr[i];
        pref[i] = max(cnt[0], cnt[1]);
    }
    cnt[0] = cnt[1] = 0;
    for(int i = n; i > 0; i --) {
        cnt[i & 1] += arr[i];
        suf[i] = max(cnt[0], cnt[1]);
    }
    if(n % 2 == 0) {
        cout << pref[n] << endl;
        return 0;
    }
    for(int i = 1; i <= n; i ++) {
        if(i & 1) {
            dp[i][0] = dp[i - 1][0] + arr[i];
            dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]);
            if(i >= 3) {dp[i][2] = max(dp[i - 1][2] + arr[i], dp[i - 3][1] + arr[i]);} else {dp[i][2] = dp[i - 1][2] + arr[i];}
        } else {
            dp[i][0] = dp[i - 1][0];
            if(i >= 3) {dp[i][1] = max(dp[i - 1][1] + arr[i], dp[i - 3][0] + arr[i]);} else {dp[i][1] = dp[i - 1][1] + arr[i];}
            dp[i][2] = dp[i - 1][2];
        }
    }
    cout << dp[n][2] << endl;
    return 0;
}
/*
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
*/