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>

#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i,a) for (auto i = rbegin(a); i != rend(a); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
using namespace std;
using ll = long long;
using ld = long double;
template<class T> using priority_queuel = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-10;
ll mod = static_cast<ll>(1e9 + 7);
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr void mins(T& a, Args... args) { a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr void maxs(T& a, Args... args) { a = max<T>({ a,args... }); }
template<class A, int N, class T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

int n;
ll a[200005];
ll dp[200005][3][2], dp2[200005][3][2];
void solve() {
    cin >> n;
    rep(i, n) cin >> a[i];

    if (n % 2 == 0) {
        ll res1 = 0, res2 = 0;
        rep(i, n) {
            if (i % 2 == 0) res1 += a[i];
            else res2 += a[i];
        }
        cout << max(res1, res2) << endl;
    }
    else {
        fillArray(dp, -inf);
        dp[0][0][0] = 0;
        rep(i, n) rep(j, 3) {
            if (dp[i][j][0] > -inf) {
                maxs(dp[i + 1][j][1], dp[i][j][0] + a[i]);
                if (i > 0 && j < 2) maxs(dp[i + 1][j + 1][0], dp[i][j][0]);
            }
            if (dp[i][j][1] > -inf) {
                maxs(dp[i + 1][j][0], dp[i][j][1]);
            }
        }
        fillArray(dp2, -inf);
        dp2[0][0][1] = 0;
        rep(i, n) rep(j, 2) {
            if (dp2[i][j][0] > -inf) {
                maxs(dp2[i + 1][j][1], dp2[i][j][0] + a[i]);
                if (i > 0 && j < 2) maxs(dp2[i + 1][j + 1][0], dp2[i][j][0]);
            }
            if (dp2[i][j][1] > -inf) {
                maxs(dp2[i + 1][j][0], dp2[i][j][1]);
            }
        }
        cout << max({ dp[n][2][0], dp[n][2][1],dp2[n][1][0],dp2[n][1][1] }) << endl;
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}