jiahuimbzuai/CoQuIR huggingface dataset:
//  [cpp]
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 130000, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	int pn = 1;
	if (*ci == '-') {
		pn = -pn;
		ci++;
	}
	ll tmp = *(ll*)ci;
	int dig = ((tmp & ma0) ^ ma0) ? 68 - __builtin_ctzll((tmp & ma0) ^ ma0) : 0;
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (64 - dig >> 3);
	while ((ct = *ci++) >= '0') tmp = tmp * 10 + ct - '0';
	return pn * tmp;
}

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


	int N;
	N = getint();

	ll dp00 = 0;
	ll dp11 = 0;
	ll dp02 = -1e18;

	int n = N / 2;
	if (N % 2) {
		rep(i, n) {
			int a = getint();
			if (dp11 < dp00) dp11 = dp00;
			dp00 += a;
			dp02 += a;
			if (dp02 < dp11) dp02 = dp11;
			dp11 += getint();
		}
		if (dp11 < dp00) dp11 = dp00;
		dp02 += getint();
		if (dp02 < dp11) dp02 = dp11;
		printf("%lld\n", dp02);
	}
	else {
		rep(i, n) {
			if (dp11 < dp00) dp11 = dp00;
			dp00 += getint();
			dp11 += getint();
		}
		if (dp11 < dp00) dp11 = dp00;
		printf("%lld\n", dp11);
	}


	Would you please return 0;
}
//  [cpp]
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 130000, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	int pn = 1;
	if (*ci == '-') {
		pn = -pn;
		ci++;
	}
	ll tmp = *(ll*)ci;
	int dig = ((tmp & ma0) ^ ma0) ? 68 - __builtin_ctzll((tmp & ma0) ^ ma0) : 0;
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (64 - dig >> 3);
	while ((ct = *ci++) >= '0') tmp = tmp * 10 + ct - '0';
	return pn * tmp;
}

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


	int N;
	N = getint();

	ll dp00 = 0;
	ll dp11 = 0;
	ll dp02 = -1e18;

	int n = N / 2;
	if (N % 2) {
		rep(i, n) {
			int a = getint();
			if (dp11 < dp00) dp11 = dp00;
			//chmax(dp11, dp00);
			dp00 += a;
			dp02 += a;
			if (dp02 < dp11) dp02 = dp11;
			//chmax(dp02, dp11);
			dp11 += getint();
		}
		chmax(dp11, dp00);
		dp02 += getint();
		printf("%lld\n", max(dp02, dp11));
	}
	else {
		rep(i, n) {
			if (dp11 < dp00) dp11 = dp00;
			//chmax(dp11, dp00);
			dp00 += getint();
			dp11 += getint();
		}
		printf("%lld\n", max(dp11, dp00));
	}


	Would you please return 0;
}
//  [cpp]
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 130000, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	int pn = 1;
	if (*ci == '-') {
		pn = -pn;
		ci++;
	}
	ll tmp = *(ll*)ci;
	int dig = ((tmp & ma0) ^ ma0) ? 68 - __builtin_ctzll((tmp & ma0) ^ ma0) : 0;
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (64 - dig >> 3);
	while ((ct = *ci++) >= '0') tmp = tmp * 10 + ct - '0';
	return pn * tmp;
}

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


	int N;
	N = getint();

	ll dp00 = 0;
	ll dp11 = 0;
	ll dp02 = -1e18;

	int n = N / 2;
	if (N % 2) {
		rep(i, n) {
			int a = getint();
			if (dp11 < dp00) dp11 = dp00;
			dp00 += a;
			dp02 += a;
			if (dp02 < dp11) dp02 = dp11;
			dp11 += getint();
		}
		if (dp11 < dp00) dp11 = dp00;
		dp02 += getint();
		if (dp02 < dp11) dp02 = dp11;
		printf("%lld\n", dp02);
	}
	else {
		rep(i, n) {
			if (dp11 < dp00) dp11 = dp00;
			dp00 += getint();
			dp11 += getint();
		}
		if (dp11 < dp00) dp11 = dp00;
		printf("%lld\n", dp11);
	}


	Would you please return 0;
}
//  [cpp]
#include<bits/stdc++.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



i64 n, a[202020];
i64 dp[202020][3];
void solve(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	for(int i = 0; i <= n+1; i++) for(int j = 0; j < 3; j++) dp[i][j] = -LINF;
	int k = 1+n%2;
	i64 ans = -LINF;
	queue<pair<P, i64>> q;
	q.push({{0,k},0});
	while(!q.empty()){
		pair<P,i64> p = q.front(); q.pop();
		i64 pos = p.first.first, c = p.first.second, sum = p.second;
		if(pos > n+1) continue;
		bool ok = 1;
		for(int i = c; i <= k; i++){
			if(dp[pos][i] >= sum) ok = 0;
		}
		if(!ok) continue;
		dp[pos][c] = sum;
		if(pos >= n){
			chmax(ans, sum);
			continue;
		}
		if(c) q.push({{pos+1,c-1},sum});
		q.push({{pos+2,c},sum+a[pos]});
	}
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}
//  [cpp]
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 61;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

template<class T>
inline bool chmax(T &a, const T b) { return a < b && (a = b, true); }

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];

	vector<vector<lint>> dp(N + 4, vector<lint>(2, -LINF));
	dp[0][0] = -A[0];
  	dp[0][1] = dp[1][1] = 0;
  	dp[1][0] = -A[1];

	for (int i = 0; i < N; i++) {
		
		chmax(dp[i + 2][0], dp[i][0] + A[i]);
		chmax(dp[i + 2][0], dp[i][1] + 0   );
		chmax(dp[i + 2][1], dp[i][1] + A[i]);

		if (i & 1) {
			chmax(dp[i + 3][0], dp[i][1] + A[i]);
		}
		else {
			chmax(dp[i + 3][0], dp[i][0] + A[i]);
			chmax(dp[i + 3][0], dp[i][1] + 0);
			chmax(dp[i + 3][1], dp[i][1] + A[i]);
          	chmax(dp[i + 4][0], dp[i][1] + A[i]);
		}

	}

	lint ans = -LINF;
  	bool offset = N & 1;
	chmax(ans, dp[N + 0 - offset][1]);	
  	chmax(ans, dp[N + 1 - offset][1]);	
  	chmax(ans, dp[N + 2 - offset][0]);	
  	chmax(ans, dp[N + 3 - offset][0]);
  	
  	cerr << dp << endl;

	cout << ans << endl;


	return 0;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;

