Replica Spread

medium combinatorics dp prefix-sums 2000 ms · 256 MB

Replica Spread

A storage cluster keeps k identical replicas of a hot object. Before choosing where to put them, the placement service wants to know how many options it actually has.

There are n servers, numbered from 1 to n. Server i has room for at most c_i replicas of the object (it may also hold none). A placement assigns a whole number of replicas x_i to each server so that 0 ≤ x_i ≤ c_i for every i and x_1 + x_2 + … + x_n = k. Replicas are indistinguishable, so two placements differ exactly when some server holds a different number of replicas in them.

Count the distinct placements. Since the number can be huge, print it modulo 1 000 000 007.

Input

The first line contains two integers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 10^5): the number of servers and the number of replicas.

The second line contains n integers c_1, c_2, …, c_n (0 ≤ c_i ≤ 10^5): the capacity of each server.

Output

Print one integer: the number of placements modulo 1 000 000 007. If the replicas cannot be placed at all, print 0.

Notes

In the first example the valid placements (x_1, x_2, x_3) are (0, 1, 3), (1, 0, 3), (1, 1, 2), (2, 0, 2) and (2, 1, 1).

In the second example the servers can hold only 6 replicas in total, so 7 replicas cannot be placed.

When k = 0 there is exactly one placement: every server holds nothing.

Example 1

Input

3 4
2 1 3

Output

5

Example 2

Input

2 7
3 3

Output

0

Hints · reveal one at a time if you're stuck

Hint 1

Try a tiny case, such as two servers, and count the ways to split k replicas between them. How does that count build on the count for one server, when you add a second one?

Hint 2

Let the state be the number of ways to place exactly j replicas on the servers processed so far. A new server with capacity c lets you add anywhere from 0 to c replicas, so each new entry is a sum over a window of the previous row. Summing each window directly is too slow for k up to 10^5.

Hint 3

Prefix sums turn each window into a constant-time difference, for O(n·k) total work. Be careful that the window has c + 1 entries, and that a difference modulo 1000000007 can be negative.

report an issue Prefer your own editor? sooks prep 27 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.