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: Time Limit Exceeded)

pub struct Poper<'a> {
	iter: std::str::SplitWhitespace<'a>,
}

impl<'a> Poper<'a> {
	pub fn new(iter: std::str::SplitWhitespace) -> Poper {
		Poper { iter: iter }
	}
	pub fn read<T: std::str::FromStr>(&mut self) -> T
	where
		<T as std::str::FromStr>::Err: std::fmt::Debug,
	{
		self.iter.next().unwrap().parse().unwrap()
	}
}

// https://docs.rs/sorted-vec/0.3.1/src/sorted_vec/lib.rs.html#1-209


/// Reverse sorted vector
#[derive(Clone, Debug, PartialEq)]
pub struct ReverseSortedVec<T: Ord> {
	vec: Vec<T>,
}


impl<T: Ord> ReverseSortedVec<T> {
	#[inline]
	pub fn new() -> Self {
		ReverseSortedVec { vec: Vec::new() }
	}
	#[inline]
	pub fn with_capacity(capacity: usize) -> Self {
		ReverseSortedVec {
			vec: Vec::with_capacity(capacity),
		}
	}
	/// Uses `sort_by()` to sort in place.
	#[inline]
	pub fn from_unsorted(mut vec: Vec<T>) -> Self {
		vec.sort_by(|x, y| x.cmp(y).reverse());
		ReverseSortedVec { vec: vec }
	}
	/// Insert an element into (reverse) sorted position, returning the order
	/// index at which it was placed.
	///
	/// If the element was already present, the order index is returned as an
	/// `Err`, otherwise it is returned with `Ok`.
	pub fn insert(&mut self, element: T) -> Result<usize, usize> {
		let p = &self.vec[..].binary_search_by(|other_element| other_element.cmp(&element).reverse());
		match *p {
			Ok(insert_at) => {
				self.vec.insert(insert_at, element);
				Err(insert_at)
			}
			Err(insert_at) => {
				self.vec.insert(insert_at, element);
				Ok(insert_at)
			}
		}
	}
	#[inline]
	pub fn remove_item(&mut self, item: &T) -> Option<T> {
		match self
			.vec
			.binary_search_by(|other_item| other_item.cmp(&item).reverse())
		{
			Ok(remove_at) => Some(self.vec.remove(remove_at)),
			Err(_) => None,
		}
	}
	/// Panics if index is out of bounds
	#[inline]
	pub fn remove_index(&mut self, index: usize) -> T {
		self.vec.remove(index)
	}
	#[inline]
	pub fn binary_search(&self, x: &T) -> Result<usize, usize> {
		self.vec.binary_search_by(|y| y.cmp(&x).reverse())
	}
	#[inline]
	pub fn pop(&mut self) -> Option<T> {
		self.vec.pop()
	}
	#[inline]
	pub fn clear(&mut self) {
		self.vec.clear()
	}
	pub fn dedup(&mut self) {
		self.vec.dedup();
	}
}
impl<T: Ord> Default for ReverseSortedVec<T> {
	fn default() -> Self {
		Self::new()
	}
}
impl<T: Ord> std::ops::Deref for ReverseSortedVec<T> {
	type Target = Vec<T>;
	fn deref(&self) -> &Vec<T> {
		&self.vec
	}
}

fn main() {
	let input = {
		use std::io::Read;
		let mut s = String::new();
		std::io::stdin().read_to_string(&mut s).unwrap();
		s
	};
	let mut iter = Poper::new(input.split_whitespace());

	let n: usize = iter.read();
	let a_list: Vec<u64> = (0..n).into_iter().map(|_| iter.read()).collect();

	let mut x_list: ReverseSortedVec<u64> = ReverseSortedVec::new();

	for a in a_list {
		let t = x_list
			.iter()
			.enumerate()
			.map(|(i, &n)| (i, n))
			.find(|&(_, n)| n < a);
		match t {
			Some((i, _)) => {
				x_list.remove_index(i);
				let _ = x_list.insert(a);
			}
			None => {
				let _ = x_list.insert(a);
			}
		}
	}

	println!("{}", x_list.len());

}