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)

//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll

#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
typedef std::numeric_limits< double > dbl;
using namespace std;
const long long N=200005, INF=2000000000000000000;
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    int ar[n];
    for(int i=0;i<n;i++)
    cin>>ar[i];
    if(n%2==0)
    {
        int sum1=0,sum2=0;
        for(int i=0;i<n;i++)
        {
            if(i%2==0)
            sum1+=ar[i];
            else
            sum2+=ar[i];
        }
        cout<<max(sum1, sum2);
    }
    else
    {
        int sum1=0,sum2=0,sum3=0;
        for(int i=0;i<n-1;i++)
        {
            if(i%2==0)
            sum1+=ar[i];
            else
            sum2+=ar[i];
        }
        for(int i=2;i<n;i+=2)
        sum3+=ar[i];
        int dp[n][2];
        for(int i=0;i<n;i++)
        {
            dp[i][0]=-1;
            dp[i][1]=-1;
        }
        dp[0][0]=ar[0];
        if(n>1)
        dp[1][0]=ar[1];
        if(n>2)
        dp[2][0]=ar[0]+ar[2];
        for(int i=3;i<n;i++)
        {
            dp[i][1]=max(dp[i-2][1], dp[i-3][0]);
            if(dp[i][1]!=-1)
            dp[i][1]+=ar[i];
            if(dp[i-2][0]!=-1)
            dp[i][0]=dp[i-2][0]+ar[i];
        }
        int ans=max({sum1, sum2, sum3, dp[n-1][1]});
        if(n>=2&&dp[n-2][1]>ans)
        ans=dp[n-2][1];
        cout<<ans;
    }
}