Rollout Interleavings
A release pushes out k independent services at the same time. Service i has a_i
deployment steps (schema migrations, config pushes, health checks, ...) that a deploy
bot must run in their fixed order: step 1 before step 2 before step 3, and so on.
All services share a single deploy queue, and the bot is free to interleave steps from
different services however it likes — the only rule is that each service's own steps
must still come out in their original relative order.
Given the step counts a_1, a_2, ..., a_k, count how many distinct sequences the deploy
queue could end up executing all a_1 + a_2 + ... + a_k steps in, modulo 1 000 000 007.
Input
The first line contains a single integer k (1 ≤ k ≤ 10^5) — the number of services.
The second line contains k integers a_1, a_2, ..., a_k (1 ≤ a_i), the number of
deployment steps for each service. It is guaranteed that a_1 + a_2 + ... + a_k ≤ 10^6.
Output
Print a single integer: the number of distinct valid deploy-queue orders, modulo
1 000 000 007.
Notes
In the first example, service 1 contributes steps X1, X2 and service 2 contributes
steps Y1, Y2, Y3. A valid queue order is any arrangement of X1, X2, Y1, Y2, Y3 that
keeps X1 before X2 and keeps Y1 before Y2 before Y3; there are
C(5, 2) = 10 such arrangements, which matches the first example's answer.