#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define M 1000000007  // 10^9+7

int candies(int arr[], int n, int k){

    ll **dp = new ll*[n+1];
    for(int i=0; i<=n; i++)
        dp[i] = new ll[k+1];

    // dp[i][j] stores the number of ways to distribute
    // 'j' candies to the first 'i' students

    // Base case: If no student, then can't distribute more than 0 candies
    //          If no candy, then can distribute all the students in only 1 way
    //          (don't give a candy to anyone)

    for(int j=1; j<=k; j++)
        dp[0][j] = 0;

    for(int i=0; i<=n; i++)
        dp[i][0] = 1;

    for(int i=1; i<=n; i++){
        for(int j=1; j<=k; j++){
            // We can distribute this student either 0, 1, 2, ... arr[i-1] candies
            ll cnt = 0;
            for(int z=0; z<=arr[i-1]; z++){
                // If we give this student 'z' candies
                // (only if we have enough candies),
                // then remaining students should get 'j-z' candies
                if(j-z >= 0)
                    cnt = (cnt + dp[i-1][j-z])%M;
            }
            dp[i][j] = cnt;
        }
    }
//    for(int i=0; i<=n; i++){
//        for(int j=0; j<=k; j++)
//            cout<<dp[i][j]<<" ";
//        cout<<endl;
//    }
    ll ans = dp[n][k];
    for(int i=0; i<=n; i++)
        delete[] dp[i];
    delete[] dp;
    return ans;
}

int candiesOptimized(int arr[], int n, int k){

    // In the above approach, notice in the third for loop,
    // we are just taking the sum:
    // dp[i-1][j-0] + dp[i-1][j-1] + dp[i-1][j-2] + ... + dp[i-1][j-arr[i-1]]

    // We can maintain a prefix sum array of previous row
    // and then can quickly take this sum
    // between [j-arr[i-1], j]

    //  To visualize: draw the DP table of this test case
    //  n = 3, k = 4
    //  arr = [1, 2, 3]

    ll **dp = new ll*[n+1];
    for(int i=0; i<=n; i++)
        dp[i] = new ll[k+1];

    ll **prefix = new ll*[n+1];
    for(int i=0; i<=n; i++)
        prefix[i] = new ll[k+1];

    for(int j=0; j<=k; j++){
        dp[0][j] = 0;
        prefix[0][j] = 1;
    }
    for(int i=0; i<=n; i++){
        dp[i][0] = 1;
        prefix[i][0] = 1;
    }

    for(int i=1; i<=n; i++){
        for(int j=1; j<=k; j++){
            ll cnt = prefix[i-1][j];
            if(j-arr[i-1]-1 >= 0)
                cnt = ((cnt - prefix[i-1][j-arr[i-1]-1])%M + M)%M;
            dp[i][j] = cnt;
            prefix[i][j] = (prefix[i][j-1] + cnt)%M;
        }
    }
    ll ans = dp[n][k];
    for(int i=0; i<=n; i++)
        delete[] dp[i];
    delete[] dp;
    return ans;
}

int candiesOptimizedBetter(int arr[], int n, int k){

    // We only need to maintain 2 rows of prefix table
    // In the end the answer is prefix[n-1][k] - prefix[n-1][k-arr[n-1]-1]
    ll prefix[2][k+1];
    for(int j=0; j<=k; j++)
        prefix[0][j] = 1;
    prefix[1][0] = 1;
    int currRow = 1;

    for(int i=1; i<=n; i++){
        for(int j=1; j<=k; j++){
            ll cnt = prefix[1-currRow][j];
            if(j-arr[i-1]-1 >= 0)
                cnt = ((cnt - prefix[1-currRow][j-arr[i-1]-1])%M + M)%M;
            prefix[currRow][j] = (prefix[currRow][j-1] + cnt)%M;
        }
        currRow = 1-currRow;
    }

    ll ans = prefix[currRow][k];
    if(k-arr[n-1]-1 >= 0)
        ans = ((ans - prefix[currRow][k-arr[n-1]-1])%M + M)%M;

    return ans;
}

int main()
{
 int n, k;
 cin>>n>>k;
 int arr[n];
 for(int i=0; i<n; i++)
    cin>>arr[i];
// int ans = candies(arr, n, k);
// int ans = candiesOptimized(arr, n, k);
 int ans = candiesOptimizedBetter(arr, n, k);
 cout<<ans;
 return 0;
}



Measured memory_bytes: 5180