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)

long long int max(long long int s1,long long int s2);
long long int back(long long int i,long long int *data,long long int n);
long long int maxAmong(long long int s1,long long int s2,long long int s3);
long long int oddback(long long int i,long long int *data,long long int n,long long int cur,long long int div);
int main(){
   long long int n,sum,div,i,res;
   long long int *data;
    scanf("%lld",&n);

    data=(long long int*)malloc(sizeof(long long int)*n);

    for(i=0;i<n;i++)
        scanf("%lld",&data[i]);
    
    div=n%2;
    if(div==0)
        res=back(0,data,n);
    else
        res=oddback(0,data,n,0,n/2);
    printf("%lld\n",res);
    return 0;
}

long long int back(long long int i,long long int *data,long long int n){
    long long int sum1=0,sum2=0;
    if(i<n){
        sum1=data[i]+back(i+2,data,n);
        sum2=data[i+1]+back(i+3,data,n);
    }
    return max(sum1,sum2);
}
long long int oddback(long long int i,long long int *data,long long int n,long long int cur,long long int div){
    long long int sum1=0,sum2=0,sum3=0;
    if((i+2)<n && cur<div){
        sum1=data[i]+oddback(i+2,data,n,cur+1,div);
        sum2=data[i+1]+oddback(i+3,data,n,cur+1,div);
        sum3=data[i+2]+oddback(i+4,data,n,cur+1,div);
        return maxAmong(sum1,sum2,sum3);
    }
    else if((i+1)<n && cur<div){
        sum1=data[i]+oddback(i+2,data,n,cur+1,div);
        sum2=data[i+1]+oddback(i+3,data,n,cur+1,div);
        return max(sum1,sum2);
    }
    else if(i<n && cur<div){
        sum1=data[i]+oddback(i+2,data,n,cur+1,div);
        return sum1;
    }   
    return 0;
}
long long int maxAmong(long long int s1,long long int s2,long long int s3){
    if(s1>=s2 && s1>=s3)
        return s1;
    else if(s2>=s1 && s2>=s3)
        return s2;
    return s3;
}
long long int max(long long int s1,long long int s2){
    if(s1>s2)
        return s1;
    return s2;
}