Problem:
Longest Increasing Subsequence

For a given sequence A = {a0, a1, ... , an-1}, find the length of the longest increasing subsequnece (LIS) in A.

An increasing subsequence of A is defined by a subsequence {ai0, ai1, ... , aik} where 0 ≤ i0 < i1 < ... < ik < n and ai0 < ai1 < ... < aik.

Input

n
a0
a1
:
an-1

In the first line, an integer n is given. In the next n lines, elements of A are given.

Output

The length of the longest increasing subsequence of A.

Constraints

1 ≤ n ≤ 100000

0 ≤ ai ≤ 109

Sample Input 1

5
5
1
3
2
4

Sample Output 1

3

Sample Input 2

3
1
1
1

Sample Output 2

1

Solution in Rust (judge verdict: Accepted)

pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn insert(dp: &mut Vec<i32>, l: usize, r: usize, a: i32) {
    if l + 1 >= r {
        dp[r] = a;
    } else {
        let m = (l + r) / 2;
        if a <= dp[m] {
            insert(dp, l, m, a);
        } else {
            insert(dp, m, r, a);
        }
    }
}

fn l(dp: &Vec<i32>) -> usize {
    let mut ans = 0;
    for i in 0..dp.len() {
        if dp[i] == 1000000001 {
            ans = i - 1;
            break;
        }
    }
    ans
}

fn main() {
    let n: usize = read();
    let a: Vec<i32> = read_col(n);
    let mut dp: Vec<i32> = vec![1000000001; n + 2];
    dp[0] = -1;

    for i in 0..n {
        insert(&mut dp, 0, n + 1, a[i]);
    }

    println!("{}", l(&dp));
}