- Time limit: 1.00 s
- Memory limit: 128 MB
Given a sequence of integers , find the length of the longest zigzagging subsequence in it. Sequence is zigzagging if for every : or .
Input
The first line of the input contains integer , the length of the sequence. Next line contains integers, .
Output
Output the maximum length of a zigzagging subsequence in .
Constraints
Example
Input:
8 5 3 1 2 3 4 2 2
Output:
4
An example of a zigzagging subsequence of length 4 is 3 1 3 2
.