#P1837E. Playoff Fixing
Playoff Fixing
No submission language available for this problem.
Description
teams participate in a playoff tournament. The teams are numbered from to , in order of decreasing strength. So, team is the strongest one, team is the weakest one. A team with a smaller number always defeats a team with a larger number.
First of all, the teams are arranged in some order during a procedure called seeding. Each team is assigned another unique value from to , called a seed, that represents its starting position in the playoff.
The tournament consists of games. They are held as follows: the teams are split into pairs: team with seed plays against team with seed , team with seed plays against team with seed (exactly in this order), and so on (so, games are played in that phase). When a team loses a game, it is eliminated.
After that, only teams remain. If only one team remains, it is declared the champion; otherwise, games are played: in the first one of them, the winner of the game "seed vs seed " plays against the winner of the game "seed vs seed ", then the winner of the game "seed vs seed " plays against the winner of the game "seed vs seed ", and so on. This process repeats until only one team remains.
After the tournament ends, the teams are assigned places according to the tournament phase when they were eliminated. In particular:
- the winner of the tournament gets place ;
- the team eliminated in the finals gets place ;
- both teams eliminated in the semifinals get place ;
- all teams eliminated in the quarterfinals get place ;
- all teams eliminated in the 1/8 finals get place , and so on.
Now that we established the rules, we do a little rigging. In particular, we want:
- team (not team with seed ) to take place ;
- team to take place ;
- teams and to take place ;
- teams from to to take place , and so on.
For example, this picture describes one of the possible ways the tournament can go with , and the resulting places of the teams:

Some seeds are already reserved for some teams (we are not the only ones rigging the tournament, apparently). We have to fill the rest of the seeds with the remaining teams to achieve the desired placements. How many ways are there to do that? Since that value might be large, print it modulo .
The first line contains a single integer () — there are teams.
The second line contains integers ( or ). If , then team has seed . Otherwise, the seed is not reserved for any team.
All values, that are not , are distinct.
Print a single integer — the number of ways to fill the non-reserved seeds so that the tournament goes as planned, modulo .
Input
The first line contains a single integer () — there are teams.
The second line contains integers ( or ). If , then team has seed . Otherwise, the seed is not reserved for any team.
All values, that are not , are distinct.
Output
Print a single integer — the number of ways to fill the non-reserved seeds so that the tournament goes as planned, modulo .