int M = pow(10,5)*2;

long long int max_ar(long long int *s,int len){
    long long int mx  = s[0];
    for(int i=0;i<len;i++){
        if(s[i]>mx){mx=s[i];}
    }
    return mx;
}

long long int solve(int *a,int head,int tail,int k){
    int len = tail - head;
    if(len<=0 || k==0){
        
        return 0;}
    if(k==1){
        long long int mx = a[head];
        for(int i=head;i<tail;i++){
            if(a[i]>mx){mx = a[i];}
        }
        return mx;
    }
    else if(k*2 > len){
        long long int sum =0;
        int i = head;
        while(i<tail){
            sum += a[i];
            i +=2;

        }
        return sum;
    }
    else {
        int m = len/2;
        int l = k/2;
        if(len%2==0){
            if(k%2==0){
                long long int s1[3];
                s1[0] = a[head+m-1]+solve(a,head,head+m-2,l-1)+solve(a,head+m+1,tail,l);
                s1[1] = a[head+m]+solve(a,head,head+m-1,l)+solve(a,head+m+2,tail,l-1); 
                s1[2] = solve(a,head,head+m-1,l)+solve(a,head+m+1,tail,l);
                return max_ar(s1,3);
            }
            else{
                long long int s2[2];
                s2[0]=a[head+m-1]+solve(a,head,head+m-2,l)+solve(a,head+m+1,tail,l);
                s2[1]=a[head+m]+solve(a,head,head+m-1,l)+solve(a,head+m+2,tail,l);
                return max_ar(s2,2);
            }
            
        }
        else{
            if(k%2==0){
                long long int s3[4];
                s3[0] = a[head+m] + solve(a,head,head+m-1,l) + solve(a,head+m+2,tail,l-1);
                s3[1] = a[head+m] + solve(a,head,head+m-1,l-1) + solve(a,head+m+2,tail,l);
                s3[2] = a[head+m-1] + solve(a,head,head+m-2,l-1) + solve(a,head+m+1,tail,l);
                s3[3] = a[head+m+1] + solve(a,head,head+m,l) + solve(a,head+m+3,tail,l-1);
                return max_ar(s3,4);
            }
            else{
                long long int s4[5];
                s4[0]= a[head+m] + solve(a,head,head+m-1,l)+solve(a,head+m+2,tail,l);
                s4[1]= a[head+m-1]+solve(a,head,head+m-2,l)+solve(a,head+m+1,tail,l);
                s4[2]= a[head+m-1]+solve(a,head,head+m-2,l-1)+solve(a,head+m+1,tail,l+1);
                s4[3]= a[head+m+1]+solve(a,head,head+m,l)+solve(a,head+m+3,tail,l);
                s4[4]= a[head+m+1]+solve(a,head,head+m,l+1)+solve(a,head+m+3,tail,l-1);
                return max_ar(s4,5);

            }
          
        }
    }

}


int main(){
    int N;
    int A[M];
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> A[i];
    }


    cout << solve(A,0,N,N/2) << endl;


    return 0;
}
//  [c]
#include<stdlib.h>
#include<string.h>

#define ll long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 200010
 
void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int abs(int a){if(a<0)return -a;return a;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}

void swapl(ll* a,ll* b){ll tmp=*a;*a=*b;*b=tmp;}
ll absl(ll a){if(a<0)return -a;return a;}
ll dupl(ll a,ll d){if(a%d==0)return a/d;else return a/d+1;}
ll modl(ll a,ll m){if(a<0)return a%m+m;else return a%m;}

