#P1837E. Playoff Fixing

Playoff Fixing

No submission language available for this problem.

Description

2k2^k teams participate in a playoff tournament. The teams are numbered from 11 to 2k2^k, in order of decreasing strength. So, team 11 is the strongest one, team 2k2^k 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 11 to 2k2^k, called a seed, that represents its starting position in the playoff.

The tournament consists of 2k12^k - 1 games. They are held as follows: the teams are split into pairs: team with seed 11 plays against team with seed 22, team with seed 33 plays against team with seed 44 (exactly in this order), and so on (so, 2k12^{k-1} games are played in that phase). When a team loses a game, it is eliminated.

After that, only 2k12^{k-1} teams remain. If only one team remains, it is declared the champion; otherwise, 2k22^{k-2} games are played: in the first one of them, the winner of the game "seed 11 vs seed 22" plays against the winner of the game "seed 33 vs seed 44", then the winner of the game "seed 55 vs seed 66" plays against the winner of the game "seed 77 vs seed 88", 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 11;
  • the team eliminated in the finals gets place 22;
  • both teams eliminated in the semifinals get place 33;
  • all teams eliminated in the quarterfinals get place 55;
  • all teams eliminated in the 1/8 finals get place 99, and so on.

Now that we established the rules, we do a little rigging. In particular, we want:

  • team 11 (not team with seed 11) to take place 11;
  • team 22 to take place 22;
  • teams 33 and 44 to take place 33;
  • teams from 55 to 88 to take place 55, and so on.

For example, this picture describes one of the possible ways the tournament can go with k=3k = 3, 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 998244353998\,244\,353.

The first line contains a single integer kk (0k190 \le k \le 19) — there are 2k2^k teams.

The second line contains 2k2^k integers a1,a2,,a2ka_1, a_2, \dots, a_{2^k} (ai=1a_i = -1 or 1ai2k1 \le a_i \le 2^k). If ai1a_i \ne -1, then team aia_i has seed ii. Otherwise, the seed ii is not reserved for any team.

All values, that are not 1-1, are distinct.

Print a single integer — the number of ways to fill the non-reserved seeds so that the tournament goes as planned, modulo 998244353998\,244\,353.

Input

The first line contains a single integer kk (0k190 \le k \le 19) — there are 2k2^k teams.

The second line contains 2k2^k integers a1,a2,,a2ka_1, a_2, \dots, a_{2^k} (ai=1a_i = -1 or 1ai2k1 \le a_i \le 2^k). If ai1a_i \ne -1, then team aia_i has seed ii. Otherwise, the seed ii is not reserved for any team.

All values, that are not 1-1, 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 998244353998\,244\,353.

Sample Input 1

2
1 2 3 4

Sample Output 1

0

Sample Input 2

2
1 3 4 2

Sample Output 2

1

Sample Input 3

1
-1 -1

Sample Output 3

2

Sample Input 4

2
-1 -1 -1 -1

Sample Output 4

16

Sample Input 5

3
-1 -1 -1 -1 2 -1 -1 -1

Sample Output 5

768

Sample Input 6

0
1

Sample Output 6

1