#arc162d. [arc162_d]Smallest Vertices

[arc162_d]Smallest Vertices

Problem Statement

In this problem, a rooted directed tree is a rooted tree where all edges are directed from the root to the leaves.

You are given a sequence of non-negative integers d=(d1,d2,ldots,dN)d=(d_1,d_2,\\ldots,d_N) with a sum of N1N-1.

Among the NN-vertex rooted directed trees with vertex numbered 11 to NN and vertex 11 as the root, a good tree is one that satisfies the following condition:

  • the out-degree of vertex i(1leqileqN)i\\ (1\\leq i \\leq N) is did_i.

Furthermore, for a vertex vv of a good tree, let f(v)f(v) be the minimum vertex number of the vertices (including vv) in the subtree rooted at vertex vv, and vv is called a good vertex if it satisfies f(v)=vf(v)=v.

Find the sum of the numbers of good vertices for all good trees, modulo 998244353998244353.

Constraints

  • 2leqNleq5002 \\leq N \\leq 500
  • 0leqdileqN10 \\leq d_i \\leq N-1
  • d1geq1d_1 \\geq 1
  • sumi=1Ndi=N1\\sum_{i=1}^N d_i = N-1
  • All input values are integers.

Input

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

NN d1d_1 d2d_2 ldots\\ldots dNd_N

Output

Print the answer.


Sample Input 1

4
2 0 1 0

Sample Output 1

7

There are two good trees, as shown below. The blue vertices are good vertices.

For these trees, there are 44 and 33 good vertices, respectively, so the answer is 77.


Sample Input 2

10
3 1 0 0 2 0 1 2 0 0

Sample Output 2

37542