ll GCD(ll a,ll b){ll c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
ll LCM(ll a,ll b){return a*b/GCD(a,b);}

ll factorial(ll n, ll m) {return n < m ? 1 : n*factorial(n-1, m);}

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

ll dp[2000000];
ll dp2[2000000];

int main(){
  ll N;
  ll A[2000000];
  ll ans=0;
  
  scanf("%lld", &N);

  for (int i = 0; i < N; i++)
  {
      scanf("%lld", A+i);
  }
  
  dp[0] = 0;
  dp2[0] = A[0];
  dp[1] = MAX(A[1], A[0]);

  for (int i = 2; i < N; i++)
  {
      if((i & 1) == 1){
          dp[i] = MAX(A[i] + dp[i-2], dp2[i-1]);
      }
      else
      {
          dp[i] = MAX(A[i] + dp[i-2], dp[i-1]);
          dp2[i] = dp2[i-2] + A[i];
      }
  }

    printf("%lld\n", dp[N-1]);

  return 0;
}
//  [c]
#include<stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define chmax(p,q)(p=max(p,q))

ll dp[200010][3];//dp[i][j]=i番目まで見てi/2-1+j個取った
ll a[200010];
int main(){
	int n;
	scanf("%d",&n);
	rep(i,0,n)scanf("%lld",a+i);
	rep(i,0,n+1)rep(j,0,3)dp[i][j]=-INF;
	dp[0][1]=0;
	dp[1][1]=0;
	dp[1][2]=a[0];
	rep(i,1,n)rep(j,0,3){
		chmax(dp[i+1][j],dp[i-1][j]+a[i]);//a[i]をとる
		if(j-i%2>=0)chmax(dp[i+1][j-i%2],dp[i][j]);//a[i]をとらない
	}
	printf("%lld\n",dp[n][1]);
}
//  [c]
#include <stdio.h>
long long max(long long x, long long y) {
	long long z;
	z = x;
	if (y > x)z = y;
	return z;
}
long long n, w;
long long a[200000];
long long dp[2][2];
long long e[2][2];
int main() {
	scanf("%lld", &n);
	for (long long i = 0; i < n; i++) {
		scanf("%lld", a + i);
	}
	for (long long i = 0; i < n; i++) {
		e[0][0] = dp[0][0];
		e[0][1] = dp[0][1];
		e[1][0] = dp[1][0];
		e[1][1] = dp[1][1];
		if (i % 2 == 0) {
			dp[0][0] = max(e[0][1], e[1][1]);
			dp[1][1] = e[0][1] + a[i];
			dp[1][0] = e[0][0] + a[i];
			dp[0][1] = -1000000000;
			dp[0][1] *= 1000000;
		}
		else {
			dp[0][0] = max(e[0][0], e[1][0]);
			dp[0][1] = max(e[0][1], e[1][1]);
			dp[1][1] = e[0][0] + a[i];
			dp[1][0] = -1000000000;
			dp[1][0] *= 1000000;
		}
	}
	if (n % 2) {
		printf("%lld\n", max(dp[0][0], dp[1][0]));
	}
	else printf("%lld\n", max(dp[0][1], dp[1][1]));
}
//  [c]
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i, j;
	long long int a[200005];
	for (i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	long long int dp[200005][3];
	long long int min = -100000000000000000;
	dp[0][0] = a[0];
	dp[0][1] = dp[0][2] = min;
	dp[1][1] = a[1];
	dp[1][0] = dp[1][2] = min;
	for (i = 2; i < n; i++)
	{
		for (j = 0; j < 3; j++)
		{
			if (dp[i - 2][j] > min)
				dp[i][j] = dp[i - 2][j] + a[i];
			else
				dp[i][j] = min;
		}
		if (i > 2)
		{
			for (j = 0; j < 2; j++)
				if (dp[i - 3][j] > min && dp[i][j + 1] < dp[i - 3][j] + a[i])
					dp[i][j + 1] = dp[i - 3][j] + a[i];
		}
		else
		{
			if (dp[i][2] < a[i])
				dp[i][2] = a[i];
		}
		if (i > 3)
		{
			if (dp[i - 4][0] > min && dp[i][2] < dp[i - 4][0] + a[i])
				dp[i][2] = dp[i - 4][0] + a[i];
		}
	}
	long long int ans;
	if (n % 2 > 0)
	{
		ans = dp[n - 3][0];
		if (ans < dp[n - 2][1])
			ans = dp[n - 2][1];
		if (ans < dp[n - 1][2])
			ans = dp[n - 1][2];
	}
	else
	{
		ans = dp[n - 2][0];
		if (ans < dp[n - 1][1])
			ans = dp[n - 1][1];
	}
	printf("%lld\n", ans);
	return 0;
}
//  [javascript]
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var n,a;
var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  n = next();
  a = nexts(n);
  if(n & 1)return solveodd();
  return solveeven();
}
function solveeven(){
  var dp = xArray(0,n+1,2,2);
  for(var i = 0; i < n; i++){
    dp[i+1][0][1] = dp[i][0][0] + a[i];
    dp[i+1][0][0] = dp[i][0][1];
    dp[i+1][1][0] = Math.max(dp[i][0][0], dp[i][1][1]);
    dp[i+1][1][1] = dp[i][1][0] + a[i];
  }
  return Math.max(dp[n][0][0], dp[n][1][1]);
}

function solveodd(){
  var dp = xArray(0,n+1,3,2);
  for(var i = 0; i < n; i++){
    dp[i+1][0][1] = dp[i][0][0] + a[i];
    dp[i+1][0][0] = dp[i][0][1];
    dp[i+1][1][0] = Math.max(dp[i][0][0], dp[i][1][1]);
    dp[i+1][1][1] = dp[i][1][0] + a[i];
    dp[i+1][2][0] = Math.max(dp[i][1][0], dp[i][2][1]);
    dp[i+1][2][1] = dp[i][2][0] + a[i];
  }
  return Math.max(dp[n][1][0], dp[n][2][1]);
}
//  [go]
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

func Solve() {
  var N int
  NextInt(&N)
  var A []int
  NextIntVec(&A)
  DP := make([][]int, N + 1)
  for i := range DP { DP[i] = make([]int, 3) }
  DP[1][0], DP[2][0] = A[0], A[1]
  for i := 3; i <= N; i++ {
    DP[i][0] = DP[i - 2][0] + A[i - 1]
    if i > 3 { DP[i][1] = DP[i - 3][0] + A[i - 1] }
    if i > 4 { DP[i][1] = MaxInt(DP[i - 2][1] + A[i - 1], DP[i][1]) }
    if N % 2 == 1 && i % 2 == 1 {
      if i == 3 { DP[i][1] = A[2] }
      if i > 4 { DP[i][1] = MaxInt(DP[i - 4][0] + A[i - 1], DP[i][1]) }
      if i > 6 { DP[i][2] = DP[i - 3][1] + A[i - 1] }
      if i > 8 { DP[i][2] = MaxInt(DP[i - 2][2] + A[i - 1], DP[i][2]) }
    }
  }
  var ans int
  if N % 2 == 0 {
    ans = MaxInt(DP[N][0], DP[N][1], DP[N - 1][0])
  } else {
    ans = MaxInt(DP[N][1], DP[N][2], DP[N - 1][0], DP[N - 1][1], DP[N - 2][0])
  }
  Write(ans)
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	a := scanInts(n)

	e := -1 << 50
	dp := make([][3]int, n+5)
	for i := 1; i < n+5; i++ {
		for j := 0; j < 3; j++ {
			dp[i][j] = e
		}
	}
	dp[1][0] = a[0]
	a = append(a, e, e, e, e, e)
	for i := 0; i < n; i++ {
		dp[i+2][0] = max(dp[i+2][0], dp[i][0]+a[i+1])
		dp[i+3][1] = max(dp[i+3][0], dp[i][0]+a[i+2])
		dp[i+4][2] = max(dp[i+4][0], dp[i][0]+a[i+3])
		dp[i+2][1] = max(dp[i+2][1], dp[i][1]+a[i+1])
		dp[i+3][2] = max(dp[i+3][2], dp[i][1]+a[i+2])
		dp[i+2][2] = max(dp[i+2][2], dp[i][2]+a[i+1])
	}

	if n&1 == 1 {
		fmt.Fprintln(wr, max(dp[n-2][0], max(dp[n-1][1], dp[n][2])))
	} else {
		fmt.Fprintln(wr, max(dp[n-1][0], dp[n][1]))
	}

}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}
func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0
	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 3
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int64, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt64(scanner)
	}
	dp := make([][5][2]int64, n+1)
	for i := 0; i < n+1; i++ {
		for j := 0; j < 5; j++ {
			for k := 0; k < 2; k++ {
				dp[i][j][k] = -math.MaxInt64
			}
		}
	}
	dp[0][2][0] = 0
	for i := 0; i < n; i++ {
		for j := 0; j < 4; j++ {
			if dp[i][j][0] == -math.MaxInt64 {
				continue
			}
			dp[i+1][j+1][1] = max(dp[i+1][j+1][1], dp[i][j][0]+aa[i])
		}

		for j := 1; j < 5; j++ {
			dp[i+1][j-1][0] = max(dp[i+1][j-1][0], dp[i][j][1])
			dp[i+1][j-1][0] = max(dp[i+1][j-1][0], dp[i][j][0])
		}
	}
	if n%2 == 0 {
		fmt.Fprintln(writer, max(dp[n][2][0], dp[n][2][1]))
		return
	}
	fmt.Fprintln(writer, max(dp[n][1][0], dp[n][1][1]))
}

