Problem Statement
A sequence $B=(B_1,\ldots,B_N)$ of length $N$ consisting of integers between $1$ and $N$ (inclusive) is called a good sequence if and only if it satisfies the following condition:
- For every interval
$[l,r]\ (1\leq l \leq r \leq N)$, there exists an integer$x\ (l\leq x\leq r)$such that the following condition holds: - Prepare a graph with
$N$vertices numbered from$1$to$N$and zero edges. For each$l \leq i \leq r$, if$i\neq x$, add an edge between vertices$i$and$B_i$. Then, vertices$l, l+1,\ldots,r$form a tree. That is, vertices$l, l+1,\ldots,r$are connected.
You are given a sequence $A=(A_1,\ldots,A_N)$ where each element is either an integer between $1$ and $N$, or $-1$. Find the number, modulo $998244353$, of ways to replace the elements that are $-1$ in $A$ with integers between $1$ and $N$ such that $A$ becomes a good sequence.
Constraints
- All input values are integers.
$1\leq N\leq 2\times 10^5$$1\leq A_i\leq N$or$A_i=-1$
Input
The input is given from Standard Input in the following format:
N
A_1 \cdots A_N
Output
Output the number, modulo $998244353$, of ways to replace the elements that are $-1$ in $A$ with integers between $1$ and $N$ (inclusive) such that $A$ becomes a good sequence.
样例
3
-1 -1 -1
7
3
-1 3 -1
3
6
2 3 -1 -1 -1 -1
21
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。