Neural Networks

아직 제출이 없습니다시간 제한4초메모리 제한1024 MB

문제

Art is a computer science student at UT. Over the last two semesters, he has applied for dozens of internships, and he's finally landed his dream job: designing neural networks for a hot new machine learning startup in Austin.

A neural network is a directed graph whose nodes are partitioned into layers. If A_iA\_i is the number of nodes in the ii-th layer and there are NN layers in total, then the graph has _i=1NA_i\sum\_{i=1}^N A\_i nodes. All the edges in the graph go from a node in the ii-th layer to a node in the (i+1)(i+1)-th layer. These graphs are used for computation in the following manner: input is provided to the nodes in layer 11, information flows magically along the edges of the graph, and output is read from the nodes in layer NN.

On Art's first day of work, his manager gives him an array AA of length NN specifying the number of nodes in each layer of a neural network, and asks him to add some edges to make it interesting. A neural network is said to be interesting if, for every node uu in the graph (including those in layer 11 and layer NN), there exists a path along which information can flow from layer 11 to layer NN that passes through uu.

Art realizes that there may be many possible interesting networks he could build using the given specification. Before he complains to his manager about the ill-defined nature of his task, though, he wants you to help him determine just how many such networks there are. Since the answer may be very large, output its remainder modulo the prime 998,244,353998\\,244\\,353.

Note that the nodes in the graph are labeled. Nodes 1,,A_11, \dots, A\_1 belong to layer 11; nodes A_1+1,,A_1+A_2A\_1+1,\dots,A\_1+A\_2 belong to layer 22, and so on. Two networks are considered different if there is an edge that exists in one network but not in the other.

입력

The first line of input contains a single integer NN (2N51052 \leq N \leq 5 \cdot 10^5), the number of layers in the network. The second line of input contains NN space-separated integers: the ii-th integer is A_iA\_i, the number of nodes in layer ii. (For each ii, 1A_i51051 \leq A\_i \leq 5 \cdot 10^5; futhermore, _i=1NA_i5105\sum\_{i=1}^N A\_i \leq 5 \cdot 10^5. That is, the total number of nodes is at most 51055 \cdot 10^5, and each layer has at least one node.)

출력

Output a single integer, the number of distinct interesting neural networks corresponding to the given specification modulo 998,244,353998\\,244\\,353.