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 C# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_162
{
    class F
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            long[] array = ReadLongs();
            long[,] dp = new long[n, 3];
            for(int i = 0; i < n; i++)
            {
                for(int j = 0; j < 3; j++)
                {
                    dp[i, j] = long.MinValue;
                }
            }
            if (n % 2 == 0)
            {
                dp[0, 1] = array[0];
                dp[1, 0] = array[1];
            }
            else
            {
                dp[0, 2] = array[0];
                dp[1, 1] = array[1];
                dp[2, 0] = array[2];
            }

            for(int i = 0; i < n; i++)
            {
                for(int j = 0; j < 3; j++)
                {
                    if (dp[i, j] == long.MinValue)
                    {
                        continue;
                    }

                    for(int k = 0; k <= j; k++)
                    {
                        int to = i + 2 + k;
                        if (to >= n)
                        {
                            continue;
                        }

                        dp[to, j - k] = Max(dp[to, j], dp[i, j] + array[to]);
                    }
                }
            }

            long res = long.MinValue;
            if (n % 2 == 0)
            {
                res = Max(dp[n - 1, 0], dp[n - 2, 1]);
            }
            else
            {
                res = Max(dp[n - 1, 0], Max(dp[n - 2, 1], dp[n - 3, 2]));
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}