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 Java (OpenJDK 11.0.6) (judge verdict: Wrong Answer)

import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int N =sc.nextInt();
    long A[] =new long[N];
    long B[] =new long[N];
    long C[] =new long[N];
    long D[] =new long[N];
    long E[] =new long[N];
    for(int i=0;i<N;i++){
      A[i]=sc.nextLong();B[i]=0;C[i]=0;D[i]=0;}
    if(N%2==0){
      long x=0; long y=0;
      for(int j=0;j<N/2;j++){
        x=x+A[2*j]; y=y+A[2*j+1];}
      long c =Math.max(x,y);
      System.out.println(c);}
    else if(N%2==1){
      for(int l=0;l<N-1;l++){
        if(l==0){
          for(int p=0;p<=(N-3)/2;p++){
            B[0]=B[0]+A[2+2*p];}
          E[0]=B[0];}
        else if(l%2==0){
          for(int q=0;q<l/2;q++){
            C[l]=C[l]+A[2*q];D[l]=D[l]+A[2*q+1];}
          B[l]=B[l]+Math.max(C[l],D[l]);
          for(int m=0;m<=(N-l-3)/2;m++){
            B[l]=B[l]+A[l+2+2*m];}
          E[l]=Math.max(B[l],E[l-1]);}
        else{
          for(int n=0;n<=(l-1)/2;n++){
            B[l]=B[l]+A[2*n];}
          for(int v=0;v<(N-l-2)/2;v++){
            C[l]=C[l]+A[l+2+2*v];
            D[l]=D[l]+A[l+2+2*v+1];}
          B[l]=B[l]+Math.max(C[l],D[l]);
         E[l]= Math.max(B[l],E[l-1]);}}
      System.out.println(E[N-2]);
    }
  }
}