Longest Increasing Subsequence

No attempts yetTime limit1sMemory limit256 MB

Problem

Given a sequence AA, write a program that finds the length of its longest increasing subsequence.

A subsequence of AA is what remains after deleting zero or more elements and keeping the rest in their original order. An increasing subsequence is one whose values grow strictly from left to right, so two elements with the same value cannot both be chosen.

For example, when A=(10,20,10,30,20,50)A = (10, 20, 10, 30, 20, 50), the longest increasing subsequence is 10, 20, 30, 50, and its length is 4.

Input

The first line contains the size NN of the sequence AA (1N10001 \le N \le 1000).

The second line contains A1,A2,,ANA_1, A_2, \dots, A_N, separated by spaces (1Ai10001 \le A_i \le 1000).

Output

Print the length of the longest increasing subsequence of AA on the first line.