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 < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  vector<ll> odd;
  vector<ll> even;
  rep(i, n) {
    if (i % 2 == 0) even.push_back(a[i]);
    else odd.push_back(a[i]);
  }

  ll ans = 0;
  chmax(ans, SUM(odd));
  if (n % 2 == 0) {
    chmax(ans, SUM(even));
    cout << ans << endl;
    return 0;
  }
  chmax(ans, SUM(even) - MIN(even));

  vector<ll> esum(even.size(), 0);
  vector<ll> esumr(even.size(), 0);
  vector<ll> osum(odd.size(), 0);
  vector<ll> osumr(odd.size(), 0);
  esum[0] = even[0];
  esumr[even.size()-1] = even[even.size()-1];
  osum[0] = odd[0];
  osumr[odd.size()-1] = odd[odd.size()-1];

  for (int i = 1; i < even.size(); i++) {
    esum[i] = even[i] + esum[i-1];
  }
  for (int i = even.size() -2; i >= 0; i--) {
    esumr[i] = esumr[i+1] + even[i];
  }

  for (int i = 1; i < odd.size(); i++) {
    osum[i] = odd[i] + osum[i-1];
  }
  for (int i = odd.size() -2; i >= 0; i--) {
    osumr[i] = osumr[i+1] + odd[i];
  }
/*
  for (auto& v : esum) {
    cerr << v << " ";
  }
  cerr << endl;
  for (auto& v : esumr) {
    cerr << v << " ";
  }
  cerr << endl;
  for (auto& v : osum) {
    cerr << v << " ";
  }
  cerr << endl;
  for (auto& v : osumr) {
    cerr << v << " ";
  }
  cerr << endl;
*/
  for (int i = 0; i < odd.size() - 1; i++) {
    chmax(ans, esum[i] + osumr[i+1]);
  }
  for (int i = 0; i < odd.size() - 1; i++) {
    chmax(ans, osum[i] + esumr[i+2]);
  }

  cout << ans << endl;

  return 0;
}