{"problem":{"name":"Tree Sequence","description":{"content":"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 inter","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"arc206_c"},"statements":[{"statement_type":"Markdown","content":"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:\n\n*   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:\n    *   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.\n\nYou 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.\n\n## Constraints\n\n*   All input values are integers.\n*   $1\\leq N\\leq 2\\times 10^5$\n*   $1\\leq A_i\\leq N$ or $A_i=-1$\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$N$ \n$A_1$ $\\cdots$ $A_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"arc206_c","tags":[],"sample_group":[["3\n-1 -1 -1","7\n\nThe replacements that satisfy the condition are the following seven:\n\n*   $(1,1,2)$\n*   $(2,1,2)$\n*   $(2,2,2)$\n*   $(2,3,1)$\n*   $(2,3,2)$\n*   $(2,3,3)$\n*   $(3,1,2)$\n\nFor example, in the case of $A=(1,1,2)$, that the interval $[1,2]$ satisfies the condition can be confirmed by setting $x=1$, where vertices $2$ and $A_2=1$ are connected and vertices $1,2$ form a tree.\nSimilarly, intervals $[1,1],[2,2],[3,3],[2,3],[1,3]$ also satisfy the condition, so $(1,1,2)$ is a good sequence."],["3\n-1 3 -1","3\n\nThe replacements that satisfy the condition are the following three:\n\n*   $(2,3,1)$\n*   $(2,3,2)$\n*   $(2,3,3)$"],["6\n2 3 -1 -1 -1 -1","21"]],"created_at":"2026-03-03 11:01:14"}}