Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/dp-eng-uzun-osuvchi-qism-ketma-ketlik

Longest increasing subsequence

Hard 1000 ms 128 MB 67%
Share

A positive integer $n$ and $n$ integers $a_{1}, a_{2}, \dots, a_{n}$ are given. Choose some of them without changing their order (not necessarily consecutive) so that the chosen ones are strictly increasing. Find the largest number of numbers that can be chosen.

The longest strictly increasing subsequence chosen from the array

Input

The first line contains a positive integer $n$. The second line contains $n$ space-separated integers $a_{i}$.

Output

One integer — the length of the longest strictly increasing subsequence.

Note

$1 \le n \le 2 * 10^{5}$
$-10^{9} \le a_{i} \le 10^{9}$

Examples

Input #1
8
10 9 2 5 3 7 101 18
Output #1
4
Input #2
4
4 4 4 4
Output #2
1

Sign in to submit a solution

Signing up is free and takes a minute.