An Up-Down sequence is defined as a sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. For example, the sequence
Given a sequence of
Input Specification
The first line of input will contain the integer
The second line of input will contain
For 50% of test cases,
Output Specification
Output the length of the longest Up-Down subsequence.
Sample Input 1
4
1 5 3 4
Sample Output 1
4
Sample Input 2
10
1 7 5 10 12 15 10 5 16 8
Sample Output 2
7
Explanation
In sample case 1, the entire sequence is the longest Up-Down subsequence.
In sample case 2, one of the longest Up-Down subsequences is
Comments