Under construction

Still being built. Things may change

Longest Decreasing Subsequence

Interview

Time limit1sMemory limit256 MB

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

Easy3 of 10

Topics
Dynamic programming
Solved
No attempts yet

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 (1≤N≤1,0001 \le N \le 1{,}000).

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

Output

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

Examples5

  1. Example 1

    Input
    6
    10 30 10 20 20 10
    
    Expected output
    3
    
  2. Example 2

    Input
    1
    1000
    
    Expected output
    1
    
  3. Example 3

    Input
    5
    7 7 7 7 7
    
    Expected output
    1
    
  4. Example 4

    Input
    5
    1 2 3 4 5
    
    Expected output
    1
    
  5. Example 5

    Input
    5
    5 4 3 2 1
    
    Expected output
    5