def f(n, k, a_s):

    md = 10 ** 9 + 7

    dp = [0] * (k + 1)

    dp[0] = 1

    for a in a_s[:-1]:

        ndp = [0] * (k + 1)

        ndp[0] = s = dp[0] % md

        for j in range(1, a + 1):

            ndp[j] = s = (s + dp[j]) % md

        for j in range(a + 1, k + 1):

            ndp[j] = s = (s + dp[j] - dp[j - a - 1]) % md

        dp = ndp

    return sum(dp[k - a_s[-1]:]) % md





n, k = list(map(int, input().split()))

a_s = list(map(int, input().split()))

print((f(n, k, a_s)))

import numpy as np





def f(n, k, a_s):

    md = 10 ** 9 + 7

    dp = np.zeros(k + 1, dtype=np.int64)

    dp[0] = 1

    for a in a_s[:-1]:

        dp = np.cumsum(dp) % md

        if k != a:

            dp[k:a:-1] = (dp[k:a:-1] - dp[k - a - 1::-1]) % md

    return np.sum(dp[k - a_s[-1]:]) % md





n, k = list(map(int, input().split()))

a_s = list(map(int, input().split()))

print((f(n, k, a_s)))

def f(n, k, a_s):
    md = 10**9 + 7
    dp = [0] * (k + 1)
    dp[0] = 1
    for a in a_s[:-1]:
        ndp = [0] * (k + 1)
        ndp[0] = s = dp[0] % md
        for j in range(1, a + 1):
            ndp[j] = s = (s + dp[j]) % md
        for j in range(a + 1, k + 1):
            ndp[j] = s = (s + dp[j] - dp[j - a - 1]) % md
        dp = ndp
    return sum(dp[k - a_s[-1] :]) % md


n, k = list(map(int, input().split()))
a_s = list(map(int, input().split()))
print((f(n, k, a_s)))

import numpy as np


def f(n, k, a_s):
    md = 10**9 + 7
    dp = np.zeros(k + 1, dtype=np.int64)
    dp[0] = 1
    for a in a_s[:-1]:
        dp = np.cumsum(dp) % md
        if k != a:
            dp[k:a:-1] = (dp[k:a:-1] - dp[k - a - 1 :: -1]) % md
    return np.sum(dp[k - a_s[-1] :]) % md


n, k = list(map(int, input().split()))
a_s = list(map(int, input().split()))
print((f(n, k, a_s)))

+import numpy as np + + -    dp = [0] * (k + 1) +    dp = np.zeros(k + 1, dtype=np.int64) -        ndp = [0] * (k + 1) -        ndp[0] = s = dp[0] % md -        for j in range(1, a + 1): -            ndp[j] = s = (s + dp[j]) % md -        for j in range(a + 1, k + 1): -            ndp[j] = s = (s + dp[j] - dp[j - a - 1]) % md -        dp = ndp -    return sum(dp[k - a_s[-1] :]) % md +        dp = np.cumsum(dp) % md +        if k != a: +            dp[k:a:-1] = (dp[k:a:-1] - dp[k - a - 1 :: -1]) % md +    return np.sum(dp[k - a_s[-1] :]) % md