402339: GYM100733 D Little thief Shi

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

D. Little thief Shitime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Shi realized that he was almost out of money, even renting Shitalian lands. Shi was walking on a street, while thinking of a way to recover his fortune. In his way, he passed by a jewelry store. The owner of the store was a Shitalian man suspected of committing minor crimes, as cutting bushes and stealing old bread. Shi hated people who cut bushes, so he decided to rob the store to take revenge and make some money.

The store has n jewels, put in a row, one after another. Each jewel i can be sold in the black market for a value vi. Shi wants to steal as much as possible, but if he steals everything, the owner will notice, so if Shi steals the i-th jewel, he can't steal the i - 1-th, i - 2-th, i + 1-th and i + 2-th jewels.

Using the best strategy possible, calculate the sum of the jewels values that Shi can obtain.

Input

The input begins with an integer n (1 ≤ n ≤ 106), indicating the number of jewels in the store. The next line contains n integers. The i-th integer vi (1 ≤ vi ≤ 103) is the value of the i-th jewel.

Output

Output the maximum value that Shi can get.

ExamplesInput
4
1 2 3 4
Output
5
Input
6
1 2 4 0 3 0
Output
5
Input
7
2 10 12 24 29 69 0
Output
81
Input
10
15 1 6 3 7 100 9 15 80 95
Output
210

Source/Category

加入题单

上一题 下一题 算法标签: