#abc262g. [abc262_g]LIS with Stack

[abc262_g]LIS with Stack

Problem Statement

There is an empty sequence XX and an empty stack SS. Also, you are given an integer sequence A=(a1,ldots,aN)A=(a_1,\\ldots,a_N) of length NN.
For each i=1,ldots,Ni=1,\\ldots,N in this order, Takahashi will do one of the following operations:

  • Move the integer aia_i onto the top of SS.
  • Discard the integer aia_i from AA.

Additionally, Takahashi may do the following operation whenever SS is not empty:

  • Move the integer at the top of SS to the tail of XX.

The score of the final XX is defined as follows.

  • If XX is non-decreasing, i.e. if xileqxi+1x_i \\leq x_{i+1} holds for all integer i(1leqiltX)i(1 \\leq i \\lt |X|), where X=(x1,ldots,xX)X=(x_1,\\ldots,x_{|X|}), then the score is X|X| (where X|X| denotes the number of terms in XX).
  • If XX is not non-decreasing, then the score is 00.

Find the maximum possible score.

Constraints

  • 1leqNleq501 \\leq N \\leq 50
  • 1leqaileq501 \\leq a_i \\leq 50
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN a1a_1 ldots\\ldots aNa_N

Output

Print the answer.


Sample Input 1

7
1 2 3 4 1 2 3

Sample Output 1

5

The following operations make the final XX equal (1,1,2,3,4)(1,1,2,3,4), for a score of 55.

  • Move a1=1a_1=1 onto the top of SS.
  • Move 11 at the top of SS to the tail of XX.
  • Move a2=2a_2=2 onto the top of SS.
  • Discard a3=3a_3=3.
  • Move a4=4a_4=4 onto the top of SS.
  • Move a5=1a_5=1 onto the top of SS.
  • Move 11 at the top of SS to the tail of XX.
  • Move a6=2a_6=2 onto the top of SS.
  • Move 22 at the top of SS to the tail of XX.
  • Move a7=3a_7=3 onto the top of SS.
  • Move 33 at the top of SS to the tail of XX.
  • Move 44 at the top of SS to the tail of XX.

We cannot make the score 66 or greater, so the maximum possible score is 55.


Sample Input 2

10
1 1 1 1 1 1 1 1 1 1

Sample Output 2

10