Problem:
Longest Increasing Subsequence

For a given sequence A = {a0, a1, ... , an-1}, find the length of the longest increasing subsequnece (LIS) in A.

An increasing subsequence of A is defined by a subsequence {ai0, ai1, ... , aik} where 0 ≤ i0 < i1 < ... < ik < n and ai0 < ai1 < ... < aik.

Input

n
a0
a1
:
an-1

In the first line, an integer n is given. In the next n lines, elements of A are given.

Output

The length of the longest increasing subsequence of A.

Constraints

1 ≤ n ≤ 100000

0 ≤ ai ≤ 109

Sample Input 1

5
5
1
3
2
4

Sample Output 1

3

Sample Input 2

3
1
1
1

Sample Output 2

1

Solution in C# (judge verdict: Accepted)

using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;

                        namespace AOJ
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Trim().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        public class lower_bound<T> : IComparer<T> where T : IComparable<T>
        {
            public int Compare(T x, T y)
            {
                return 0 <= x.CompareTo(y) ? 1 : -1;
            }
        }
        static int LIS(List<int> A)
        {
            var lst = new List<int>();
            for(var i=0;i<A.Count;++i)
            {
                var num = ~lst.BinarySearch(A[i], new lower_bound<int>());
                if (lst.Count <= num)
                    lst.Add(A[i]);
                else
                    lst[num] = A[i];
            }
            return lst.Count;
        }
        static void Main(string[] args)
        {
            var n = Sarray()[0];
            var A = new List<int>();
            for (var i = 0; i < n; ++i)
            { A.Add((int)Sarray()[0]); }
            WriteLine(LIS(A));
        }
    }
}