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>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef vector<int64_t> vi;
typedef pair< int64_t,int64_t> ii;
typedef vector<pair<int64_t, int64_t> > vp;
typedef vector<pair<int64_t, ii> > vpp;
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define INF 1e9
#define SIZE 200001
#define mod 1000000007
#define int int64_t
#define sz(x)       (int)x.size()
void solve();
int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    solve();
    return 0;
}
void solve()
{
    int n;
    cin>>n;
    int ar[SIZE];
    vi br;
    for(int i=0;i<n;i++)
    {
        cin>>ar[i];
        br.pb(ar[i]);
    }
    sort(br.begin(),br.end());
    int hmm=br[br.size()-1];
//    int ans=0;
//    int back=br[sz(br)-1].s;
//    int last=br[sz(br)-1].f;
//    int prelast=-1;
//    for(int i=sz(br)-1;i>-1;i--)
//    {
//        if(br[i].f==last and br[i].s>prelast)
//        {
//            ans++;
//        }
//        else
//        {
//            if(br[i].s>back)
//            {
//                ans++;
//                prelast=back;
//                back=br[i].s;
//                last=br[i].f;
//            }
//        }
//    }
//    cout<<ans<<"\n";
    int ans=0;
    int tt=ar[0];
    for(int i=0;i<n;i++)
    {
        if(ar[i]<=tt)
        {
            ans++;
        }
    }
    ans+=upper_bound(br.begin(),br.end(),hmm)-lower_bound(br.begin(),br.end(),hmm);
    ans-=1;
    cout<<ans<<"\n";
}