Task
After reading about the ambitious SETI program, William decided to join the project and build an array of radios for interstellar transmissions in his garage. However, the array has not received any extraterrestrial message yet, fact that William blamed to the phenomenon of interference.
In particular, William noticed that whenever the -th radio is turned on, of the radios on its left (that is, radios ) receive disturbed signals and are not usable. Fortunately, no interfering signals are received by radios on the right (that is, with ). In order to plan his next experiment avoiding interferences, William now needs to select a subset of his radios avoiding interferences, that is, such that if radio is turned on then all radios between and are turned off.
Help William plan his next experiment, by counting the number of subsets of radios avoiding interferences modulo .
Input data
The first line contains the only integer . The second line contains integers .
Output data
You need to write a single line with an integer: the number of valid subsets of radios modulo .
Constraints and clarifications
- .
- for each .
# | Points | Constraints |
---|---|---|
1 | 5 | Examples. |
2 | 20 | for each . |
3 | 30 | . |
4 | 25 | . |
5 | 20 | No additional limitations. |
Example 1
stdin
3
0 0 0
stdout
8
Explanation
In the first sample case, there is no interference thus all subsets of the three radios are valid.
Example 2
stdin
6
0 1 2 3 2 1
stdout
13
Explanation
In the second sample case, the valid subsets are the following: