Box Packing

Given box sizes in order, find the longest subsequence where each box is strictly smaller than the next, counting boxes in the pile.

Medium4Dynamic programmingBinary searchArrayGreedyInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

Yeongseon works part time at Namgyu's company, which is known for oversized packaging. Her job is to pack boxes inside one another.

The boxes stand in a row. An earlier box goes inside a later box only if the earlier box is smaller than the later one. A later box never goes inside an earlier box.

You are given the box sizes in order from the front. Following that rule, nest boxes one inside another and report the largest number of boxes that can end up in a single nested pile. The outermost box counts too.

Input

The first line contains the number of boxes nn (1n50001 \le n \le 5000).

The second line contains the box sizes A1,A2,,AnA_1, A_2, \dots, A_n in order from the front (1Ai1000001 \le A_i \le 100000).

Output

Print the largest number of boxes that can be nested together under the rule.