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)

#include <bits/stdc++.h>
//#pragma GCC optimize(2)

using namespace std;

#define LL long long
#define Re register
#define U unsigned
#define forn(i,a,b) for(int i = a;i <= b;++i)
#define nfor(i,a,b) for(int i = a;i >= b;--i)
#define CLR(i,a) memset(i,a,sizeof(i))
#define BR printf("--------------------\n")
#define pb push_back
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const double PI=atan(1.)*4.;
const int maxn=1e6+5;
const int inf = 0x3f3f3f3f;
const int mod=1e9+7;
const double e=2.71828182845904523536;
int dir[4][2]={1,0,0,1,-1,0,0,-1};
int a[maxn];

int merge_sort(int l,int r)
{
    if(l>=r)
        return r;
    int m=l+(r-l)/2;
    int rl=merge_sort(l,m);
    int rr=merge_sort(m+1,r);
    int res;
    if(a[rr]<=a[rl])
        res=rr;
    else
        res=rl;
    return res;
}

int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
   	cout.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int ans=0;
    int res=n;
    while(res>=1)
    {
        //int t=res;
        //cout<<"aaaaaa:"<<merge_sort(1,res)<<endl;
        res=merge_sort(1,res)-1;
        ans++;
        //cout<<t<<"---"<<res<<"---"<<t-res<<endl;
    }
    cout<<ans;
	return 0;
}