Zonal Computing Olympiad 2014, 30 Nov 2013

In IPL 2025, the amount that each player is paid varies from match to match.  The match fee depends on the quality of opposition, the venue etc.

The match fees for each match in the new season have been announced in advance.  Each team has to enforce a mandatory rotation policy so that no player ever plays three matches in a row during the season.

Nikhil is the captain and chooses the team for each match. He wants to allocate a playing schedule for himself to maximize his earnings through match fees during the season.  

-----Input format-----
Line 1: A single integer N, the number of games in the IPL season.
Line 2: N non-negative integers, where the integer in
position i represents the fee for match i.

-----Output format-----
The output consists of a single non-negative integer, the
maximum amount of money that Nikhil can earn during this IPL
season. 

-----Sample Input 1-----
5 
10 3 5 7 3 

-----Sample Output 1-----
23

(Explanation: 10+3+7+3)

-----Sample Input 2-----
8
3 2 3 2 3 5 1 3

-----Sample Output 2-----
17

(Explanation: 3+3+3+5+3)

-----Test data-----
There is only one subtask worth 100 marks.  In all inputs:

• 1 ≤ N ≤ 2×105
• The fee for each match is between 0 and 104, inclusive.

-----Live evaluation data-----
There are 12 test inputs on the server during the exam.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'from sys import stdin, stdout\nimport math,sys,heapq\nfrom itertools import permutations, combinations\nfrom collections import defaultdict,deque,OrderedDict\nfrom os import path\nimport random\nimport bisect as bi\ndef yes():print(\'YES\')\ndef no():print(\'NO\')\nif (path.exists(\'input.txt\')): \n    #------------------Sublime--------------------------------------#\n    sys.stdin=open(\'input.txt\',\'r\');sys.stdout=open(\'output.txt\',\'w\');\n    def I():return (int(input()))\n    def In():return(map(int,input().split()))\nelse:\n    #------------------PYPY FAst I/o--------------------------------#\n    def I():return (int(stdin.readline()))\n    def In():return(map(int,stdin.readline().split()))\n#sys.setrecursionlimit(1500)\ndef dict(a):\n    d={} \n    for x in a:\n        if d.get(x,-1)!=-1:\n            d[x]+=1\n        else:\n            d[x]=1\n    return d\ndef find_gt(a, x):\n    \'Find leftmost value greater than x\'\n    i = bi.bisect_left(a, x)\n    if i != len(a):\n        return i\n    else:            \n        return -1\ndef main():\n    try:\n        n=I()\n        l=list(In())\n        dp=[[0,0] for x in range(n)]\n        if n==1:\n            print(l[0])\n        elif n==2:\n            print(sum(l))\n        else:\n            dp[2][0]=l[2]+l[1]\n            dp[2][1]=l[2]+l[0]\n            ma=max(dp[1][0],dp[1][1])\n            dp[1][1]=l[1]\n            dp[1][0]=l[1]+l[0]\n            for i in range(3,n):\n                dp[i][0]=l[i]+dp[i-1][1]\n                ma=max(dp[i-2][0],dp[i-2][1],ma)\n                dp[i][1]=ma+l[i]\n            ma=0\n            # for i in range(n):\n            #     print(dp[i][0],end=" ")\n            # print()\n            # for i in range(n):\n            #     print(dp[i][1],end=" ")\n            # print()\n            for i in range(n):\n                ma=max(dp[i][0],ma,dp[i][1])\n            print(ma)\n                \n    except:\n        pass\n        \nM = 998244353\nP = 1000000007\n \ndef __starting_point():\n    #for _ in range(I()):main()\n    for _ in range(1):main()\n__starting_point()'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 16743