##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
You are given a permutation of integers from to .
In one operation, you can choose an index such that (where is the current length of the permutation), and , and remove from the sequence. After removing , the remaining elements are concatenated without changing their relative order.
Find the number of different subsets of numbers that can remain after applying this operation any number of times (possibly zero). Since the answer can be very large, print it modulo .
The initial permutation is 1 3 2 4. We can either do no operations and keep 1 3 2 4, or we can choose the element 3 (since 3 > 1 and 3 > 2) and remove it, resulting in 1 2 4. No further operations are possible. So there are 2 valid subsets.
The sequence is 5 3 4 2 1. We can remove 4 (since 4 > 3 and 4 > 2), resulting in 5 3 2 1. We cannot remove any other elements. So the valid subsets are 5 3 4 2 1 and 5 3 2 1.
The sequence is 1 4 5 2 3. The valid subsets are: