{"problem":{"name":"Row Column Sums 2","description":{"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: *   for all $i = 1, 2, \\ldots, N$, the","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":3000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"abc273_g"},"statements":[{"statement_type":"Markdown","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).\n\n## Constraints\n\n*   $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.\n\n## Input\n\nThe 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$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"abc273_g","tags":[],"sample_group":[["3\n1 1 1\n0 1 2","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"],["3\n1 1 1\n2 2 2","0"],["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","968235177\n\nBe sure to print the count modulo $998244353$."]],"created_at":"2026-03-03 11:01:14"}}