#F. ARC106F - Figures

    Type: Default 1000ms 256MiB

ARC106F - Figures

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Score : 800 points

Problem Statement

Takahashi is about to assemble a character figure, consisting of N parts called Part 1, Part 2, ..., Part N and N1 connecting components. Parts are distinguishable, but connecting components are not.

Part i has di holes, called Hole 1, Hole 2, ..., Hole di, into which a connecting component can be inserted. These holes in the parts are distinguishable. Each connecting component will be inserted into two holes in different parts, connecting these two parts. It is impossible to insert multiple connecting components into a hole.

The character figure is said to be complete when it has the following properties:

  • All of the N1 components are used to connect parts.
  • Consider a graph with N vertices corresponding to the parts and N1 undirected edges corresponding to the pairs of vertices connected by a connecting component. Then, this graph is connected.

Two ways A and B to make the figure complete are considered the same when the following is satisfied: for every pair of holes, A uses a connecting component to connect these holes if and only if B uses one to connect them.

Find the number of ways to make the figure complete. Since the answer can be enormous, find the count modulo 998244353.

Constraints

  • All values in input are integers.
  • 2N2×105
  • 1di<998244353

Input

Input is given from Standard Input in the following format:

N
d1 d2  dN

Output

Print the answer.


Sample Input 1

3
1 1 3

Sample Output 1

6

One way to make the figure complete is to connect Hole 1 in Part 1 and Hole 3 in Part 3 and then connect Hole 1 in Part 2 and Hole 1 in Part 3.


Sample Input 2

3
1 1 1

Sample Output 2

0

Sample Input 3

6
7 3 5 10 6 4

Sample Output 3

389183858

Sample Input 4

9
425656 453453 4320 1231 9582 54336 31435436 14342 423543

Sample Output 4

667877982

ARC106

Not Attended
Status
Done
Rule
IOI
Problem
6
Start at
2023-7-5 8:15
End at
2023-7-5 10:15
Duration
2 hour(s)
Host
Partic.
13