program am
implicit none
integer::N
integer(16),allocatable,dimension(:)::A
integer(16),allocatable,dimension(:,:)::DP
integer(16)::i
read*,N
allocate(A(N))
read*,A
allocate(DP(N,3))
DP=-huge(i)/2
DP(1,1)=A(1)
DP(2,2)=A(2)
if(N>=3)DP(3,3)=A(3);DP(3,1)=A(1)+A(3)
do i=4,N
    DP(i,1)=DP(i-2,1)+A(i)
    DP(i,2)=max( DP(i-2,2)+A(i), DP(i-3,1)+A(i) )
    DP(i,3)=max( DP(i-2,3)+A(i), DP(i-3,2)+A(i), DP(i-4,1)+A(i) )
end do
if(mod(N,2)==0)then
    print"(i0)",max(DP(N,2),DP(N-1,1))
else
    print"(i0)",max(DP(N,3),DP(N-1,2),DP(N-2,1))
endif
end program am