Longest Decreasing Subsequence

Find the length of the longest strictly decreasing subsequence of the given sequence.

Easy3Dynamic programmingInterviewNo attempts yetTime limit1sMemory limit256 MB

Problem

A sequence AA is given. Write a program that finds the length of the longest decreasing subsequence of AA.

A subsequence is formed by picking one or more elements of AA and keeping their original order. A decreasing subsequence is one in which every element is strictly greater than the element right after it.

For example, if A={10,30,10,20,20,10}A = \{10, 30, 10, 20, 20, 10\}, the longest decreasing subsequence is {30,20,10}\{30, 20, 10\} and its length is 3.

Input

The first line contains the size NN of the sequence AA (1N1,0001 \le N \le 1{,}000).

The second line contains A1,A2,,ANA_1, A_2, \dots, A_N separated by spaces (1Ai1,0001 \le A_i \le 1{,}000).

Output

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