Stacking Pizzas
Time limit1sMemory limit1024 MB
Given a_i pizzas of each size i, sum over all stacking orders the number of pizzas visible from above, modulo 1000000007.
- Level
Medium6 of 10
- Topics
- Combinatorics, Probability, Math
- Solved
- No attempts yet
Problem
There are pizzas of size , pizzas of size , , and pizzas of size . You want to stack all of these pizzas so that their centers coincide.
For every possible stacking order, find the total number of pizzas that are visible when viewed from above. A pizza is visible if it is larger than every pizza stacked on top of it.
Pizzas of the same size are indistinguishable, so the order among pizzas of the same size is not considered.
Input
The first line contains , the size of the largest pizza.
The next line contains , , , separated by spaces, where is the number of pizzas of size .
Output
Print the sum, over all possible orders, of the number of visible pizzas, modulo .
Constraints
Hint
In the first sample, every possible order and the number of visible pizzas for each order are listed below. Pizzas are written from the top down.
- (1, 2, 2): 2
- (2, 1, 2): 1
- (2, 2, 1): 1
The total number of visible pizzas is .