You have N children numbered from 1 to N. They want to share K candies among themselves. Each child i (1 ≤ i ≤ N) should receive between 0 and a_i candies (inclusive), and no candies should be left over. Find the number of ways to share candies, considering two ways different if a child receives a different number of candies. All input values are integers. Constraints: 1 ≤ N ≤ 100, 0 ≤ K ≤ 10^5, 0 ≤ a_i ≤ K. Input format: N K a_1 a_2 ... a_N. Output the number of ways to share candies modulo 10^9 + 7. Example: Input: 3 4 1 2 3, Output: 5 (e.g., (0, 1, 3), (0, 2, 2), (1, 0, 3), (1, 1, 2), (1, 2, 1)). If there are no ways to share candies, output 0. Be sure to print the answer modulo 10^9 + 7.

# Buggy version:
n, k = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))

dp = [[0 for i in range(n+1)] for i in range(k+2)]

for i in range(1, k+2):
    dp[i][0] = 1

for i in range(1, k+2):
    for j in range(1, n+1):
        K = i-1
        if K < arr[j-1]:
            dp[i][j] = dp[i-1][j] + dp[i][j-1]-dp[0][j-1]
        else:
            dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-arr[j-1]-1][j-1]
        

print(dp[-1][-1]-dp[-2][-1])

# Fixed version:
mod = 1000000007
n, k = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))

dp = [[0 for i in range(n+1)] for i in range(k+2)]

for i in range(1, k+2):
    dp[i][0] = 1

for i in range(1, k+2):
    for j in range(1, n+1):
        K = i-1
        if K < arr[j-1]:
            dp[i][j] = dp[i-1][j] + dp[i][j-1]-dp[0][j-1]
        else:
            dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-arr[j-1]-1][j-1]
        
        dp[i][j] %= mod


print((dp[-1][-1]-dp[-2][-1] + mod)%mod)

# Buggy version:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
import numpy as np

N, K = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
mod = 10**9+7

dp = [[0]*(K+1) for i in range(N+1)]
dp[0][0] = 1

for i in range(1,N+1):
    for k in range(K+1):
        s = np.cumsum(dp[i-1])
        m = max(0, k-a[i])
        if m > 0:
            dp[i][k] = ((s[k] % mod) - (s[m-1] % mod)) % mod
        else:
            dp[i][k] = s[k] % mod

print(dp[N][K] % mod)



# Fixed version:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)

N, K = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
mod = 10**9+7

dp = [[0]*(K+1) for i in range(N+1)]
dp[0][0] = 1

for i in range(1,N+1):
    s = list(itertools.accumulate(dp[i - 1]))
    for k in range(K+1):
        m = max(0, k-a[i])
        if m > 0:
            dp[i][k] = ((s[k] % mod) - (s[m-1] % mod)) % mod
        else:
            dp[i][k] = s[k] % mod

print(dp[N][K] % mod)

# Buggy version:
n,k=map(int,input().split())
li=[int(K) for K in input().split()]
dp=[[0 for j in range(k+1)] for i in range(n+1)]
dp[0][0]=1
for b in range(1,n+1):
  dp[b][0]=1
mod=10**9+7  
for i in range(1,n+1):
  sums=[0]*(k+1)
  sums[0]=1
  for j in range(1,k+1):
    sums[j]=sums[j-1]+dp[i-1][j]
  for a in range(k+1):
    res=sums[a]
    if(a-li[i-1]-1)>=0:
      res=(res-sums[a-li[i-1]-1]+mod)%mod
    dp[i][a]=res
print(dp[n][k])    


# Fixed version:
n,k=map(int,input().split())
li=[int(K) for K in input().split()]
dp=[[0 for j in range(k+1)] for i in range(n+1)]
dp[0][0]=1
for b in range(1,n+1):
  dp[b][0]=1
mod=10**9+7  
for i in range(1,n+1):
  sums=[0]*(k+1)
  sums[0]=1
  for j in range(1,k+1):
    sums[j]=(sums[j-1]+dp[i-1][j])%mod
  for a in range(k+1):
    res=sums[a]
    if(a-li[i-1]-1)>=0:
      res=(res-sums[a-li[i-1]-1]+mod)%mod
    dp[i][a]=res
print(dp[n][k])

# Buggy version:
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]*(k+1)
mod=10**9+7
for i in range(0,a[0]+1):
    dp[i]=1
for i in range(1,len(a)):
    for j in range(k+1):
        dp[j]=(dp[j]+dp[j-1])%mod
    for j in range(k,a[i],-1):
        dp[j]=(dp[j]-dp[j-a[i]-1]+mod)%mod
