— Billy, you are wasting your life on computer games!
— That's OK, Mom, I have three lives left!
In the Great Battle to save everything good in this world, heroes are fighting a horde of monsters. The combatants are standing in a circle, in a given order. The -th hero is followed on the circle by monsters (such that ).
Beginning with the first hero, combatants take turns striking with their swords. A hero may strike any monster, while a monster may strike any hero (anywhere on the circle). A monster that takes strikes is destroyed. Heroes are invincible.
Task
The heroes are fighting for glory and wish to receive as few strikes as possible. What is the least number of strikes that the heroes must receive before destroying all the monsters?
Input data
The first line of input will contain the integers and , separated by a space.
The second line will contain space-separated integers, , , ..., .
Output data
Output a single integer, the minimum number of strikes that the heroes can receive.
Constraints and clarifications
- for
- The answer is guaranteed not to exceed .
# | Points | Constraints |
---|---|---|
0 | 0 | Examples |
1 | 7 | , , |
2 | 11 | , , |
3 | 15 | |
4 | 17 | |
5 | 19 | |
6 | 31 | No additional constraints |
Example 1
stdin
3 1
0 3 3
stdout
3
Explanation
There are heroes and monsters with life each. The initial order is HHMMMHMMM
(where H
is a hero and M
is a monster). The first two heroes destroy the first two monsters. The third monster strikes. The third hero destroys the fourth monster. The last two monsters strike. The circle is now HHMHMM
. The second time around, every hero destroys one monster and the heroes receive no further strikes.
Example 2
stdin
3 2
0 3 3
stdout
10