Task
You find an old game of monopoly in your attic and you decide to play it against Carlo. You don't like to lose, so you decide to use your magic dice to cheat.
The game is played on a board, made of cells arranged in a circle. The cells are numbered from to , with cells and being adjacent. Each cell has a tax value associated with it. Every time a player lands on a cell, he has to pay the tax value of that cell (the tax value can be negative, meaning that the player receives money).
Carlo starts on cell and will play turns of monopoly. Each turn he rolls two -sided dice and moves forward by the sum of the two values. He then pays the tax value of the cell he lands on. If the two dice value are equal, after moving and paying, he must continue and roll the dice again.
Carlo can move at most times in a single turn, then his turn automatically ends (even if the dice values are equal). You can control the outcomes of all the dice rolls, maximize the amount of money Carlo loses during the game.
Input
The first line contains the integers and (), ().
The second line contains integers ().
Restrictions
- For tests worth points, .
- For tests worth more points (), ().
Output
You need to write a single line with an integer: the amount of money Carlo loses during the game.
Example 1
stdin
11 1
0 5 4 12 6 3 15 7 2 20 5
stdout
47
Example 2
stdin
12 1
-10 -20 -4 -6 -15 -20 -20 -20 -20 -20 -20 -20
stdout
-6
Example 3
stdin
2 2
999999999 1000000000
stdout
5999999998
Explanation
In the first sample case the answer is . A possible sequence of rolls is the following:
- Carlo rolls and and moves to cell , with tax value . Since the dice values are equal he must throw again.
- Carlo rolls and and moves to cell , with tax value . Since the dice values are equal he must throw again.
- Carlo rolls and and moves to cell , with tax value . He already moved times, so his turn ends, even if the dice values are equal.
In the second sample case the answer is . A possible sequence of rolls is the following:
- Carlo rolls and and moves to cell , with tax value . Then his turn ends.
Note that going to the cell is not optimal because the only way to do so is by rolling and , but that forces Carlo to move again.