{"problem":{"name":"Strange Constraints","description":{"content":"You are given a sequence of length $N$ consisting of integers from $1$ to $N$, $A=(A_1,A_2,\\ldots,A_N)$. Find the number, modulo $998244353$, of sequences of length $N$ consisting of integers from $1$","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":3000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"arc162_e"},"statements":[{"statement_type":"Markdown","content":"You are given a sequence of length $N$ consisting of integers from $1$ to $N$, $A=(A_1,A_2,\\ldots,A_N)$.\nFind the number, modulo $998244353$, of sequences of length $N$ consisting of integers from $1$ to $N$, $B=(B_1,B_2,\\ldots,B_N)$, that satisfy the following conditions for all $i=1,2,\\ldots,N$.\n\n*   The number of occurrences of $i$ in $B$ is at most $A_i$.\n*   The number of occurrences of $B_i$ in $B$ is at most $A_i$.\n\n## Constraints\n\n*   $1 \\leq N \\leq 500$\n*   $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$ $\\ldots$ $A_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"arc162_e","tags":[],"sample_group":[["3\n1 2 3","10\n\nThe following $10$ sequences satisfy the conditions:\n\n*   $(1,2,2)$\n*   $(1,2,3)$\n*   $(1,3,2)$\n*   $(1,3,3)$\n*   $(2,1,3)$\n*   $(2,3,1)$\n*   $(2,3,3)$\n*   $(3,1,2)$\n*   $(3,2,1)$\n*   $(3,2,2)$"],["4\n4 4 4 4","256\n\nAll sequences of length $4$ consisting of integers from $1$ to $4$ satisfy the conditions, and there are $4^4=256$ such sequences."],["5\n1 1 1 1 1","120\n\nAll permutations of $(1,2,3,4,5)$ satisfy the conditions, and there are $5!=120$ such sequences."],["14\n6 5 14 3 6 7 3 11 11 2 3 7 8 10","628377683\n\nBe sure to print the number modulo $998244353$."]],"created_at":"2026-03-03 11:01:13"}}