There are cards arranged in a row. The number written on the -th card is , and is a permutation of .
In one operation, you remove either the leftmost or the rightmost remaining card. If the removed card is the largest card remaining immediately before the operation, you gain one point.
You continue until all cards have been removed. Find the maximum score you can obtain.
Remove , , and from the left, then remove and from the right. Every removal except that of card gives one point. It is impossible to score on all five removals because, after card is removed, the largest remaining card is not at either end.
Remove every card from the right. Each removed card is the largest one remaining, so the final score is .
One optimal choice is to remove , , and from the right, followed by , , , and . The removals of , , and give points. No better score is possible: before removing , one whole side of it must disappear, and the largest card on either side initially lies between two other cards.
Remove cards alternately from the left and the right in the order . Every removed card is the largest remaining card, giving a score of .