print(dp[k])

# Fixed version:
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]*(k+1)
dp[0]=1
mod=10**9+7
for i in range(n):
  for j in range(k,0,-1):
    if j>a[i]:dp[j]-=dp[j-a[i]-1]
  for j in range(k):dp[j+1]=(dp[j+1]+dp[j])%mod
print(dp[k])

# Buggy version:

def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    OPT[N][K] = sum(OPT[N-1][K-i]) 0 <= i <= A[N]
    OPT[0][0] = 1
    N*K
    3 4
    1 2 3

1 0 0 0 0
1 1 0 0 0
1 2 2 1 0
1 3 5 6 5

OPT[3][1] = OPT[2][1]+OPT[2][0]
OPT[3][2] = OPT[2][2]+OPT[2][1]+OPT[2][0]
OPT[3][3] = OPT[2][3]+OPT
    """
    N, K = read_ints()
    A = read_ints()
    modulo = 10**9+7
    OPT = [[0]*(K+1) for _ in range(N+1)]
    for i in range(N+1):
        OPT[i][0] = 1
    for j in range(K+1):
        OPT[0][j] = 1
    for i in range(1, N+1):
        for j in range(1, K+1):
            OPT[i][j] += OPT[i][j-1]+OPT[i-1][j]
            if j-A[i-1]-1 >= 0:
                OPT[i][j] -= OPT[i-1][j-A[i-1]-1]
            OPT[i][j] %= modulo
    return (OPT[-1][-1])%modulo


if __name__ == '__main__':
    print(solve())


# Fixed version:


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    OPT[N][K] = sum(OPT[N-1][K-i]) 0 <= i <= A[N]
    OPT[0][0] = 1
    N*K
    3 4
    1 2 3

1 0 0 0 0
1 1 0 0 0
1 2 2 1 0
1 3 5 6 5

OPT[3][1] = OPT[2][1]+OPT[2][0]
OPT[3][2] = OPT[2][2]+OPT[2][1]+OPT[2][0]
OPT[3][3] = OPT[2][3]+OPT
    """
    N, K = read_ints()
    A = read_ints()
    modulo = 10**9+7
    OPT = [[0]*(K+1) for _ in range(N+1)]
    for i in range(N+1):
        OPT[i][0] = 1
    for j in range(K+1):
        OPT[0][j] = 1
    for i in range(1, N+1):
        for j in range(1, K+1):
            OPT[i][j] += OPT[i][j-1]+OPT[i-1][j]
            if j-A[i-1]-1 >= 0:
                OPT[i][j] -= OPT[i-1][j-A[i-1]-1]
            OPT[i][j] %= modulo
    if K == 0:
        return OPT[-1][-1]
    return (OPT[-1][-1]-OPT[-1][-2])%modulo


if __name__ == '__main__':
    print(solve())

# Buggy version:
mod = 10 ** 9 + 7

N, K, *A = map(int, open(0).read().split())

dp = [1] + [0] * K
for a in A:
    for i in range(1, K + 1):
        dp[i] += dp[i - 1]
    for i in reversed(range(1, K + 1)):
        dp[i] -= dp[max(0, i - a) - 1]
        dp[i] %= mod

print(dp[K])

# Fixed version:
mod = 10 ** 9 + 7

N, K, *A = map(int, open(0).read().split())

dp = [1] + [0] * (K + 1)
for a in A:
    for i in range(1, K + 1):
        dp[i] += dp[i - 1]
    for i in reversed(range(1, K + 1)):
        dp[i] -= dp[max(0, i - a) - 1]
        dp[i] %= mod

print(dp[K])

# Buggy version:
N,K = map(int, input().split())
A = list(map(int, input().split()))

dp = [[0] * (K+10) for _ in range(N+1)]
dp[0][0] = 1
for i in range(N):
    for j in range(K,0,-1):
        dp[i+1][j] += dp[i][j]
        dp[i+1][j] %= MOD
        if j + a[i] + 1 <= K+1:
            dp[i+1][j+a[i]+1] = (dp[i+1][j+a[i]+1] - dp[i][j] + MOD) % MOD
    
    for j in range(K+1):
        dp[i+1][j+1] += dp[i+1][j]
        dp[i+1][j+1] %= MOD

print(dp[N][K])


# Fixed version:
N,K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 1000000007

