There exists a sequence A of size N whose each element is an integer from 1 to N. There is no integer that appears more than once in the sequence A.
Pak Dengklek wants to play with this sequence. He can perform deletion operation by doing the following:
For example, if the sequence is [2, 5, 1, 3, 4], and Pak Dengklek chooses 1 and 3 which are adjacent in that sequence, then Pak Dengklek can delete 3 and the sequence turns into [2, 5, 1, 4].
Pak Dengklek can perform deletion operations any number of times (possibly none) as long as the sequence has at least two integers. Pak Dengklek wonders how many different final sequences he can obtain after performing the deletion operations. Since the number of different final sequences can be very large, calculate the value modulo 1000000007.
The input is given with the following format:
N A1 A2 … AN
An integer representing the number of different sequences that can be obtained modulo 1\;000\;000\;007.
3 2 3 1
3
The following are possible deletion operations that can be performed on the sequence:
4 2 1 4 3
6
The following are possible deletion operations that can be performed on the sequence:
Subtask | Score |
---|---|
1 | 8 |
2 | 20 |
3 | 13 |
4 | 9 |
5 | 23 |
6 | 27 |
7 | 0 |