#c22506. 最长上升子序列II

最长上升子序列II

Longest Increasing Subsequence II

Problem Description

Given an array a1,a2,…,ana_1, a_2, \dots, a_n of length nn, find the length of its longest increasing subsequence. That is, we want the largest mm and array p1,p2,…,pmp_1, p_2, \dots, p_m such that 1≤p1<p2<⋯<pm≤n1 \leq p_1 < p_2 < \dots < p_m \leq n and ap1<ap2<⋯<apma_{p_1} < a_{p_2} < \dots < a_{p_m}.

Input Format

The first line contains an integer nn.

The next line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n.

Output Format

One number: the answer.

Sample Input

6
3 7 4 2 6 8

Sample Output

4

Constraints

All data guarantee 1≤n≤100000,1≤ai≤1091 \leq n \leq 100000, 1 \leq a_i \leq 10^9.