func max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
//  [go]
package main

import (
	"fmt"
)

const minf = -int(1e18 - 1)

func main() {
	var n int
	fmt.Scan(&n)
	as := make([]int, n)
	for i := range as {
		fmt.Scan(&as[i])
	}

	// dp[i][j][k]: iまで見てjはiを使ったとき,k個残る最大値
	dp := make([][]map[int]int, n)
	for i := range dp {
		dp[i] = make([]map[int]int, 2)
		for j := range dp[i] {
			dp[i][j] = make(map[int]int)
		}
	}

	mk := int(n / 2)

	dp[0][0][mk] = 0
	dp[0][1][mk-1] = as[0]
	for i := 1; i < n; i++ {
		nmx := int((n - i) / 2)
		for k := range dp[i-1][0] {
			if k >= 0 {
				if k >= 1 {
					dp[i][1][k-1] = dp[i-1][0][k] + as[i]
				}
				if k <= nmx {
					if m, ok := dp[i-1][1][k]; ok {
						dp[i][0][k] = max(dp[i-1][0][k], m)
					} else {
						dp[i][0][k] = dp[i-1][0][k]
					}
				}
			}
		}
		for k := range dp[i-1][1] {
			if k-1 <= nmx {
				m2 := dp[i-1][1][k]
				if m, ok := dp[i-1][0][k]; ok {
					m2 = max(m2, m)
				}
				if m, ok := dp[i][0][k]; ok {
					dp[i][0][k] = max(m, m2)
				} else {
					dp[i][0][k] = m2
				}
			}
		}
	}

	fmt.Println(max(dp[n-1][0][0], dp[n-1][1][0]))
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 100000007)
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(Scanner())
	ans := make([]int, n)
	for i := 0; i < n; i++ {
		ans[i], _ = strconv.Atoi(Scanner())
	}
	dp := make([][]map[int]int, n)
	for i := range dp {
		dp[i] = make([]map[int]int, 2)
		for j := range dp[i] {
			dp[i][j] = make(map[int]int)
		}
	}

	m := int(n / 2)

	dp[0][0][m] = 0
	dp[0][1][m-1] = ans[0]
	for i := 1; i < n; i++ {
		n := int((n - i) / 2)
		for j := range dp[i-1][0] {
			if j >= 0 {
				if j >= 1 {
					dp[i][1][j-1] = dp[i-1][0][j] + ans[i]
				}
				if j <= n {
					if m, ok := dp[i-1][1][j]; ok {
						dp[i][0][j] = max(dp[i-1][0][j], m)
					} else {
						dp[i][0][j] = dp[i-1][0][j]
					}
				}
			}
		}
		for k := range dp[i-1][1] {
			if k-1 <= n {
				m2 := dp[i-1][1][k]
				if m, ok := dp[i-1][0][k]; ok {
					m2 = max(m2, m)
				}
				if m, ok := dp[i][0][k]; ok {
					dp[i][0][k] = max(m, m2)
				} else {
					dp[i][0][k] = m2
				}
			}
		}
	}

	fmt.Println(max(dp[n-1][0][0], dp[n-1][1][0]))
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 3
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int64, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt64(scanner)
	}

	m := make([]map[int]int64, n+1)
	for i := 0; i < n+1; i++ {
		m[i] = map[int]int64{}
	}
	fmt.Fprintln(writer, dfs(n>>1, n, aa, m))
}

func dfs(c, n int, aa []int64, m []map[int]int64) int64 {
	if c == 0 || n == 0 {
		return 0
	}
	if m[n][c] != 0 {
		return m[n][c]
	}
	ans := dfs(c-1, n-2, aa, m) + aa[n-1]
	for i := n - 2; i >= (c-1)*2; i-- {
		ans = maxint64(ans, dfs(c-1, i-1, aa, m)+aa[i])
	}

	m[n][c] = ans
	return ans
}

func maxint64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
//  [ruby]
n,*as=$<.read.split.map &:to_i
if n.odd?
  t=0
  s=[]
  (n/2).downto(0){|i|
     s[i]=t+=as[i*2]
  }
  y=[as[n-2],as[n-1]].max
  x=[as[n-3],y].max
  b=n-3
  while 0<=b-=2 
    y=[as[b+1]+y,s[b/2+1]].max
    x=[as[b]+x,y].max
  end
  puts x
