atcoder#ABC262G. [ABC262G] LIS with Stack
[ABC262G] LIS with Stack
Score : points
Problem Statement
There is an empty sequence and an empty stack . Also, you are given an integer sequence of length . For each in this order, Takahashi will do one of the following operations:
- Move the integer onto the top of .
- Discard the integer from .
Additionally, Takahashi may do the following operation whenever is not empty:
- Move the integer at the top of to the tail of .
The score of the final is defined as follows.
- If is non-decreasing, i.e. if holds for all integer , where , then the score is (where denotes the number of terms in ).
- If is not non-decreasing, then the score is .
Find the maximum possible score.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
7
1 2 3 4 1 2 3
5
The following operations make the final equal , for a score of .
- Move onto the top of .
- Move at the top of to the tail of .
- Move onto the top of .
- Discard .
- Move onto the top of .
- Move onto the top of .
- Move at the top of to the tail of .
- Move onto the top of .
- Move at the top of to the tail of .
- Move onto the top of .
- Move at the top of to the tail of .
- Move at the top of to the tail of .
We cannot make the score or greater, so the maximum possible score is .
10
1 1 1 1 1 1 1 1 1 1
10