dp = [[0] * (K+10) for _ in range(N+1)]
dp[0][0] = 1
for i in range(N):
    for j in range(K,-1,-1):
        dp[i+1][j] += dp[i][j]
        dp[i+1][j] %= MOD
        if j + A[i] + 1 <= K+1:
            dp[i+1][j+A[i]+1] = (dp[i+1][j+A[i]+1] - dp[i][j] + MOD) % MOD
    
    for j in range(K+1):
        dp[i+1][j+1] += dp[i+1][j]
        dp[i+1][j+1] %= MOD

print(dp[N][K])

# Buggy version:
n, k = map(int, input().split())
a = list(map(int, input().split()))

cs_a, cnt = [0] * n, 0
for i in range(n):
    cnt += a[i]
    cs_a[i] = cnt

dp = [[0] * (n + 1) for i in range(k + 1)]
cs_dp = [[0] * (n + 1) for i in range(k + 1)]

for i in range(k + 1):
    for j in range(1, n + 1):
        if i > cs_a[j - 1]:
            dp[i][j] = 0
        elif i == 0:
            dp[i][j], cs_dp[i][j] = 1, 1
        elif i == 1:
            dp[i][j] = dp[i][j - 1] + min(1, a[j - 1])
        elif i - a[j - 1] - 1 < 0:
            dp[i][j] = cs_dp[i][j - 1]
        else:
            dp[i][j] = cs_dp[i][j - 1] - cs_dp[i - a[j - 1] - 1][j - 1]
        if i > 0:
            cs_dp[i][j] = cs_dp[i - 1][j] + dp[i][j]

print(dp)
print(dp[k][n] % (10 ** 9 + 7))


# Fixed version:
n, k = map(int, input().split())
a = list(map(int, input().split()))

cs_a, cnt = [0] * n, 0
for i in range(n):
    cnt += a[i]
    cs_a[i] = cnt
dp = [[0] * (k + 1) for i in range(n + 1)]

for i in range(n + 1):
    for j in range(k + 1):
        if j == 0:
            dp[i][j] = 1
        elif (i == 0) or (j > cs_a[i - 1]):
            dp[i][j] = 0
        elif j - a[i - 1] - 1 < 0:
            dp[i][j] = dp[i - 1][j] + dp[i][j - 1]
        else:
            dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - a[i - 1] - 1]
        dp[i][j] %= 10 ** 9 + 7

print(dp[n][k])

# Buggy version:
n, k = map(int, input().split())
a = list(map(int, input().split()))

cs_a, cnt = [0] * n, 0
for i in range(n):
    cnt += a[i]
    cs_a[i] = cnt

dp = [[0] * (n + 1) for i in range(k + 1)]

for i in range(k + 1):
    for j in range(1, n + 1):
        if i > cs_a[j - 1]:
            dp[i][j] = 0
        elif i == 0:
            dp[i][j] = 1
        elif i == 1:
            dp[i][j] = dp[i][j - 1] + min(1, a[j - 1])
        else:
            dp[i][j] = sum(dp[i - x][j - 1] for x in range(a[j - 1] + 1))

print(dp[k][n] % (10 ** 9 + 7))


# Fixed version:
n, k = map(int, input().split())
a = list(map(int, input().split()))

cs_a, cnt = [0] * n, 0
for i in range(n):
    cnt += a[i]
    cs_a[i] = cnt
dp = [[0] * (k + 1) for i in range(n + 1)]

for i in range(n + 1):
    for j in range(k + 1):
        if j == 0:
            dp[i][j] = 1
        elif (i == 0) or (j > cs_a[i - 1]):
            dp[i][j] = 0
        elif j == 1:
            dp[i][j] = dp[i - 1][j] + min(a[i - 1], 1)
        elif j - a[i - 1] - 1 < 0:
            dp[i][j] = dp[i - 1][j] + dp[i][j - 1]
        else:
            dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - a[i - 1] - 1]
        dp[i][j] %= 10 ** 9 + 7

print(dp[n][k])

# Buggy version:
n,k=map(int,input().split())
a=list(map(int,input().split()))

m=10**9+7

dp=[ [0]*(k+1) for _  in range(n+1) ]
dp[0][0]=1

for i in range(n):
    for j in range(k+1):
        if j-a[i]>=0:
            dp[i+1][j]=sum( dp[i][j-a[i]:j+1 ])
        else:
            dp[i+1][j]=sum( dp[i][0:j+1 ])

print(dp[n][k]%m)

# Fixed version:
n,k=map(int,input().split())
a=list(map(int,input().split()))

m=10**9+7

dp=[ [0]*(k+1) for _  in range(n+1) ]
dp[0][0]=1

dp_sum=[ [0]*(k+1) for _  in range(n+1) ]

