This page is still under construction.

Parts of this page are still being built. What you see may change.

Neural Networks

Time limit4sMemory limit1024 MB

Summary
Count labeled layered digraphs in which every node lies on some directed path from layer 1 to layer N, modulo 998244353.
Level

Hard8 of 10

Topics
Dynamic programming, Combinatorics, Math, Graph
Solved
No attempts yet

Problem

Art is a computer science student at UT. Over the last two semesters he applied for dozens of internships, and he has 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 1, 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 1 and layer NN), there exists a path along which information can flow from layer 1 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 1; nodes A_1+1,…,A_1+A_2A\_1+1,\dots,A\_1+A\_2 belong to layer 2, and so on. Two networks are considered different if there is an edge that exists in one network but not in the other.

Input

The first line of input contains a single integer NN (2≤N≤5⋅1052 \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, 1≤A_i≤5⋅1051 \leq A\_i \leq 5 \cdot 10^5; furthermore, ∑_i=1NA_i≤5⋅105\sum\_{i=1}^N A\_i \leq 5 \cdot 10^5. That is, the total number of nodes is at most 5⋅1055 \cdot 10^5, and each layer has at least one node.)

Output

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

Examples2

  1. Example 1

    Input
    3
    2 3 2
    
    Expected output
    625
    
  2. Example 2

    Input
    3
    1 2 1
    
    Expected output
    1