#P1407D. Discrete Centrifugal Jumps
Discrete Centrifugal Jumps
No submission language available for this problem.
Description
There are beautiful skyscrapers in New York, the height of the -th one is . Today some villains have set on fire first of them, and now the only safety building is -th skyscraper.
Let's call a jump from -th skyscraper to -th () discrete, if all skyscrapers between are strictly lower or higher than both of them. Formally, jump is discrete, if and one of the following conditions satisfied:
- .
At the moment, Vasya is staying on the first skyscraper and wants to live a little longer, so his goal is to reach -th skyscraper with minimal count of discrete jumps. Help him with calcualting this number.
The first line contains a single integer () — total amount of skyscrapers.
The second line contains integers () — heights of skyscrapers.
Print single number — minimal amount of discrete jumps. We can show that an answer always exists.
Input
The first line contains a single integer () — total amount of skyscrapers.
The second line contains integers () — heights of skyscrapers.
Output
Print single number — minimal amount of discrete jumps. We can show that an answer always exists.
Samples
Note
In the first testcase, Vasya can jump in the following way: .
In the second and third testcases, we can reach last skyscraper in one jump.
Sequence of jumps in the fourth testcase: .