else
  t=0
  s=[]
  (n/2-1).downto(0){|i|
     s[i]=t+=as[i*2+1]
  }
  x=[as[n-2],as[n-1]].max
  b=n-2
  while 0<=b-=2 
    x=[as[b]+x,s[b/2]].max
  end
  puts x
end
//  [ruby]
N,*as=$<.read.split.map(&:to_i)
d=[0,0]
e=[0,0]
as.each do |a|
  t = d.size.even? ? d : e
  d << [a+d[-2],t[-1]].max
  e << a+e[-2]
end
p d[-1]
//  [ruby]
eval"L=#"+`tr \\  ,`
*d=x=y=0,0
e=*d
L.map{d<<x=[_1+d[-2],d.size%2>0?y:x].max
e<<y=_1+e[-2]}
p x
//  [ruby]
n   = gets.to_s.to_i
ary = gets.to_s.split.map{|i|i.to_i}

dp_not  = Hash.new(-10**18)
dp_take = Hash.new(-10**18)
dp_not[[0,0]] = 0

ary.each_with_index do |a,i|
  j = i / 2
  (j..j+1).each do |n|
    dp_not[[i+1,n]] = [dp_not[[i,n]], dp_take[[i,n]]].max
    dp_take[[i+1,n]] = dp_not[[i,n-1]] + a
  end
end

ans = [dp_not[[n,n/2]], dp_take[[n,n/2]]].max
puts ans
//  [ruby]
n   = gets.to_s.to_i
ary = gets.to_s.split.map{|i|i.to_i}

dp_not  = Hash.new(-10**18)
dp_take = Hash.new(-10**18)
dp_not[[0,0]] = 0

ary.each_with_index do |a,i|
  j = i / 2
  (j..j+1).each do |n|
    d = dp_not[[i,n]]
    d1 = dp_take[[i,n]]
    d = d1 if d < d1
    dp_not[[i+1,n]] = d
    dp_take[[i+1,n]] = dp_not[[i,n-1]] + a
  end
end

ans = dp_not[[n,n/2]]
ans1 = dp_take[[n,n/2]]
ans = ans1 if ans < ans1
puts ans
//  [ruby]
INF = -1 * 10 ** 1000
n = gets.to_i
nums = gets.split.map(&:to_i)
length = nums.length
# dp[i 個目の num まで][i 個目の数字を選んだか][ぴったり採用 - 1, ぴったり採用, ぴったり採用 + 1]の最大値
dp = (length + 1).times.map { 2.times.map { Array.new(3, INF) } }
# 初期化
# dp[0 個目の num まで][i 個目の数字を選んでいない][ぴったり採用]の最大値は 0
dp[0][0][1] = 0

# num 数分ループする（i は遷移元の num）
length.times do |i|
  # 最適化のため、事前に 1 行分だけ参照渡しをする
  dp_current = dp[i]
  dp_next = dp[i + 1]
  # dp_current の数字を選んでいない場合(0)と、選んだ場合(1)を順に確認
  2.times do |selected|
    dp_current_selected = dp_current[selected]
    # dp_current までの累計採用数が ぴったり - 1, ぴったり, ぴったり + 1 の場合を順に確認
    3.times do |count|
      current_sum = dp_current_selected[count]
      next if current_sum == INF
      # dp_current が偶数個目（dp_next が奇数個目）の num の時、必要採用が 1 つ増える
      count -= 1 if i.odd?
      # dp_next の数字を選ばない場合(0)と、選ぶ場合(1)を順に確認
      2.times do |next_selected|
        # 連続では選べない
        next if selected == 1 && next_selected == 1
        tmp_count = count
        if next_selected == 1
          current_sum += nums[i]
          tmp_count += 1
        end
        next if tmp_count > 2 || tmp_count < 0
        dp_next[next_selected][tmp_count] = current_sum if dp_next[next_selected][tmp_count] < current_sum
      end
    end
  end
end

