Andy is getting bored in English class, and so he decides to pull out his laptop and start playing his favourite game!
In this game, Andy controls a stationary robot that stands in the center of a line of
Andy must use the robot's arms to take
The line of books is very unstable! Define the instability of the line as the minimum number of increasing and decreasing subsections of books. For example, the instability of the line
The game does not care about how many times swaps are made. It only cares about the final instability. Can you find the minimum possible instability that Andy should strive for?
Python users are recommended to use PyPy over CPython. There is a significant performance increase.
Input Specification
The first line will contain the integer
The second line will contain
Output Specification
Output the minimum instability of the line of books, given that you can perform an infinite number of swaps between indices
Constraints
Subtask 1 [10%]
Subtask 2 [50%]
Subtask 3 [40%]
No additional constraints.
Sample Input 1
4
4 1 3 2
Sample Output 1
2
Explanation For Sample 1
One way to achieve the minimum instability is to perform the swap once on index
Sample Input 2
8
1 3 8 7 5 2 6 4
Sample Output 2
3
Comments