#ARC155F. [ARC155F] Directable as Desired

[ARC155F] Directable as Desired

Score : 10001000 points

Problem Statement

You are given a sequence of NN non-negative integers: D=(D1,D2,,DN)D=(D_1, D_2, \dots, D_N).

Find the number of labeled trees with NN vertices numbered 11 to NN that satisfy the following condition, modulo 998244353998244353.

  • There is a way to direct the N1N-1 edges so that the outdegree of each vertex i (1iN)i\ (1\leq i \leq N) is DiD_i.

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • 0DiN10 \leq D_i \leq N-1
  • i=1NDi=N1\sum_{i=1}^{N} D_i = N-1
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN

D1D_1 D2D_2 \dots DND_N

Output

Print the answer.

4
0 1 0 2
5

Below are the five trees that satisfy the condition, directed in a desired way.

5
0 1 1 1 1
125
15
0 0 0 0 0 0 0 1 1 1 1 1 2 3 4
63282877