#P11281. 「GFOI Round 2」Aob & Blice

「GFOI Round 2」Aob & Blice

Description

Aob and Blice are playing a game.

There is a permutation pp of length nn, and both Aob and Blice each hold an initially empty distinct set, denoted as SAS_A and SBS_B respectively. The rules for one round of the game are as follows:

  • First, Aob randomly selects two integers xx and yy such that 1x<yn1 \leq x < y \leq n and px>pyp_x > p_y. Then, Aob randomly chooses one of the two ordered pairs (x,y)(x, y) or (px,py)(p_x, p_y) to add to his set SAS_A.

  • After that, Blice must choose one of the pairs (y,x)(y, x) or (py,px)(p_y, p_x) to add to her set SBS_B. Note that xx and yy are the same as those chosen by Aob in the previous step.

After infinitely many rounds ^{\dagger}, Aob and Blice will compare their sets. Although Aob plays randomly, Blice is smarter and hopes to make both sets exactly the same in the end, so the game will end in a tie—this way, neither of them will be upset!

Unfortunately, some elements in the permutation have disappeared. Blice has asked for your help to determine how many possible original permutations could allow them to achieve a tie after infinitely many rounds. For convenience, you only need to compute the answer modulo 998244353998244353.


^{\dagger} A tie after infinitely many rounds is defined as follows: for any ε>0\varepsilon > 0, there exists a positive integer NN such that for all n>Nn > N, Blice can adopt a strategy ensuring that the probability of not achieving a tie after nn rounds is less than ε\varepsilon.

Input Format

The first line contains a positive integer nn.

The second line contains nn integers pip_i. For each ii, if pi=0p_i = 0, it indicates that the number at the ii-th position has disappeared; otherwise, it represents the number that was originally at the ii-th position in the permutation.

Output Format

Output a single line containing an integer that represents the answer modulo 998244353998244353.

3
0 2 0
2
7
0 3 2 0 5 7 0
2

Hint

Sample 11 Explanation

Exactly two permutations are valid: {1,2,3},{3,2,1}\{1,2,3\},\{3,2,1\}.

Subtasks and Constraints

Subtask ID nn \leq Special Properties Score
1 99 No 2020
2 20002000 A 1515
3 No 1010
4 10610^6 A 1515
5 B 1010
6 No 3030
  • Special Property A: pi0p_i \ne 0.
  • Special Property B: pi=0p_i = 0.

For all tests, it is guaranteed that:

  • 1n1061 \le n \le 10^6;
  • 0pin0 \le p_i \le n;
  • For all 1i<jn1 \le i < j \le n, if pi0p_i \ne 0 and pj0p_j \ne 0, then pipjp_i \ne p_j.