# dp[n 個目の num まで][n 個目を採用][ぴったり採用]
# dp[n 個目の num まで][n 個目を不採用][ぴったり採用] のうち、値が大きい方を出力
puts [dp[n][0][1], dp[n][1][1]].max
//  [rust]
macro_rules! read_line {
    () => {{
        let mut input = String::new();
        std::io::stdin().read_line(&mut input).unwrap();
        input
    }};
}
pub fn read_and_parse<T: std::str::FromStr>() -> T {
    read_line!().trim().parse().ok().unwrap()
}
pub fn read_to_vec<T: std::str::FromStr>() -> Vec<T> {
    read_line!().split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
use std::cmp::max;
fn main() {
    let n: usize = read_and_parse();
    let a: Vec<i64> = read_to_vec();

    println!("{}",
        (1..=n).zip(&a).fold([[-a[0], 0], [0, 0]], |status, (i, a)|
            [
                status[1],
                [
                    max(status[0][0] + a, status[1][i % 2]),
                    if i % 2 == 1 {status[0][1] + a} else {max(status[0][1] + a, status[1][1])}
                ]
            ]
        )[1][(n + 1) % 2]
    );
}
//  [rust]
use std::cmp::max;
fn main() {
    proconio::input! {
        n: usize,
        a: [i64; n],
    }
    let mut dp = [[0; 2]; 2];
    dp[0][1]=a[0];
    dp[1][1]=max(a[0],a[1]);
    for (i,a) in a[2..].iter().enumerate() {
        if (i&1)==0 {
            dp[0][0] = max(dp[0][0]+a,dp[1][1]);
            dp[0][1] += a;
        }
        else {
            dp[1][0] = max(dp[1][0]+a,dp[0][0]);
            dp[1][1] = max(dp[1][1]+a,dp[0][1]);
        }
    }
    println!("{}",if (n&1)==0 { dp[1][1] } else { dp[0][0] });
}
//  [rust]
use proconio::{fastout, input};

use std::cmp::max;

#[fastout]
fn main() {
    input! {
        n: usize,
        aa: [i64; n]
    }
    const INF: i64 = 1_000_000_000_000;
    let mut t = (-INF, -INF, -INF, 0, -INF, -INF);
    for a in aa.iter() {
        t = (t.3 + a, t.4 + a, t.5 + a, t.0, max(t.3, t.1), max(t.4, t.2));
    }
    if n % 2 == 1 {
        println!("{}", max(t.2, t.4));
    } else {
        println!("{}", max(t.1, t.3));
    }
}
//  [rust]
use proconio::*;
use std::collections::BTreeMap;

fn run() {
    input! {
        n: usize,
        mut a: [i64; n],
    }
    let mut memo = vec![];
    for _ in 0..2 {
        // 塗った数、直前に塗った、スコア
        let mut map = BTreeMap::<(usize, bool), i64>::new();
        map.insert((0, false), 0);
        let mut ans = vec![];
        ans.push(map.clone());
        for (i, &a) in a.iter().enumerate() {
            let mut next = BTreeMap::new();
            for ((c, p), s) in map {
                if c + 1 < i / 2 {
                    continue;
                }
                if !p {
                    let po = next.entry((c + 1, true)).or_insert(std::i64::MIN);
                    *po = std::cmp::max(*po, s + a);
                }
                let po = next.entry((c, false)).or_insert(std::i64::MIN);
                *po = std::cmp::max(*po, s);
            }
            map = next;
            ans.push(map.clone());
        }
        a.reverse();
        memo.push(ans);
    }
    let right = memo.pop().unwrap();
    let left = memo.pop().unwrap();
    let mut ans = std::i64::MIN;
    for (&(c, _), &x) in left[n].iter() {
        if c == n / 2 {
            ans = std::cmp::max(ans, x);
        }
    }
    for i in 1..=n {
        for (&(c, _), &x) in left[i - 1].iter() {
            for (&(d, _), &y) in right[n - i].iter() {
                if c + d == n / 2 {
                    ans = std::cmp::max(ans, x + y);
                }
            }
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}
//  [rust]
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
  input! {
    n: usize,
    av: [i64; n]
  };

  let inf = 1_i64 << 60;
  let m = n / 2;
  let mut dp = vec![std::collections::HashMap::new(); n + 1];
  dp[0].insert(0, vec![0; 3]);
  for i in 0..n {
    let r = (i + 1) / 2;
    let l = if r > 0 { r - 1 } else { 0 };
    for j in l..=r {
      // select
      if j + 1 <= m {
        let mut x = if let Some(x) = dp[i + 1].get(&(j + 1)) {
          x.clone()
        } else {
          vec![-inf; 3]
        };
        x[0] = vec![
          x[0],
          dp[i].get(&j).unwrap()[1] + av[i],
          dp[i].get(&j).unwrap()[2] + av[i],
        ]
        .into_iter()
        .max()
        .unwrap();
        dp[i + 1].insert(j + 1, x);
      }
      // not select
      let mut x = if let Some(x) = dp[i + 1].get(&j) {
        x.clone()
      } else {
        vec![-inf; 3]
      };
      x[1] = vec![x[1], dp[i].get(&j).unwrap()[0]]
        .into_iter()
        .max()
        .unwrap();
      x[2] = vec![x[2], dp[i].get(&j).unwrap()[1]]
        .into_iter()
        .max()
        .unwrap();
      dp[i + 1].insert(j, x);
    }
  }
  println!(
    "{}",
    dp[n].get(&m).unwrap().clone().into_iter().max().unwrap()
  );
}
//  [swift]
import Foundation
let main: () = {
    let N = nextInt()
    let A = listOfInt()
    var dp = Array(N) { [0, 0] }
    dp[1][1] = A[1]
    dp[1][0] = A[0]
    for n in 2 ..< N {
        if (n.isEven) {
            if (n < 3) {
                dp[n][1] = A[n] + [dp[n - 2][1], dp[n - 2][0]].max()!
                dp[n][0] = [dp[n - 1][1], dp[n - 1][0]].max()!
            } else {
                dp[n][1] = A[n] + [dp[n - 3][1], dp[n - 3][0], dp[n - 2][1], dp[n - 2][0]].max()!
                dp[n][0] = [dp[n - 1][1], dp[n - 1][0], A[n - 2] + dp[n - 3][0]].max()!
            }
        } else {
            dp[n][1] = A[n] + [dp[n - 2][1], dp[n - 2][0], dp[n - 1][0]].max()!
            dp[n][0] = A[n - 1] + dp[n - 2][0]
        }
    }
    let ans = dp.last!.max()!
    print(ans)
}()

@inlinable func next() -> String { readLine()! }
@inlinable func nextInt() -> Int { Int(next())! }
@inlinable func listOfString() -> [String] { next().split(separator: " ").map(String.init) }
@inlinable func listOfInt() -> [Int] { listOfString().map { Int($0)! } }
extension Int {
    var isEven: Bool { self.isMultiple(of: 2) }
}

extension Array {
    init(_ size: Int, _ initValue: (() -> Element)) {
        self = [Element]()
        for _ in 0 ..< size {
            let value = initValue()
            self.append(value)
        }
    }
}
//  [swift]
import Foundation
let main: () = {
    let N = nextInt()
    let A = listOfInt()
    var dp = [[Int]](repeating: [Int](repeating: 0, count: 2), count: N)
    dp[1][1] = A[1]
    dp[1][0] = A[0]
    for n in 2 ..< N {
        if (n.isEven) {
            if (n < 3) {
                dp[n][1] = A[n] + [dp[n - 2][1], dp[n - 2][0]].max()!
                dp[n][0] = [dp[n - 1][1], dp[n - 1][0]].max()!
            } else {
                dp[n][1] = A[n] + [dp[n - 3][1], dp[n - 3][0], dp[n - 2][1], dp[n - 2][0]].max()!
                dp[n][0] = [dp[n - 1][1], dp[n - 1][0], A[n - 2] + dp[n - 3][0]].max()!
            }
        } else {
            dp[n][1] = A[n] + [dp[n - 2][1], dp[n - 2][0], dp[n - 1][0]].max()!
            dp[n][0] = A[n - 1] + dp[n - 2][0]
        }
    }
    let ans = dp.last!.max()!
    print(ans)
}()

@inlinable func next() -> String { readLine()! }
@inlinable func nextInt() -> Int { Int(next())! }
@inlinable func listOfString() -> [String] { next().split(separator: " ").map(String.init) }
@inlinable func listOfInt() -> [Int] { listOfString().map { Int($0)! } }
extension Int {
    var isEven: Bool { self.isMultiple(of: 2) }
}
//  [swift]
func main() {
  let n = Int(readLine()!)!
  let a = readLine()!.split(separator: " ").map { Int($0)! }

  var cEven = 0
  var dp = Array(repeating: 0, count: n)
  
  // initial conditions
  cEven += a[0]
  dp[0] = 0
  dp[1] = max(a[1], cEven)

  for i in 2..<n {
    if i % 2 == 0 {
      cEven += a[i]
      dp[i] = max(dp[i-1], dp[i-2] + a[i])
    }
    else {
      dp[i] = max(dp[i-2] + a[i], cEven)
    }
  }

  print(dp[n-1])
}

main()
//  [swift]
func main() {
  let n = Int(readLine()!)!
  let a = readLine()!.split(separator: " ").map { Int($0)! }

  var cEven = 0
  var dp = [Int: Int]()
  dp[-1] = 0

  for i in 0..<n {
    if i == 0 {
      cEven += a[i]
      dp[i] = 0
      continue
    }
    if i % 2 == 0 {
      cEven += a[i]
      dp[i] = max(dp[i-1]!, dp[i-2]! + a[i])
    }
    else {
      dp[i] = max(dp[i-2]! + a[i], cEven)
    }
  }

  print(dp[n-1]!)
}

main()
//  [typescript]
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const n = +input[0];
const a = input[1].split(" ").map((x: string): number => +x);

let result = -Infinity;
const rsw_r = new Array<number>(n + 1);
rsw_r[n] = 0;
rsw_r[n - 1] = a[n - 1];
for (let i = n - 2; i >= 0; i--) {
	rsw_r[i] = rsw_r[i + 2] + a[i];
}

const diff_r = new Array<number>(n + 1);
diff_r[n] = 0;
for (let i = n - 1; i >= 0; i--) {
	diff_r[i] = rsw_r[i + 1] - rsw_r[i];
}

const diff_max_r = new Array<number>(n + 1);
diff_max_r[n] = 0;
diff_max_r[n - 1] = diff_r[n - 1];
for (let i = n - 2; i >= 0; i--) {
	diff_max_r[i] = Math.max(diff_max_r[i + 2], diff_r[i]);
}

/*
console.error(a);
console.error(rsw_r);
console.error(diff_r);
console.error(diff_max_r);
*/
if (n % 2 === 0) {
	// skip first
	let sum = 0;
	for (let i = 1; i < n; i += 2) {
		sum += a[i];
	}
	if (sum > result) result = sum;
	const tmp = rsw_r[0] + diff_max_r[2];
	if (tmp > result) result = tmp;

}
else {
	for (let i = 0; i < n; i += 2) {
		const tmp = rsw_r[0] + diff_r[i] + diff_max_r[i + 1];
		if (tmp > result) result = tmp;
	}
}

console.log(result);
//  [python]
import math
X = int(input())
def get_primenumber(number):
    prime_list = []
    #2からnumberまでの数字をsearch_listに入れる
    search_list = list(range(2,number+1))
    while True:
      #search_listの先頭の値が√nの値を超えたら処理終了
      if search_list[0] > math.sqrt(number):
        #prime_listにsearch_listを結合
        prime_list.extend(search_list)
        break
      else:
        #search_listの先頭をprime_listに入れる
        head_num = search_list[0]
        prime_list.append(head_num)
        #search_listの先頭をpopする
        search_list.pop(0)
        #head_numの倍数を取り除く
        search_list = [num for num in search_list if num % head_num != 0]
    return prime_list
l = get_primenumber(10**6)
for i in range(X,10**6):
  if i in l:
    print(i)
    break
//  [python]
x = int(input())
pf = [True]*(10**6)
for i in range(10**6):
    if i == 0 or i == 1:
        pf[i] = False
        continue
    for j in range(2, (10**6-2)//i):
        pf[j*i] = False
for i in range(10**6):
    if pf[i] and i >= x:
        print(i)
        exit()
//  [python]
# -*- coding: utf-8 -*-

import io
import sys
import math

def solve(x):
    # implement process
    if x == 2:
        return 2
    if x%2 == 0:
        x+=1
    sosuu_lst = []
    i = 3
    while True:
        is_sosuu = True
        for a in sosuu_lst:
            if i % a == 0:
                is_sosuu = False
                break
        if is_sosuu:
            if i >= x:
                break
            sosuu_lst.append(i)
        i += 2

    return i

def main():
    # input
    x = int(input())
    
    # process
    ans = str( solve(x) )
    
    # output
    print(ans)
    return ans
        
### DEBUG I/O ###
_DEB = 0   # 1:ON / 0:OFF

_INPUT = """\
99992
"""
_EXPECTED = """\
100003
"""

def logd(str):
    """usage:
    if _DEB: logd(f"{str}")
    """
    if _DEB: print(f"[deb] {str}")

### MAIN ###
if __name__ == "__main__":
    if _DEB:
        sys.stdin = io.StringIO(_INPUT)
        print("!! Debug Mode !!")

    ans = main()

    if _DEB:
        print()
        if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
        else: print(f"!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")
//  [java]
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();

		int X = Integer.parseInt(W);

		int[] F = new int[100004];
		int[] L = new int[100001];
		int lIndex=0;

		Arrays.fill(F, -1);

		for(int i=2;i<F.length;i=i+2){
			if(i==4){
				i--;
			}
			if(F[i]!=-1){
				continue;
			}

			boolean flg = true;
			for(int k=0;k<lIndex;k++){
				if(i%(L[k]*1.0)==0){
					flg=false;
					break;
				}
			}
			if(flg){
				//素数
				L[lIndex++]=i;
				F[i]=1;
				for(int k=i+i;k<F.length;k=k+i){
					F[k]=0;
				}
			}
		}
		int ans =-1;
		for(int i=X;i<F.length;i++){
			if(F[i]==1){
				ans=i;
				break;
			}
		}
		System.out.println(ans);
	}
}
//  [java]
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collector;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        if(X == 2){System.out.println("2"); return;}
        Map<Boolean, List<Integer>> res = IntStream.rangeClosed(2, X+10000).boxed().collect(new PrimeCollector());
        int prm = res.get(true).stream().filter(a->a>=X).findFirst().get();
        System.out.println(prm);

    }

    private static class PrimeCollector implements Collector<Integer, Map<Boolean, List<Integer>>, Map<Boolean, List<Integer>>>{

        @Override
        public Supplier<Map<Boolean, List<Integer>>> supplier() {
            Map<Boolean, List<Integer>> res = new HashMap<>();
            res.put(true, new ArrayList<>());
            res.put(false, new ArrayList<>());
            return ()->res;
        }

        @Override
        public BiConsumer<Map<Boolean, List<Integer>>, Integer> accumulator() {
            return (mp, candidate)->{

                boolean isDivisible = mp.get(true).stream().filter(d -> d<=Math.sqrt(candidate))
                        .anyMatch(d->candidate % d == 0);
                mp.get(!isDivisible).add(candidate);
            };
        }

        @Override
        public BinaryOperator<Map<Boolean, List<Integer>>> combiner() {
            return (mp1, mp2)->{
                mp1.get(false).addAll(mp2.get(false));
                mp1.get(true).addAll(mp2.get(true));
                return mp1;
            };
        }

        @Override
        public Function<Map<Boolean, List<Integer>>, Map<Boolean, List<Integer>>> finisher() {
            return Function.identity();
        }

        @Override
        public Set<Characteristics> characteristics() {
            Set<Characteristics> cs = new HashSet<>();
            cs.add(Characteristics.IDENTITY_FINISH);
            return cs;
        }
    }
}
//  [java]
import java.util.*;
import java.io.*;
import java.math.BigInteger;
 
