Sorted Lists are thought beautiful while permutations are considered elegant. So what about sequence (1, 2, ... , n) ? It is the oracle from god. Now Coach Pang finds a permutation (p
1, p
2, ... , p
n) over {1, 2, ... , n} which has been shuffled by some evil guys. To show Coach Pang’s best regards to the oracle, Coach Pang decides to rearrange the sequence such that it is the same as (1, 2, 3, ... , n). The time cost of swapping p
i and p
j is 2|i- j| - 1. Of course, the minimum time cost will be paid since Coach Pang is lazy and busy. Denote the minimum time cost of the task as f(p). But Coach Pang is not good at maths. He finally works out a clumsy algorithm to get f(p) as following:
Coach Pang’s algorithm is clearly wrong. For example, n = 3 and (3, 2, 1) is the permutation. In this case, f(p) = 3 but g(p) = 0 + 0 + 2 = 2. The question is that how many permutations p of {1, 2, ... , n} such that f(p) = g(p). To make the problem more challenge, we also restrict the prefix of p to (a
1, a
2, ... , a
k). To sum up, you need to answer the question that how many permutations p of {1, 2, ... , n} with the fixed prefix p
1 = a
1, p
2 = a
2, ... , p
k = a
k such that f(p) = g(p). Since the answer may be very large, for convenience, you are only asked to output the remainder divided by (10
9 + 7).