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)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use std::collections::BTreeMap;
use std::ops::Bound::*;
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [isize; n],
    }

    let mut set: BTreeMap<isize, usize> = BTreeMap::new();
    for a_i in a {
        // let mut v = VecDeque::new();
        // v.push_front(a_i);
        // set.range((Unbounded, (v)));

        let range = set.range((Unbounded, Excluded(a_i)));
        let max = range.rev().next().map(|(x, _)| *x);
        if let Some(max) = max {
            let max_ref = set.get_mut(&max).unwrap();
            *max_ref -= 1;
            if *max_ref == 0 {
                set.remove(&max);
            }

            let entry = set.entry(a_i).or_insert(0);
            *entry += 1;
        } else {
            let entry = set.entry(a_i).or_insert(0);
            *entry += 1;
        }
    }

    let ans: usize = set.iter().map(|(k, v)| v).sum();
    println!("{}", ans);
}
*/

fn main() {
    let exe = "/tmp/bin582CC6E3";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";