#agc058b. [agc058_b]Adjacent Chmax
[agc058_b]Adjacent Chmax
Problem Statement
You are given a permutation of .
You may perform the following operation zero or more times.
- Choose an integer (). Let and replace the values of and with .
How many sequences are there that can be after your operations? Find the count modulo .
Constraints
- is a permutation of .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3
1 3 2
Sample Output 1
4
The four sequences that can become are , , , and .
Sample Input 2
4
2 1 3 4
Sample Output 2
11
Sample Input 3
10
4 9 6 3 8 10 1 2 7 5
Sample Output 3
855