Under construction

Still being built. Things may change

Board Game

Interview

Time limit1sMemory limit128 MB

Summary
Starting on field 1, move forward 1 to 6 fields per step to reach field n while collecting the largest possible sum of visited values.
Level

Easy3 of 10

Topics
Dynamic programming
Solved
No attempts yet

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 (1≤n≤1061 \le n \le 10^6), the number of fields. The second line contains nn integers w1,w2,…,wnw_1, w_2, \dots, w_n (−1000≤wi≤1000-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.

Examples1

  1. Example 1

    Input
    4
    1 2 -1 1
    
    Expected output
    4