for i in range(n):
    for j in range(k+1):
        if j==0:
            dp_sum[i][j]=1
        else:
            dp_sum[i][j]= (dp_sum[i][j-1]+dp[i][j])%m
        if j-a[i]>0:
            dp[i+1][j]= (dp_sum[i][j] - dp_sum[i][j-a[i]-1])%m
        else:
            dp[i+1][j]= (dp_sum[i][j])%m

print(dp[n][k]%m)

# Buggy version:
n,k=map(int,input().split())
a=list(map(int,input().split()))
if k > sum(a):
    print(-1)
    exit()

mod = 1000000007
dp = [[0 for _ in range(k+1)]for __ in range(n+1)]
for i in range(n+1):
    dp[i][0] = 1
    dp[0][i] = 0

for i in range(1,n+1):
    for j in range(1,k+1):
        if j > a[i-1]:
            if i is 1:
                break
        dp[i][j] = dp[i-1][j] + dp[i][j-1]
        if j > a[i-1]:
            dp[i][j] -= dp[i-1][j-1-a[i-1]]
        dp[i][j] %= mod
print(dp[n][k])

# Fixed version:
n,k=map(int,input().split())
a=list(map(int,input().split()))
if k > sum(a):
    print(0)
    exit()

mod = 1000000007
dp = [[0 for _ in range(k+1)]for __ in range(n+1)]
for i in range(n+1):
    dp[i][0] = 1
for i in range(k+1):
    dp[0][i] = 0

for i in range(1,n+1):
    for j in range(1,k+1):
        if j > a[i-1]:
            if i is 1:
                break
        dp[i][j] = dp[i-1][j] + dp[i][j-1]
        if j > a[i-1]:
            dp[i][j] -= dp[i-1][j-1-a[i-1]]
        dp[i][j] %= mod
print(dp[n][k])

# Buggy version:
N,K= map(int, input().split())
a=list(map(int,input().split()))
dp=[[0]*(K+1) for i in range(N)]
for j in range(a[0]+1):
  dp[0][j]=1
  
for i in range(1,N):
  for j in range(1,K+1):
    if j==0:
      dp[i][j]=0
    else:
      dp[i][j]=dp[i][j-1]+dp[i-1][j]
      if j>=a[i]+1:
        dp[i][j]-=dp[i-1][j-1-a[i]]
      dp[i][j]=dp[i][j]%(10**9+7)
print(dp[-1][-1])

# Fixed version:
N, K = map(int, input().split())
a = [-1] + list(map(int, input().split()))

MOD = 10**9 + 7

dp = [[0]*(K+1) for _ in range(N+1)]
for i in range(N+1):
    dp[i][0] = 1

for i in range(N):
    for j in range(K):
        if j - a[i+1] >= 0:
            dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1] - dp[i][j - a[i+1]]) % MOD
        else:
            dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1]) % MOD

print(dp[N][K])

# Buggy version:
def main():
    N, K = map(int, input().split())
    if K == 0:
        return 1
    A = list(map(int, input().split()))
    MOD = 10**9+7
    dp = [[0]*(K+1) for _ in range(N+1)]
    dp[0][0] = 1
    for i in range(N):
        a = A[i]
        for j in range(K):
            dp[i+1][j] += dp[i][j]
            if j+a+1 <= K:
                dp[i+1][j+a+1] -= dp[i][j]
        for j in range(K):
            dp[i+1][j] %= MOD
            dp[i+1][j+1] += dp[i+1][j]

    return dp[N][K]


print(main())


# Fixed version:
def main():
    N, K = map(int, input().split())
    if K == 0:
        return 1
    A = list(map(int, input().split()))
    MOD = 10**9+7
    dp = [[0]*(K+1) for _ in range(N+1)]
    dp[0][0] = 1
    for i in range(N):
        a = A[i]
        for j in range(K+1):
            dp[i+1][j] += dp[i][j]
            if j+a+1 <= K:
                dp[i+1][j+a+1] -= dp[i][j]
        for j in range(K):
            dp[i+1][j+1] += dp[i+1][j]
        for j in range(K+1):
            dp[i+1][j] = dp[i+1][j] % MOD

    return dp[N][K]


print(main())

# Buggy version:
def p_m():
    n, k = map(int, input().split())
    *a, = map(int, input().split())
    mod = 10 ** 9 + 7
    # dp[i][j]はi番目の子にj個の飴を配る方法が何通りかどうか
    dp = [[0] * (k + 1) for _ in range(n + 1)]
    dp[0][0] = 1

    count = 0
    for i in range(n):
        for j in range(min(k + 1, count + 1)):
            count += a[i]
            for m in range(a[i] + 1):
                if j + m > k:
                    break
                dp[i + 1][j + m] += dp[i][j]
                dp[i + 1][j + m] %= mod
    print(dp[n][k])


