macro_rules !read_value {($iter :expr ,($($t :tt ) ,*) ) =>{($(read_value !($iter ,$t ) ) ,*) } ;($iter :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($iter ,$t ) ) .collect ::<Vec <_ >>() } ;($iter :expr ,{chars :$base :expr } ) =>{read_value !($iter ,String ) .chars () .map (|c |(c as u8 -$base as u8 ) as usize ) .collect ::<Vec <usize >>() } ;($iter :expr ,{char :$base :expr } ) =>{read_value !($iter ,{chars :$base } ) [0 ] } ;($iter :expr ,chars ) =>{read_value !($iter ,String ) .chars () .collect ::<Vec <char >>() } ;($iter :expr ,char ) =>{read_value !($iter ,chars ) [0 ] } ;($iter :expr ,usize1 ) =>{read_value !($iter ,usize ) -1 } ;($iter :expr ,$t :ty ) =>{$iter .next () .unwrap () .parse ::<$t >() .unwrap () } ;}
macro_rules !input_inner {($iter :expr ) =>{} ;($iter :expr ,) =>{} ;($iter :expr ,mut $var :ident :$t :tt $($r :tt ) *) =>{let mut $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,mut $var :ident $($r :tt ) *) =>{input_inner !{$iter ,mut $var :usize $($r ) *} } ;($iter :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,$var :ident $($r :tt ) *) =>{input_inner !{$iter ,$var :usize $($r ) *} } ;}
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;(iter =$iter :ident ,$($r :tt ) *) =>{let s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut $iter =s .split_whitespace () ;input_inner !{$iter ,$($r ) *} } ;($($r :tt ) *) =>{let s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut iter =s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;}
fn main() {
    input! { n, a: [i64; n] };
    if n % 2 == 0 {
        let mut dp = vec![vec![vec![std::i64::MIN; 2]; 4]; n + 1];
        dp[0][2][0] = 0;
        for i in 0..n {
            let ni = i + 1;
            for j in 1..4 {
                let nj = j - 1;
                for k in 0..2 {
                    dp[ni][nj][0] = std::cmp::max(dp[ni][nj][0], dp[i][j][k]);
                }
            }
            for j in 0..3 {
                let nj = j + 1;
                if dp[i][j][0] > std::i64::MIN {
                    dp[ni][nj][1] = std::cmp::max(dp[ni][nj][1], dp[i][j][0] + a[i]);
                }
            }
        }
        println!("{}", std::cmp::max(dp[n][2][0], dp[n][2][1]));
    } else {
        let mut dp = vec![vec![vec![std::i64::MIN; 2]; 4]; n + 1];
        dp[0][2][0] = 0;
        for i in 0..n {
            let ni = i + 1;
            for j in 1..4 {
                let nj = j - 1;
                for k in 0..2 {
                    dp[ni][nj][0] = std::cmp::max(dp[ni][nj][0], dp[i][j][k]);
                }
            }
            for j in 0..3 {
                let nj = j + 1;
                if dp[i][j][0] > std::i64::MIN {
                    dp[ni][nj][1] = std::cmp::max(dp[ni][nj][1], dp[i][j][0] + a[i]);
                }
            }
        }
        println!("{}", std::cmp::max(dp[n][1][0], dp[n][1][1]));
    }
}


Measured memory_bytes: 57228