#P7625. [COCI 2011/2012 #1] JABUKE

[COCI 2011/2012 #1] JABUKE

Description

Mirko has recently become obsessed with a video game.

The game screen is divided into NN columns. At the bottom of the screen, there is a ship that is MM columns wide. In the game, the player can move the ship left and right, but the ship must always stay completely inside the screen. Initially, the ship occupies the leftmost MM columns of the screen.

Apples will fall from the top of the screen. Each apple starts falling straight down from one of the NN columns at the top. When the current apple reaches the bottom of the screen, the next apple starts falling.

If, when an apple reaches the bottom, the ship covers the column where the apple is, we say the apple is picked up. Your task is to minimize the distance the ship moves, while picking up all the apples.

Input Format

The first line contains two integers N,MN, M separated by spaces.

The second line contains an integer JJ, indicating the number of apples that will fall.

The next JJ lines: the ii-th line contains one integer, indicating from which column the ii-th apple will start falling.

Output Format

Output one integer on a single line, the minimum distance the ship needs to move.

5 1
3
1
5
3
6
5 2
3
1
5
3
4

Hint

Constraints

For 100%100\% of the testdata, 1M<N101 \le M < N \le 10, 1J201 \le J \le 20.

Explanation

The score for this problem follows the original COCI settings, with a full score of 5050.

Translated from COCI2011-2012 CONTEST #1 T1 JABUKE.

Translated by ChatGPT 5