Mindol Tour
Time limit1sMemory limit512 MB
Count Hamiltonian cycles starting and ending at trampoline 0 in a graph where node 0 connects to all and node i reaches nodes within distance A_i, with A_i at least i.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Combinatorics, Greedy, Math
- Solved
- No attempts yet
Problem
Mindol is the best rapper in the world. With the money he earned on a tour of 100 countries, he built an amusement park called Mindol Park a while ago.
The main ride in Mindol Park is a row of trampolines. There are trampolines numbered to , placed in that order, and you play by jumping between them. Trampoline is the starting point, so from it you can jump to every other trampoline in one jump. From trampoline with you can jump in one jump only to a trampoline whose number differs by at most , that is, to trampoline with . For safety, every trampoline can reach trampoline in one jump, so holds.
Minsol, a fan of Mindol, went to Mindol Park and decided to try a Mindol tour, named after the Hamiltonian tour. A Mindol tour starts at trampoline , visits each of the other trampolines exactly once, and returns to trampoline . Tours with a different visiting order are different tours, so a tour and its reverse are counted separately.
Minsol wants to make every possible Mindol tour once before going home. Count how many times she rides.
Input
The first line contains the number of trampolines other than trampoline , ().
The second line contains (), separated by spaces.
Output
Print the number of possible Mindol tours modulo on the first line.
Note
For and the possible tours are , , , and .