#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 with a sum of .
Among the -vertex rooted directed trees with vertex numbered to and vertex as the root, a good tree is one that satisfies the following condition:
- the out-degree of vertex is .
Furthermore, for a vertex of a good tree, let be the minimum vertex number of the vertices (including ) in the subtree rooted at vertex , and is called a good vertex if it satisfies .
Find the sum of the numbers of good vertices for all good trees, modulo .
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
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 and good vertices, respectively, so the answer is .
Sample Input 2
10
3 1 0 0 2 0 1 2 0 0
Sample Output 2
37542