{"problem":{"name":"Not So Consecutive","description":{"content":"You are given an integer $N$. An integer sequence $x=(x_1,x_2,\\cdots,x_N)$ of length $N$ is called a **good** sequence if and only if the following conditions are satisfied: *   Each element of $x$ i","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"arc169_c"},"statements":[{"statement_type":"Markdown","content":"You are given an integer $N$. An integer sequence $x=(x_1,x_2,\\cdots,x_N)$ of length $N$ is called a **good** sequence if and only if the following conditions are satisfied:\n\n*   Each element of $x$ is an integer between $1$ and $N$, inclusive.\n*   For each integer $i$ ($1 \\leq i \\leq N$), there is no position in $x$ where $i$ appears $i+1$ or more times in a row.\n\nYou are given an integer sequence $A=(A_1,A_2,\\cdots,A_N)$ of length $N$. Each element of $A$ is $-1$ or an integer between $1$ and $N$. Find the number, modulo $998244353$, of good sequences that can be obtained by replacing each $-1$ in $A$ with an integer between $1$ and $N$.\n\n## Constraints\n\n*   $1 \\leq N \\leq 5000$\n*   $A_i=-1$ or $1 \\leq A_i \\leq N$.\n*   All input values are integers.\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$N$\n$A_1$ $A_2$ $\\cdots$ $A_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"arc169_c","tags":[],"sample_group":[["2\n-1 -1","3\n\nYou can obtain four sequences by replacing each $-1$ with an integer between $1$ and $2$.\n$A=(1,1)$ is not a good sequence because $1$ appears twice in a row.\nThe other sequences $A=(1,2),(2,1),(2,2)$ are good.\nThus, the answer is $3$."],["3\n2 -1 2","2"],["4\n-1 1 1 -1","0"],["20\n9 -1 -1 -1 -1 -1 -1 -1 -1 -1 7 -1 -1 -1 19 4 -1 -1 -1 -1","128282166"]],"created_at":"2026-03-03 11:01:14"}}