Miss Burger has learned a lot of data structures recently. Her favorite one is the queue. Now, she wants to use two queues to implement a sorting algorithm.
To do so, she creates two queues $$$A$$$ and $$$B$$$ in the beginning. They are all initialized to be empty. For a queue, you can only conduct two kinds of operations:
The integers we will sort only include $$$1$$$ to $$$n$$$. For each $$$i$$$ ($$$1 \leq i \leq n$$$), we let $$$a_i$$$ denote the amount of $$$i$$$ in total. Therefore, $$$\sum\limits_{i=1}^n a_i$$$ integers are to be sorted in total, denoted as $$$m$$$.
Miss Burger first rearranges all $$$m$$$ integers into a sequence $$$b$$$ in arbitrary order. We say $$$b$$$ is legal if and only if she can sort all integers in non-decreasing order in the following way:
Now, Miss Burger wants to know how many different sequences $$$\{b_i\}_{i=1...m}$$$ can be sorted by her two queues. Two sequences $$$\{b_i\}_{i=1...m}$$$ are considered different if there exists a position $$$i$$$ where their values $$$b_i$$$ of these two sequences are different. As the answer may be large, your output should be modulo $$$998\,244\,353$$$.
The first line contains an integer $$$n$$$ ($$$1\le n\le 500$$$), denoting the types of numbers.
The second line contains $$$n$$$ integers, $$$a_1,...,a_n$$$ ($$$0\le a_i \le n$$$), where $$$a_i$$$ denotes the amount of number $$$i$$$.
It is guaranteed that $$$1 \le \sum\limits_{i=1}^n a_i\le 500$$$.
Output a single line containing only one integer, denoting the number of legal sequences.
As the answer may be large, your output should be modulo $$$998\,244\,353$$$.
41 1 1 1
14
| Название |
|---|


