program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,i,j
    integer(int64), pointer:: oodp(:),odp(:),ndp(:),dmp(:)
    integer(int64), allocatable:: a(:)
    integer(int64),parameter:: nmin=-1000000000

    read*, n
    allocate(oodp(-2:2),odp(-2:2),ndp(-2:n),a(n))
    read*, a(:)

    odp(:) = nmin
    odp(0) = 0
    oodp(:) = nmin
    oodp(0) = 0

    do i=1,n
        ! ndp => null()
        ! allocate(ndp(-2:n))
        do j=(i-1)/2,(i+1)/2
            ndp(j) = max(odp(j), oodp(j-1)+a(i))
        end do
        deallocate(oodp)
        allocate(oodp(i/2-2:i/2+2))
        oodp(i/2-2:i/2+2) = odp(i/2-2:i/2+2)
        deallocate(odp)
        allocate(odp(i/2-2:i/2+3))
        odp(:) = nmin
        odp(i/2-2:i/2+2) = ndp(i/2-2:i/2+2)
    end do

    ! print*, ndp(:)
    print*, ndp(n/2)
end program name