monopoly

Time limit: 1s
Memory limit: 256MB
Input:
Output:

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 NN cells arranged in a circle. The cells are numbered from 00 to N1N-1, with cells N1N-1 and 00 being adjacent. Each cell has a tax value TiT_i 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 00 and will play KK turns of monopoly. Each turn he rolls two 66-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 33 times in a single turn, then his turn automatically ends (even if the 22 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 NN and KK (1N1 0001 \leq N \leq 1 \ 000), (1K1 0001 \leq K \leq 1 \ 000).
The second line contains NN integers TiT_i (109Ti109-10^9 \le T_i \le 10^9).

Restrictions

  • For tests worth 2020 points, K=1K = 1.
  • For tests worth 3030 more points (1N1001 \leq N \leq 100), (1K1001 \leq K \leq 100).

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 4747. A possible sequence of rolls is the following:

  • Carlo rolls 33 and 33 and moves to cell 66, with tax value 1515. Since the 22 dice values are equal he must throw again.
  • Carlo rolls 44 and 44 and moves to cell 33, with tax value 1212. Since the 22 dice values are equal he must throw again.
  • Carlo rolls 33 and 33 and moves to cell 99, with tax value 2020. He already moved 33 times, so his turn ends, even if the 22 dice values are equal.

In the second sample case the answer is 6-6. A possible sequence of rolls is the following:

  • Carlo rolls 11 and 22 and moves to cell 33, with tax value 6-6. Then his turn ends.

Note that going to the cell 22 is not optimal because the only way to do so is by rolling 11 and 11, but that forces Carlo to move again.

Problem info

ID: 299

Editor: Dap

Author:

Source: IIOT 2022-23 Round I

Tags:

IIOT 2022-23 Round I

Log in or sign up to be able to send submissions!