{"raw_statement":[{"iden":"problem statement","content":"You are given a sequence of integers $(A_1,\\dots,A_N)$ of length $N$. This sequence satisfies $0\\le A_i < i$ for each $i=1,\\dots,N$. Find the number of permutations $(P_1,\\dots,P_N)$ of $(1,\\dots,N)$ that satisfy the following conditions, modulo $998244353$.\n\n*   For each $i=1,\\dots,N$:\n    *   $P_j > P_i$ for any integer $j$ with $A_i < j < i$\n    *   $P_{A_i} < P_i$ if $A_i > 0$\n\nFor the sequence $(A_1,\\dots,A_N)$ given in the input, it is guaranteed that there exists a permutation satisfying the conditions."},{"iden":"constraints","content":"*   $1\\le N\\le 3\\times 10^5$\n*   $0\\le A_i \\lt i$\n*   For $A_1,\\dots,A_N$, there exists a permutation satisfying the conditions in the problem statement.\n*   All input values are integers."},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$N$\n$A_1$ $A_2$ $\\dots$ $A_N$"},{"iden":"sample input 1","content":"4\n0 1 0 3"},{"iden":"sample output 1","content":"3\n\nThere are three such permutations: $(2, 3, 1, 4)$, $(2, 4, 1, 3)$, and $(3, 4, 1, 2)$."},{"iden":"sample input 2","content":"22\n0 1 2 2 2 2 2 2 1 9 9 9 9 0 14 15 15 15 14 19 19 19"},{"iden":"sample output 2","content":"353820794\n\nThe answer is $353820794$, which is $2350309500$ modulo $998244353$."}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}