if __name__ == '__main__':
    p_m()

# Fixed version:
def p_m():
    n, k = map(int, input().split())
    *a, = map(int, input().split())
    mod = 10 ** 9 + 7
    # dp[i][j]はi番目の子にj個の飴を配る方法が何通りかどうか
    dp = [[0] * (k + 1) for _ in range(n + 1)]
    for i in range(n + 1):
        dp[i][0] = 1

    for i in range(1, n + 1):
        for j in range(1, k + 1):
            if j - 1 - a[i - 1] >= 0:
                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1 - a[i - 1]]) % mod
            else:
                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod
    print(dp[n][k])


if __name__ == '__main__':
    p_m()

# Buggy version:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    dp=[0]*(k+1)
    dp[k]=1
    for i in range(n):
        ndp=[0]*(k+1)
        # dpの累積和を取っておく
        S=[0]*(k+2)
        for j in range(k+1): S[j+1]=S[j]+dp[j]
        # iterete
        for j in range(k+1):
            ndp[j]=S[min(j+A[i]+1,k+1)]-S[j]
        dp=ndp
    print(dp[0])
resolve()

# Fixed version:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    dp=[0]*(k+1)
    dp[k]=1
    for i in range(n):
        ndp=[0]*(k+1)
        # dpの累積和を取っておく
        S=[0]*(k+2)
        for j in range(k+1):
            S[j+1]=S[j]+dp[j]
            S[j+1]%=MOD
        # iterete
        for j in range(k+1):
            ndp[j]=S[min(j+A[i]+1,k+1)]-S[j]
            ndp[j]%=MOD
        dp=ndp
    print(dp[0])
resolve()

# Buggy version:
from itertools import accumulate

def f(k, A):
    n = len(A)

    mod = int(1e9 + 7)
    dp = [0] * (k + 1)

    # init for last column
    for j in range(min(A[n - 1], k) + 1):
        dp[j] = 1

    for i in range(n - 2, -1, -1):
        dp = list(accumulate(dp))
        a = A[i]
        dp[a+1:] = [x - y for x, y in zip(dp[a + 1:], dp)]

    return dp[-1]

assert f(4, [2, 3]) == 2
assert f(4, [1, 2, 3]) == 5
assert f(10, [9]) == 0
assert f(0, [0, 0]) == 1
#assert f(100000, [100000, 100000, 100000, 100000]) == 665683269

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


# Fixed version:
from itertools import accumulate

def f(k, A):
    n = len(A)

    mod = int(1e9 + 7)
    dp = [0] * (k + 1)

    # init for last column
    for j in range(min(A[n - 1], k) + 1):
        dp[j] = 1

    for i in range(n - 2, -1, -1):
        dp = list(accumulate(dp))
        a = A[i]
        dp[a+1:] = [x - y for x, y in zip(dp[a + 1:], dp)]
        dp = [x % mod for x in dp]

    return dp[-1] % mod

assert f(4, [2, 3]) == 2
assert f(4, [1, 2, 3]) == 5
assert f(10, [9]) == 0
assert f(0, [0, 0]) == 1
assert f(100000, [100000, 100000, 100000, 100000]) == 665683269

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

# Buggy version:
from sys import stdin
from itertools import accumulate
input = stdin.readline

MOD = 10**9+7
N, K = map(int,input().split())
a = list(map(int,input().split()))

p = list(accumulate(a))

dp = [0] * (K+1)
dp[0] = 1
prefix = [0]+[1]*(K+1)
for i in range(N):
    new_dp = [0]*(K+1)
    for j in range(min(p[i],K)+1):
        new_dp[j] = prefix[j+1] - prefix[max(0,j-a[i])]
    dp = new_dp[:]


print(dp[K]%MOD)


# Fixed version:
from sys import stdin
from itertools import accumulate
input = stdin.readline

MOD = 10**9+7
N, K = map(int,input().split())
a = list(map(int,input().split()))

p = list(accumulate(a))

dp = [0] * (K+1)
dp[0] = 1
prefix = [0]+[1]*(K+1)
for i in range(N):
    new_dp = [0]*(K+1)
    for j in range(min(p[i],K)+1):
        new_dp[j] = prefix[j+1] - prefix[max(0,j-a[i])]
    dp = new_dp[:]
    prefix = [i % MOD for i in [0]+list(accumulate(dp))]

print(dp[K]%MOD)