One of the daunting chores you must face, whether you're 18 or 28, is the task of doing laundry. On one occasion, you find yourself with a massive stack of laundry consisting of
To do this, you may temporarily form a second stack of clothes next to the first one. In one move, you may choose a positive number of clothes off the top of one stack and move it to the other stack, maintaining the same relative order of clothes in the pile you moved (you may not flip or rearrange the pile of clothes in any other way).
Since you would like to get back to filmmaking as soon as possible, please find a sequence of moves that arranges the clothes in non-decreasing order of width back in the original stack. Your solution will be scored based on the number of moves used.
Constraints
Input Specification
The first line contains an integer
The next line contains
Output Specification
On the first line, output an integer
Then, on the
All
Scoring
For each test case:
If any of your Wrong Answer
verdict.
Otherwise, your score
In particular, a full score will be given if your solution uses no more than
Your final score will be the minimum score over all test cases.
Sample Input
4
2 1 1 3
Sample Output
3
1
2
-3
Explanation
Initially, the stacks look like this:
2
1
1
3
After the first move, the stacks look like this:
1
1
3 2
After the second move, the stacks look like this:
1
1
3 2
Finally, after the third move, the stacks look like this:
1
1
2
3
All moves were valid and the clothes are arranged in non-decreasing order of width from top to bottom in the first stack, so this is a valid output.
Since
Comments