eolymp
bolt
Try our new interface for solving problems
Problems

Space Invaders

Space Invaders

Peter wrote his version of the popular game "Space Invaders". The game is as follows. On the ground attack ships of Space Invaders. They lined up in rows at the top of the screen. The player controls a laser gun, which is located at the bottom of the screen in one of the columns. For one action a player can move the gun left or right, or make a shot straight up. If a player makes a shot, it destroys the alien ship coming in that column, in which the gun. \includegraphics{https://static.e-olymp.com/content/3c/3c8d497d752adb5e85c0705fa1ae902263f125b3.jpg} Unlike the original game, Petya embodiment of alien ships are in place and can not shoot, so the player can not lose. Help the Pete destroy all alien ships in a minimum number of operations. \InputFile The first line contains the number \textbf{n} and \textbf{p} - number of columns and column number, which is initially a gun (\textbf{1} ≤ \textbf{n} ≤ \textbf{100}, \textbf{1} ≤ \textbf{p} ≤ \textbf{n}). The second line contains \textbf{n} numbers \textbf{a_1}, \textbf{a_2}, ..., \textbf{a_n}, where \textbf{a_i} - the number of aliens in the \textbf{i}^th column (\textbf{1} ≤ \textbf{a_i} ≤ \textbf{100}). \OutputFile In the output file output a single number - the minimum number of operations required to destroy all the aliens.
Time limit 1 second
Memory limit 64 MiB
Input example #1
5 4
5 3 4 1 2
Output example #1
20
Author Georgiy Korneev, Pavel Mavrin