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 Lua (LuaJIT 2.1.0) (judge verdict: Wrong Answer)

local mmi, mma = math.min, math.max
local bls, brs = bit.lshift, bit.rshift
local mfl, mce = math.floor, math.ceil
local n = io.read("*n")
local t = {}
for i = 1, n do
  t[i] = io.read("*n")
end
if n % 2 == 0 then
  local hn = brs(n, 1)
  local p1, p2 = {t[1]}, {t[2]}
  for i = 2, hn do
    p1[i] = p1[i - 1] + t[2 * i - 1]
    p2[i] = p2[i - 1] + t[2 * i]
  end
  local ret = mma(p1[hn], p2[hn])
  for i = 1, hn - 1 do
    local cand = p1[i] + p2[hn] - p2[i]
    ret = mma(ret, cand)
  end
  if ret < 100000000000000 then
    print(ret)
  else
    print("100000000000000")
  end
else
  -- use0, nouse0, use1, nouse1, use2, nouse2
  local dp = {t[1], false, false, 0, false, false}
  for i = 2, n do
    local dst = {false, false, false, false, false, false}
    if dp[1] then
      dst[2] = dp[1]
    end
    if dp[2] then
      dst[1] = dp[2] + t[i]
      dst[4] = dp[2]
    end
    if dp[3] then
      if dst[4] then
        dst[4] = mma(dst[4], dp[3])
      else
        dst[4] = dp[3]
      end
    end
    if dp[4] then
      dst[3] = dp[4] + t[i]
      dst[6] = dp[4]
    end
    if dp[5] then
      if dst[6] then
        dst[6] = mma(dst[6], dp[5])
      else
        dst[6] = dp[5]
      end
    end
    if dp[6] then
      dst[5] = dp[6] + t[i]
    end
    for j = 1, 6 do
      dp[j] = dst[j]
      -- io.write(tostring(dp[j]))
      -- io.write(j == 6 and "\n" or " ")
    end
  end
  if not dp[5] then
    print(dp[6])
  elseif not dp[6] then
    print(dp[5])
  else
    print(mma(dp[5], dp[6]))
  end
end