1316: 山峰子序列

Memory Limit:128 MB Time Limit:1.000 S
Judge Style:Text Compare Creator:
Submit:18 Solved:10

Description

现给了一个序列,让找出最长的“山峰子序列”。

何为“山峰序列”:数列中有一个$a_i$,所有$a0 < a1 < a2 <.. < ai-1< ai$且$ai>ai+1>ai+2>..>an-1$

子序列即原序列的一部分,序列元素相对位置不发生改变。

例如,1 2 3 4 5 4 3 1,是山峰序列。其子序列1 3 5 3 1也是山峰序列,序列本身也是本身的子序列,最长山峰子序列长度为8。

1 2 3 4 5 2 3 4不是山峰序列,其子序列1 2 3 4 5 3是山峰序列,最长山峰子序列长度为6。

单调递增或单调递减序列也算山峰序列;单独一个数是长度为1的山峰序列。

Input

输入第一行有一个$n(3<=n<=1000)$;
第二行n个数依次为$ai (0 < ai< 1000000)$。

Output

输出最长山峰子序列的长度。

Sample Input Copy

5
1 2 3 3 1

Sample Output Copy

4

HINT

样例解释:
1、2、3、1是一个山峰子序列,长度为4。

Source/Category