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 <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0LL);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

template <class T>
void VecRowShow(vector<T> vec) {
	rep(i, vec.size()) {
		if (i != vec.size() - 1) cout << vec[i] << " ";
		else cout << vec[i] << endl;
	}
}

unsigned euclidean_gcd(unsigned a, unsigned b) {
	if (a < b) return euclidean_gcd(b, a);
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

int main() {

	int n;
	cin >> n;
	vector<ll> e(n), o(n), q(n);
	rep(i, n) {
		ll a;
		cin >> a;
		q[i] = a;
		if (i % 2 == 0) {
			if (i == 0) {
				e[0] = a;
			}
			else {
				ll z = e[i - 2];
				e[i] = z + a;
			}
		}
		else {
			if (i == 1) {
				o[1] = a;
			}
			else {
				ll z = o[i - 2];
				o[i] = z + a;
			}
		}
	}
	if (n % 2 == 0) {
		ll se = e[n - 2];
		ll so = o[n - 1];
		if (se > so) {
			cout << se << endl;
		}
		else {
			cout << so << endl;
		}
		return 0;
	}

	ll ans = e[n - 3];

	ans = max(ans, e[n - 1] - e[0]);

	for (int a = 0; a < n - 3; a += 2) {
		ll z = e[a] + e[n - 1] - e[a + 2];
		ans = max(ans, z);
		ll z3 = e[a] + e[n - 1] - e[a + 2];
		z3 = z3 - q[a] + q[a + 1];
		ans = max(ans, z3);
		ll z2 = e[a] + o[n - 2] - o[a + 1];
		ans = max(ans, z2);
	}

	ans = max(ans, o[n - 2]);
	for (int a = 1; a < n - 2; a += 2) {
		ll z = o[a] + e[n - 1] - e[a + 1];
		ans = max(ans, z);
	}
	cout << ans << endl;
}