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 Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.io.*;
import java.util.*;

public class Main {
    private static final int MAX = Integer.MAX_VALUE;
    private static final int MIN = Integer.MIN_VALUE;

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        InputReader.OutputWriter out = new InputReader.OutputWriter(outputStream);
        Scanner scanner = new Scanner(System.in);


        int n = in.nextInt();
        int [] a = new int[n];
        TreeSet<Integer> set = new TreeSet<>();
        for (int i = 0; i < a.length; i++) {
            a[i] = in.nextInt();
        }
        int count = 0;
        for (int i = 0; i < a.length; i++) {
            Integer less = set.lower(a[i]);
            if(less == null) count++;
            set.add(a[i]);
        }
        out.println(count);
        out.flush();
    }
    static boolean isPrime(int n) {
        if(n<2) return false;
        for (int i = 2; i*i <=n ; i++) {
            if(n%i==0) return false;
        }
        return true;
    }

    static int min(char[][] c) {
        int [] row = new int[c.length];
        int [] col = new int[c[0].length];

        for (int i = 0; i < c.length; i++) {
            for (int j = 0; j < c[0].length; j++) {
                if(c[i][j] == '*') {
                    row[i]++;
                    col[j]++;
                }
            }
        }
        int ans = Integer.MAX_VALUE;
        int sum = c.length + c[0].length;
        for (int i = 0; i < c.length; i++) {
            for (int j = 0; j < c[0].length; j++) {
                int count = sum -  row[i] - col[j];
                if(c[i][j] == '.') count--;
                ans = Math.min(ans,count);
            }
        }

        return ans;
    }
    static String solve(String s,String t, String p) {
        int [] main = freq(t);
        int [] sf = freq(s);
        int [] pf = freq(p);

        for (int i = 0; i < sf.length; i++) {
            if(sf[i] > main[i]) {
                return  "NO";
            }
        }
        for (int i = 0; i < sf.length; i++) {
            sf[i]+=pf[i];
        }
        for (int i = 0; i < sf.length; i++) {
            if(sf[i] < main[i]) {
                return "NO";
            }
        }
        int index = -1;
        for (char c : s.toCharArray()) {
            index = t.indexOf(c,index + 1);
            if(index < 0) {
                return "NO";
            }
        }
        return "YES";
    }
    private static int [] freq(String s) {
        int [] f = new int[26];
        for(char c : s.toCharArray()) {
            f[c-'a']++;
        }
        return f;
    }

}

class Point {
    int x;
    int y;
    public Point(int x,int y) {
        this.x = x;
        this.y = y;
    }
}

class Lift {

    int level;
    int time;

    public int getLevel() {
        return level;
    }

    public int getTime() {
        return time;
    }

    public Lift(int level, int time) {
        this.level = level;
        this.time = time;
    }
}

class InputReader extends BufferedReader {
    StringTokenizer tokenizer;

    public InputReader(InputStream inputStream) {
        super(new InputStreamReader(inputStream), 32768);
    }

    public InputReader(String filename) {
        super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return tokenizer.nextToken();
    }

    public Integer nextInt() {
        return Integer.valueOf(next());
    }
    public Long nextLong() {return  Long.valueOf(next());}

    static class OutputWriter extends PrintWriter {
        public OutputWriter(OutputStream outputStream) {
            super(outputStream);
        }

        public OutputWriter(Writer writer) {
            super(writer);
        }

        public OutputWriter(String filename) throws FileNotFoundException {
            super(filename);
        }

        public void close() {
            super.close();
        }
    }
}