{"raw_statement":[{"iden":"problem statement","content":"Find the number, modulo $998244353$, of square matrices of size $N$ whose elements are non-negative integers, that satisfy both of the following two conditions:\n\n*   for all $i = 1, 2, \\ldots, N$, the sum of the elements in the $i$\\-th row is $R_i$;\n*   for all $i = 1, 2, \\ldots, N$, the sum of the elements in the $i$\\-th column is $C_i$.\n\nNote that $R_i$ and $C_i$ given in the input are integers between $0$ and $2$ (see Constraints)."},{"iden":"constraints","content":"*   $1 \\leq N \\leq 5000$\n*   $0 \\leq R_i \\leq 2$\n*   $0 \\leq C_i \\leq 2$\n*   All values in the input are integers."},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$N$\n$R_1$ $R_2$ $\\ldots$ $R_N$\n$C_1$ $C_2$ $\\ldots$ $C_N$"},{"iden":"sample input 1","content":"3\n1 1 1\n0 1 2"},{"iden":"sample output 1","content":"3\n\nThe following $3$ matrices satisfy the conditions:\n\n0 1 0\n0 0 1\n0 0 1\n\n0 0 1\n0 1 0\n0 0 1\n\n0 0 1\n0 0 1\n0 1 0"},{"iden":"sample input 2","content":"3\n1 1 1\n2 2 2"},{"iden":"sample output 2","content":"0"},{"iden":"sample input 3","content":"18\n2 0 1 2 0 1 1 2 1 1 2 0 1 2 2 1 0 0\n1 1 0 1 1 1 1 1 1 1 1 1 2 1 1 0 2 2"},{"iden":"sample output 3","content":"968235177\n\nBe sure to print the count modulo $998244353$."}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}