##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
| # | Title | Points | Solved | Admin | |
|---|---|---|---|---|---|
You are given a permutation of the numbers .
In one operation, you delete exactly one element from the current array. The deleted element must be either the leftmost element or the rightmost element of the current array.
For each with , define as follows.
You perform exactly operations. Let be the set of values that were deleted. Then is the maximum possible value of over all valid sequences of operations.
Here, is the smallest non-negative integer that does not belong to .
Output .
The only deleted value is . The deleted set is , so its mex is .
For every , delete the first elements from the left. Then the deleted values are exactly , so the mex is .
The mex cannot be larger than , because exactly values are deleted.
The permutation is .
With one deletion, value cannot be deleted, so the mex is .
With two or three deletions, value can be deleted, but values and cannot both be deleted. Therefore the best mex is .
With four deletions, delete two elements from the left and two elements from the right. The deleted values are , so the mex is .
With five deletions, all values are deleted, so the mex is .
The permutation is .
With one deletion, value cannot be deleted, so the mex is .
With two or three deletions, value can be deleted, but values and cannot both be deleted. Therefore the best mex is .
With four deletions, delete two elements from the left and two elements from the right. The deleted values are , so the mex is .
With five deletions, keep only the third element, whose value is . The deleted values are , so the mex is .
With six deletions, all values are deleted, so the mex is .
The permutation is .
For , value cannot be deleted, so the mex is .
For , delete the first four elements. The deleted values are , so the mex is .
For , delete the first four elements and the last element. The deleted values are , so the mex is still . Values cannot all be deleted using only five deletions.
For , delete the first four elements and the last two elements. The deleted values are , so the mex is .
For , keep only the fifth element, whose value is . The deleted values are , so the mex is .
For , all values are deleted, so the mex is .