Score : $600$ points
There is an empty sequence $X$ and an empty stack $S$. Also, you are given an integer sequence $A=(a_1,\ldots,a_N)$ of length $N$.
For each $i=1,\ldots,N$ in this order, Takahashi will do one of the following operations:
Additionally, Takahashi may do the following operation whenever $S$ is not empty:
The score of the final $X$ is defined as follows.
Find the maximum possible score.
Input is given from Standard Input in the following format:
$N$ $a_1$ $\ldots$ $a_N$
Print the answer.
7 1 2 3 4 1 2 3
5
The following operations make the final $X$ equal $(1,1,2,3,4)$, for a score of $5$.
We cannot make the score $6$ or greater, so the maximum possible score is $5$.
10 1 1 1 1 1 1 1 1 1 1
10