시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB73312547.170%

문제

You are given an integer sequence $A = (a_1, a_2, \dots , a_N)$. Find the length of the longest sequence $B = (b_1, b_2, \dots , b_N)$ which satisfies the following two conditions:

  • $B$ is a subsequence of $A$
  • $b_i < b_{i+2}$ for all $i$ ($1 ≤ i ≤ M-2$)

A subsequence of a sequence is a sequence obtained by removing zero or more elements from the original sequence and then concatenating the remaining elements without changing the order.

입력

$N$

$a_1$ $a_2$ $\dots$ $a_N$

The first line consists of an integer $N$ between $1$ and $5\,000$, inclusive. This represents the number of elements in $A$.

The second line consists of $N$ integers between $1$ and $N$, inclusive. For each $i$ ($1 ≤ i ≤ N $), $a_i$ represents the $i$-th element of $A$.

출력

Print the answer in a line.

예제 입력 1

7
1 5 7 6 3 4 2

예제 출력 1

4

예제 입력 2

7
6 2 1 4 7 5 3

예제 출력 2

5

예제 입력 3

2
2 1

예제 출력 3

2

예제 입력 4

6
1 1 2 2 3 3

예제 출력 4

6