Problem F
Gym Aesthetics
The polar bear Sven is competing in the yearly international strongbear competition held in Svalbard. The competition is divided into different events. In the current event, the participants will perform barbell squats with varying weights for each squat.

The order of the required weights of the barbell is given beforehand and the participants will have to load and unload weight plates themselves such that they can squat the required weights.
In one move, a participant can either:
-
Add an available weight to each side of the barbell.
-
Remove the outermost weight from each side of the barbell.
Because of his love of aesthetics, Sven wants the weights to
be in descending order, meaning that if the innermost weight
plate weighs
In order to avoid tiring Sven unnecessarily, we want to calculate the minimum number of moves required for Sven to complete his squats with the required weights in the order given.
The empty barbell (the rod upon which weights are placed)
weighs
Input
The first line of input contains the integers
The second line contains the integers
The third line contains the integers
Output
Print an integer: the minimum number of moves needed to squat the required weights in the given order.
Points
Your solution will be tested on several test case groups. To get the points for a group, it must pass all the test cases in the group.
Group |
Point value |
Constraints |
|
|
|
|
|
|
|
|
No additional constraints. |
Explanation of sample 1
For the first squat, the bar already weighs
For the second squat, Sven can load
For the third squat, Sven can load
Afterwards, he will unload all weights in two moves.
Sample Input 1 | Sample Output 1 |
---|---|
3 5 20 80 120 20 20 10 30 50 |
4 |
Sample Input 2 | Sample Output 2 |
---|---|
2 3 340 400 150 10 40 |
6 |
Sample Input 3 | Sample Output 3 |
---|---|
1 3 100 20 10 10 |
6 |