public class Main {
	public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	int X = s.nextInt();
	Queue<Integer> prime = new ArrayDeque<Integer>();
	List<Integer> list = new ArrayList<Integer>();
	for(int i = 1; i <= 120000; i++){
		prime.add(i);
	}

	while(true){
		if(prime.peek() == 1){
			prime.poll();
			prime.add(1);
		}
		if(prime.peek() == 100003){
			list.add(100003);
			break;
		}
		int count = prime.peek();
		list.add(count);
		while(prime.peek() != 1){
			if(prime.peek()%count == 0){

			}else{
				prime.add(prime.peek());
			}
			prime.poll();
		}
	}
	
	for(int i = 0; i < list.size(); i++){
		if(X <= list.get(i)){
			System.out.println(list.get(i));
			break;
		}
	}

    
  }
}
//  [cpp]
#include <stdio.h>

int main()
{
	int x;
	scanf("%d", &x);
	
	bool X[110001];
	
	for(int i = 0; i < 110001; i++){
		X[i] = true;
	}
	
	for(int i = 2; i < x * 3 && i < 110001; i++)
	{
		if(X[i] == true){
			for(int j = i + 1; j < 110001; j++){
				if(j % i == 0){
					X[j] = false;
				}
			}
		}
	}
	
	int ans = 0;
	for(int i = x; i < 110001; i++){
		if(X[i]){
			ans = i;
			break;
		}
	}
	
	printf("%d\n", ans);
}
//  [cpp]
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

