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.
# cook your dish here
no = int(input())
alls = list(input().split())
dp = [0]*(no+1)
if(no==1):
	dp[1]=alls[0]
	print(dp[1])
elif(no==2):
	dp[2] = int(alls[1])+int(alls[0])
	print(dp[2])
elif(no>=3):
	dp[1]= int(alls[0])
	dp[2] = int(alls[1])+int(alls[0])
	a = int(alls[0])+int(alls[1])		
	b = int(alls[1])+int(alls[2])
	c = int(alls[0])+int(alls[2])		
	dp[3] = max(a,b,c)
	for x in range(4,(no+1)):
		d = int(dp[x-2]) + int(alls[x-1])
		e = int(dp[x-1])
		f = int(dp[x-3]+int(alls[x-2])+int(alls[x-1]))
		dp[x] = max(d,e,f)
	print(dp[no])

# cook your dish here
no = int(input())
alls = list(input().split())
dp = [0]*(no+1)
if(no==1):
	dp[1]=alls[0]
	print(dp[1])
elif(no==2):
	dp[2] = int(alls[1])+int(alls[0])
	print(dp[2])
elif(no>=3):
	dp[1]= int(alls[0])
	dp[2] = int(alls[1])+int(alls[0])
	a = int(alls[0])+int(alls[1])		
	b = int(alls[1])+int(alls[2])
	c = int(alls[0])+int(alls[2])		
	dp[3] = max(a,b,c)
	for x in range(4,(no+1)):
		d = int(dp[x-2]) + int(alls[x-1])
		e = int(dp[x-1])
		f = int(dp[x-3]+int(alls[x-2])+int(alls[x-1]))
		dp[x] = max(d,e,f)
	print(dp[no])
