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>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

const int N = 1e6 + 11;
int a[N] = {};
ll dp[N][3][2] = {};

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i <= n; i++) {
        for (int t1 = 0; t1 < 3; t1++) {
            for (int t2 = 0; t2 < 2; t2++) {
                dp[i][t1][t2] = -LINF;
            }
        }
    }
    dp[0][0][0] = 0;
    dp[0][0][1] = 0;
    for (int i = 0; i < n; i++) {
        umax(dp[i + 1][0][1], dp[i][0][0] + a[i + 1]);
        if (i + 2 <= n) {
            umax(dp[i + 2][1][1], dp[i][0][0] + a[i + 2]);
        }
        umax(dp[i + 1][1][1], dp[i][1][0] + a[i + 1]);
        umax(dp[i + 1][0][0], dp[i][0][1]);
        if (i + 3 <= n) {
            umax(dp[i + 3][1][1], dp[i][0][1] + a[i + 3]);
        }
        umax(dp[i + 1][1][0], dp[i][1][1]);
        if (n % 2 == 1) {
            if (i + 4 <= n && i > 0) {
                umax(dp[i + 4][2][1], dp[i][0][1] + a[i + 4]);
            }
            umax(dp[i + 1][2][1], dp[i][2][0] + a[i + 1]);
            if (i + 2 <= n) {
                umax(dp[i + 2][2][1], dp[i][1][0] + a[i + 2]);
            }
            umax(dp[i + 1][2][1], dp[i][2][0] + a[i + 1]);
            if (i + 3 <= n) {
                umax(dp[i + 3][2][1], dp[i][1][1] + a[i + 3]);
            }
            umax(dp[i + 1][2][0], dp[i][2][1]);
        }
    }
    ll ans = max({dp[n][1][0], dp[n][1][1], dp[n][2][1]});
    cout << ans << '\n';

//    for (int i = 0; i <= n; i++) {
//        for (int t1 = 0; t1 < 3; t1++) {
//            for (int t2 = 0; t2 < 2; t2++) {
//                cout << dp[i][t1][t2] << ' ';
//            }
//        }
//        cout << '\n';
//    }
}