#BS0000209. Dãy Wavio dài nhất (Wavio Sequence)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Dãy Wavio dài nhất (Wavio Sequence)
Wavio Sequence
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
An integer sequence is given. A Wavio sequence has odd length for . Its values satisfy and . Both arms have the same length including their shared peak. A single element is valid when . Find the maximum length of a Wavio subsequence, retaining the original order but not necessarily consecutive positions.
Input
The first line contains the sequence length . The second line contains integers in their original order.
Output
Print one integer: the maximum Wavio subsequence length.
Subtasks
- Subtask 1 (20 points): ; ().
- Subtask 2 (30 points): ; ().
- Subtask 3 (50 points): ; ().
Examples
Input
10
1 2 3 4 5 4 3 2 1 10
Output
9
Explanation
The first nine of the ten numbers form . The peak is 5; four elements precede it in increasing order and four follow in decreasing order. Its length is 9. All Wavio lengths are odd, and only ten elements exist, so no longer Wavio subsequence is possible.