Time limit: 0.8s
Memory limit: 256MB
Input:
Output:
Task
Given a permutation of length , count the number of tuples , where . Since the answer can be large, print its remainder modulo .
Input data
The input file consists of:
- a line containing integer .
- a line containing the integers .
Output data
The output file must contain a single line consisting of integer -- the number of such tuples modulo .
Constraints and clarifications
- .
- for each .
- for every .
| # | Score | Constraints |
|---|---|---|
| 1 | 0 | Examples |
| 2 | 30 | |
| 3 | 30 | |
| 4 | 40 | No additional restrictions |
Example 1
stdin
5
2 1 3 4 5
stdout
3
Explanation
In the first sample case the following tuples meet the requirements: , , .
Example 2
stdin
10
4 5 1 2 8 7 9 3 6 10
stdout
27