Skip to content
UPEEC

Longest Increasing Subsequence

Hard#dynamic-programming#binary-search· solved by 0 · time limit 2.0 s

Find the length of the longest strictly increasing subsequence. O(n2)O(n^2) DP works for small nn; the patience-sorting trick with binary search is O(nlog⁡n)O(n \log n).

Input

nn, then nn integers.

Output

The LIS length.

Constraints

1≤n≤1051 \le n \le 10^5

Sample 1

Input

8
10 9 2 5 3 7 101 18

Output

4

Sample 2

Input

3
7 7 7

Output

1

Sign in or join free to run and submit your solution.