AT_arc212_e [ARC212E] Drop Min
Description
There is a permutation $ P $ of $ (1,2,\ldots,N) $ and an empty array $ A $ . Perform the following operation $ N-1 $ times on $ P $ :
- Choose two adjacent elements. Remove the smaller of the chosen elements from $ P $ and concatenate the parts before and after the removed element. Append the removed element to the end of $ A $ .
Find the number, modulo $ 998244353 $ , of possible final sequences $ A $ of length $ N-1 $ .
Input Format
The input is given from Standard Input in the following format:
> $ N $ $ P_1 $ $ P_2 $ $ \ldots $ $ P_N $
Output Format
Output the answer.
Explanation/Hint
### Sample Explanation 1
All six permutations of $ (1,2,3) $ are possible as the final $ A $ .
For example, $ A=(2,1,3) $ can be obtained as follows:
- Choose $ 2,3 $ . Remove $ 2 $ , and now $ P=(1,3,4), A=(2) $ .
- Choose $ 1,3 $ . Remove $ 1 $ , and now $ P=(3,4), A=(2,1) $ .
- Choose $ 3,4 $ . Remove $ 3 $ , and now $ P=(4), A=(2,1,3) $ .
### Constraints
- $ 2 \le N \le 2\times 10^5 $
- $ 1 \le P_i \le N $
- $ P $ is a permutation of $ (1,2,\ldots,N) $ .
- All input values are integers.