Problem:
Score : 500 points

Problem Statement

You are given a sequence with N integers: A = \{ A_1, A_2, \cdots, A_N \}.
For each of these N integers, we will choose a color and paint the integer with that color. Here the following condition must be satisfied:

If A_i and A_j (i < j) are painted with the same color, A_i < A_j.

Find the minimum number of colors required to satisfy the condition.

Constraints

1 \leq N \leq 10^5

0 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1
:
A_N

Output

Print the minimum number of colors required to satisfy the condition.

Sample Input 1

5
2
1
4
5
3

Sample Output 1

2

We can satisfy the condition with two colors by, for example, painting 2 and 3 red and painting 1, 4, and 5 blue.

Sample Input 2

4
0
0
0
0

Sample Output 2

4

We have to paint all the integers with distinct colors.

Solution in Rust (1.15.1) (judge verdict: Accepted)

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
mod vig {
    pub trait S {
        fn binary_search(&mut self, key: i64);
        fn binary_search_index(&mut self, key: i64) -> i64;
    }
    impl S for Vec<i64> {
        fn binary_search(&mut self, key: i64) {
            let mut ng: i64 = -1;
            let mut ok: i64 = self.len() as i64;
            loop {
                if (ok - ng).abs() <= 1 {
                    break;
                }
                let mid = (ok + ng) / 2;
                if self[mid as usize] > key {
                    ok = mid;
                } else {
                    ng = mid;
                }
            }
            self[ok as usize] = key;
        }
        fn binary_search_index(&mut self, key: i64) -> i64 {
            let mut ng: i64 = -1;
            let mut ok: i64 = self.len() as i64;
            loop {
                if (ok - ng).abs() <= 1 {
                    break;
                }
                let mid = (ok + ng) / 2;
                if self[mid as usize] >= key {
                    ok = mid;
                } else {
                    ng = mid;
                }
            }
            ok
        }
    }
}

fn main() {
    input!{
        n:usize,
        mut a: [i64;n]
    }
    // println!("{:?}", a);
    let mut dp = vec![1<<50;n];
    a.reverse();
    for i in 0..n {
        vig::S::binary_search(&mut dp, a[i]);
    }
    // println!("{:?}", dp);
    let ans = vig::S::binary_search_index(&mut dp, 1<<50);
    println!("{}", ans);
}