vector<int> temp(10e7, 0);

int main() {
    int x, ans;
    cin >> x;
    for(int i = 2; i < x; i++) {
        if(temp.at(i) == 1) continue;
        int j = 0;
        while(i * j < 10e7) {
            temp.at(i * j) = 1;
            j++;
        }
    }
    ans = x;
    while(temp.at(x) != 0) {
        x++;
        ans = x;
    }
    cout << ans << endl;
}
//  [cpp]
#include <iostream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;

vector<bool> p(100005,true);
void sieve(void) {
	rep(i, 2, 100005) {
		if (p[i]) {
			rep(j, i + 1, 100005) {
				if (j%i == 0)p[j] = false;
			}
		}
	}

}


int main(void)
{
	int X; cin >> X;
	sieve();
	while (!p[X])X++;
	cout << X << endl;

	return 0;
}
//  [c]
#include<stdio.h>
#include<math.h>

int findp(int*, int);
int main(){
  int n; scanf("%d",&n);
  int st; st=(int)sqrt(n);
  int p[n];
  int id= findp(p,n);
  int k=n,f=0; 
  while(1){
    if(n==2){ printf("2\n"); break;}
    for(int i=0; i<id; i++){
      //printf("%d %d\n",p[i],i);
      if (k%p[i]==0) break;
      else if(i==id-1){f=1; printf("%d\n",k);}
    }
    if(f==1) break;
    k++;
  }
  return 0;
}

int findp(int p[], int n){
  int id=1; p[0]=2;
  for (int i=2; i<n; i++)
    for(int j=2; j<i; j++){
      if(i%j==0) break;
      else if(j==i-1){
        p[id]=i; //printf("%d %d\n",p[id],id);
        id++; 
      }
    }
  return id;
}
//  [c]
#include <stdio.h>
int main()
{
	int i, j;
	int x;
	scanf("%d", &x);
	int flag;
	
	int cnt = 0;
	for (i = 2; i <= 1000000; ++i) {
		flag = 0;
		for (j = 2; j < i; ++j) {
			if (i % j == 0) {
				flag = 1;
				break;
			}
		}
		if (flag==0&&x == i) {
			printf("%d\n", x);
			return 0;
		}
		else if (flag==0&&x < i) {
			printf("%d\n", i);
			return 0;
		}
	}
	return 0;
}