spoj#MORENA. Morenas Candy Shop ( Easy )
Morenas Candy Shop ( Easy )
Brunette's Candy Shop ( Easy )
HARDER VERSION: http://www.spoj.com/problems/HILO/
Brunette's is a big candy shop from Little Campina in Paraibas/Brazil. This company is known for making the best candies in the world. Matheus Pheverso is the president of this company and he has a sister called Morena who loves and helps him in running the company. She uses to go the supermarket every day and buy a lot of stuffs to make all the candies. But she's insane and likes to take an alternate path to go to the supermarket.
Given the streets heights, a path is alternate only if the differences between succesive numbers strictly alternate between positive and negative.
Ex:
- Street Heights: {1,3,4,5,2,9,8,10}
- Alternate Paths: {1,3,2,9,8}, {1,4,2,8} {1,5,2,9,8}
Matheus Pheverso is a friendly brother and he would like to know the longest alternate path between the first supermarket and the last supermarket, this means that his sister always starts at the supermarket number 1, and always ends at the last supermarket.
Given the number of supermarkets, and their heights, your task is to print the longest alternate path between the first and the last city.
Input
There is a single positive integer N on the first line of input ( 1 <= N <= 10^6 ) representing the number of supermarkets. In the second line there're N integers Ai representing the heights of each supermarket ( -10^18 <= Ai <= 10^18 ).
Ouput
You have to print the longest alternate path between the first and the last supermarket. The supermarket number 1 is always the first, and the supermarket number N is always the last one.
Example
Input:
5
1 2 3 4 5
Output
2
Input:
8
1 4 2 10 1 9 7 8
Output
8