{"raw_statement":[{"iden":"problem statement","content":"Given is a sequence $a_1,\\dots,a_n$ consisting of $1,\\dots, n$ and $-1$, along with an integer $d$. How many sequences $p_1,\\dots,p_n$ satisfy the conditions below? Print the count modulo $998244353$.\n\n*   $p_1,\\dots,p_n$ is a permutation of $1,\\dots, n$.\n*   For each $i=1,\\dots,n$, $a_i=p_i$ if $a_i\\neq -1$. (That is, $p_1,\\dots,p_n$ can be obtained by replacing the $-1$s in $a_1,\\dots,a_n$ in some way.)\n*   For each $i=1,\\dots,n$, $|p_i - i|\\le d$."},{"iden":"constraints","content":"*   $1 \\le d \\le 5$\n*   $d < n \\le 500$\n*   $1\\le a_i \\le n$ or $a_i=-1$.\n*   $|a_i-i|\\le d$ if $a_i\\neq -1$.\n*   $a_i\\neq a_j$, if $i\\neq j$ and $a_i, a_j \\neq -1$.\n*   All values in input are integers."},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$n$ $d$\n$a_1$ $\\dots$ $a_n$"},{"iden":"sample input 1","content":"4 2\n3 -1 1 -1"},{"iden":"sample output 1","content":"2\n\nThe conditions are satisfied by $(3,2,1,4)$ and $(3,4,1,2)$."},{"iden":"sample input 2","content":"5 1\n2 3 4 5 -1"},{"iden":"sample output 2","content":"0\n\nThe only permutation of $1,2,3,4,5$ that can be obtained by replacing the $-1$ is $(2,3,4,5,1)$, whose fifth term violates the condition, so the answer is $0$."},{"iden":"sample input 3","content":"16 5\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1"},{"iden":"sample output 3","content":"794673086\n\nPrint the count modulo $998244353$."}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}