{"raw_statement":[{"iden":"problem statement","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$."},{"iden":"constraints","content":"*   $1 \\leq N \\leq 500$\n*   $1 \\leq A_i \\leq N$\n*   All input values are integers."},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$N$\n$A_1$ $A_2$ $\\ldots$ $A_N$"},{"iden":"sample input 1","content":"3\n1 2 3"},{"iden":"sample output 1","content":"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)$"},{"iden":"sample input 2","content":"4\n4 4 4 4"},{"iden":"sample output 2","content":"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."},{"iden":"sample input 3","content":"5\n1 1 1 1 1"},{"iden":"sample output 3","content":"120\n\nAll permutations of $(1,2,3,4,5)$ satisfy the conditions, and there are $5!=120$ such sequences."},{"iden":"sample input 4","content":"14\n6 5 14 3 6 7 3 11 11 2 3 7 8 10"},{"iden":"sample output 4","content":"628377683\n\nBe sure to print the number modulo $998244353$."}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}