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 C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t;
int cev;
string s;
multiset<int> st;
vector<int> v;

int main(void){
	scanf("%d",&n);
	FOR{
		scanf("%d",&a[i]);
	}
	//~ st.insert(inf)
	st.insert(a[1]);
	for(int i=2;i<=n;i++){
		//~ cout<<st.size()<<endl;
		auto it=st.end();
		it--;
		if(*it>=a[i]){st.insert(a[i]);continue;}
		it=st.lower_bound(a[i]);
		//~ auto it1=st.upper_bound(a[i]);
		//~ if(st.size()==1){
			//~ it--;
			//~ if(it==st.end()){
				//~ it--;
				//~ st.erase(it);
				//~ st.insert(*it);
				//~ continue;
			//~ }
			//~ else{
				//~ st.insert(a[i]);continue;
			//~ }
		//~ }
		it--;
		//~ if(it==){st.insert(a[i]);continue;}
		//~ if(*it>=a[i]){st.insert(a[i]);continue;}
		
		st.erase(it);
		st.insert(*it);
	}
	printf("%d\n",st.size());
	return 0;
}