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 PHP (7.4.4) (judge verdict: Wrong Answer)

<?php
$N = (int)fgets(STDIN);
$A = array_map(function ($n) {
    return (int)$n;
}, explode(' ', fgets(STDIN)));

$sums_at_depth = [];
$depth = (int)floor($N / 2);

$left_tree = new TreeNode();
$left_tree->node = $A[0];
$left_tree->sum = $A[0];
$left_tree->min = $A[0];
$left_tree->depth = 1;
makeTree($left_tree, 0);

$right_tree = new TreeNode();
$right_tree->node = $A[1];
$right_tree->sum = $A[1];
$right_tree->min = $A[1];
$right_tree->depth = 1;
makeTree($right_tree, 1);

$tree = new TreeNode();
$tree->left_tree = $left_tree;
$tree->right_tree = $right_tree;

// var_dump($tree);

echo max($sums_at_depth);

function makeTree(&$tree, $i) {
    global $A, $depth, $sums_at_depth;
    $left_tree = null;
    $right_tree = null;
    $tree_depth = $tree->depth + 1;
    if (isset($A[$i + 2])) {
        $left_tree = new TreeNode();
        $left_tree->node = $A[$i + 2];
        $left_tree->sum = $tree->sum + $A[$i + 2];
        $left_tree->depth = $tree_depth;
        $left_tree->min = min($tree->min, $A[$i + 2]);
        if ($depth === $tree_depth) {
            $sums_at_depth[] = $left_tree->sum;
        }
        if ($tree_depth > $depth) {
            $sums_at_depth[] = $left_tree->sum - $left_tree->min;
        }
        $left_tree->left_tree = makeTree($left_tree, $i + 2);
        $left_tree->right_tree = makeTree($left_tree, $i + 2);
    }

    if (isset($A[$i + 3])) {
        $right_tree = new TreeNode();
        $right_tree->node = $A[$i + 3];
        $right_tree->sum = $tree->sum + $A[$i + 3];
        $right_tree->depth = $tree_depth;
        $right_tree->min = min($tree->min, $A[$i + 3]);
        if ($depth === $tree_depth) {
            $sums_at_depth[] = $right_tree->sum;
        }
        if ($tree_depth > $depth) {
            $sums_at_depth[] = $right_tree->sum - $right_tree->min;
        }
        $right_tree->left_tree = makeTree($right_tree, $i + 3);
        $right_tree->right_tree = makeTree($right_tree, $i + 3);
    }

    $tree->left_tree = $left_tree;
    $tree->right_tree = $right_tree;

    return $tree;
}

class TreeNode
{
    public $node;
    public $sum;
    public $min;
    public $depth;
    public $left_tree;
    public $right_tree;

    /*
    public function __construct($node, $parent_node) {
        $this->node = $node;
        if ($parent_node) {
            $this->sum = $parent_node->sum + $node;
            $this->min = min($node, $parent_node->min);
            $this->depth = $parent_node->depth + 1;
        } else {
            $this->sum = $node;
            $this->min = $node;
            $this->depth = 1;
        }
    }
    */
    /*
    public function __construct($node, $left_tree, $right_tree) {
        $this->node = $node;
        if (!empty($left_tree) && !empty($right_tree)) {
            $this->depth = max($left_tree->depth, $right_tree->depth) + 1;
            if ($left_tree->depth === $right_tree->depth) {
                $this->sum = $node + max($left_tree->sum, $right_tree->sum);
                if ($left_tree->sum === $right_tree->sum) {
                    $this->min = min($node, $left_tree->min, $right_tree->min);
                } elseif ($left_tree->min > $right_tree->min) {
                    $this->min = min($node, $left_tree->min);
                } else {
                    $this->min = min($node, $right_tree->min);
                }
            } elseif ($left_tree->depth > $right_tree->depth) {
                $this->sum = $node + $left_tree->sum;
                $this->min = min($node, $left_tree->min);
            } else {
                $this->sum = $node + $right_tree->sum;
                $this->min = min($node, $right_tree->min);
            }
        } else if (!empty($left_tree)) {
            $this->sum = $node + $left_tree->sum;
            $this->depth = $left_tree->depth + 1;
            $this->min = min($node, $left_tree->min);
        } else {
            $this->sum = $node;
            $this->depth = 1;
            $this->min = $node;
        }
    }*/
}