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

/**
	������������ Author : Avi J Patel ������������
	������������ University : DA-IICT ������������
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair 
#define mt make_tuple
#define N 100000
#define ff first
#define ss second
#define si size()
#define MOD 1000000007
#define large 10000000000000001

#define For(i,m,n) for(long long i=m;i<n;i++)
#define st(x) sort(x.begin(),x.end())
#define re(x,i) reverse(x.begin()+i,x.end())
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 
/*void calc()
{
	for(int i=0;i<2005;i++)
	{
		a[i][0]=1;
		a[i][i]=1;
		for(int j=1;j<i;j++)
		{
			a[i][j]=(a[i-1][j-1]+a[i-1][j])%MOD;	
		}
	}
}*/
int main()
{
	int n;
	cin>>n;
	vector<ll> a(n);
	int temp=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	//vector<ll> t;
	int cnt=0;
	for(int i=n-1;i>=1;i--)
	{
		if(a[i]>a[i-1])
		{
			temp=1;
			break;
		}
	}
	if(temp==0)
	{
		cout<<n;
		return 0;
	}
	int r=a[n-1];
	temp=1;
	for(int i=n-2;i>=0;i--)
	{
		if(a[i]>r)
		{
			r=a[i];
			temp++;
		}
	}
	if(temp>50000)
	{
		cout<<temp;
		return 0;
	}
	while(1)
	{
		ll cur=a[0];
		int len=0;
		for(int i=1;i<n;i++)
		{
			if(a[i]>cur)
			{
				cur=a[i];
			}
			else
			{
				a[len]=a[i];
				len++;
			}
		}
		cnt++;
		n=len;
		if(len==0)
		break;
	}
	cout<<cnt;
	return 0;
}