Board Game

No attempts yetTime limit1sMemory limit128 MB

Problem

On another rainy day two friends are stuck indoors, so they invent a game.

On a sheet of paper they draw nn fields. Each field carries two numbers: its index (a distinct integer from 11 to nn) and its value (an integer between 1000-1000 and 10001000). A pawn starts on field 11. On every move the player rolls a six-sided die (its faces are numbered 11 through 66) and advances the pawn forward by the number rolled. The game ends the instant the pawn lands on field nn. The player's score is the sum of the values of every field the pawn stood on, counting both the starting field 11 and the final field nn.

Because the players may pick any rolls they like, one game corresponds to a sequence of forward steps, each between 11 and 66 fields, that starts on field 11 and stops exactly on field nn. Compute the largest score achievable over all such sequences.

Input

The first line contains an integer nn (1n1061 \le n \le 10^6), the number of fields. The second line contains nn integers w1,w2,,wnw_1, w_2, \dots, w_n (1000wi1000-1000 \le w_i \le 1000), where wiw_i is the value of field ii.

Output

Print one integer: the maximum score that can be obtained on the given board.