#include <iostream>
    #include <sstream>
    #include <iomanip>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <cctype>
    #include <cstring>
    #include <vector>
    #include <list>
    #include <queue>
    #include <deque>
    #include <stack>
    #include <map>
    #include <set>
    #include <algorithm>
    #include <iterator>
    #include <bitset>
    #include <ctime>

    using namespace std;

    #define FOR(i,a,b) for(int i = (a); i < (b); i++)
    #define rep(i,n) FOR(i,0,n)
    #define RFOR(i,b,a) for(int i = (b) - 1; i>= (a); i--)
    #define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
    #define FILL(a, value) memset(a, value, sizeof(a)

    #define SZ(a) (int)a.size()
    #define ALL(a) a.begin(), a.end()
    #define PB push_back
    #define MP make_pair
    #define er erase 
    #define in insert
    #define fs first 
    #define sc second
    

    typedef  long long LL;
    typedef vector<int> VI;
    typedef vector<LL > VL; 
    typedef vector<vector<int > > VVI;
    typedef  vector<vector<LL>> VVL; 
    typedef vector < vector<pair<int, int >> >VVPI;
    typedef vector<vector<pair<LL, LL >> >VVPL;
    typedef vector<pair<LL, LL >> PL; 
    typedef vector<PL> VPL; 
    typedef pair<int, int> PII;
    typedef vector<PII> VPI; 

    const double PI = acos(-1.0);
    const int INF = 1000 * 1000 * 1000 + 7;
    const LL LINF = INF * (LL)INF;

    const double EPS = 1e-7;
    const int MAX = 20 * 1000 + 47;
    const int MAS = 1e5  * 2;
    const int MOD = 1000 * 1000 * 1000 + 7;
    void max_self(LL& a, LL b)
    {
        a = max(a, b); 
    }
    void min_self(LL& a, LL b)
    {
        a = min(a, b); 
    }
    void max_self(int& a, int b)
    {
        a = max(a, b); 
    }
    void min_self(int& a, int b)
    {
        a = min(a, b); 
    }
    void add(LL &a, LL b)
    {
        a += b;
        if (a >= MOD)
        {
            a -= MOD; 
        }
    }
    void sub(LL& a, LL b)
    {
        a -= b;
        if (a < 0)
        {
            a += MOD; 
        }
    }
    VI psum(VI a)
    {
        VI b;
        FOR(i,1,a.size())
        {
            b[i] = b[i - 1] + a[i];
        }
        return b; 
    }
    struct rmq {
        int t[MAS * 4];
        int n;
        void build(VI a, int v, int tl, int tr) {
            if (tl == tr)
                t[v] = a[tl];
            else {
                int tm = (tl + tr) / 2;
                build(a, v * 2, tl, tm);
                build(a, v * 2 + 1, tm + 1, tr);
                t[v] = t[v * 2] + t[v * 2 + 1];
            }
        }
        void init(int n,VI a )
        {
            this->n = n;
            build(a , 1, 0, n - 1);
        }

        int sum(int v, int tl, int tr, int l, int r) {
            if (l > r)
                return 0;
            if (l == tl && r == tr)
                return t[v];
            int tm = (tl + tr) / 2;
            return sum(v * 2, tl, tm, l, min(r, tm))
                + sum(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
        } 
        void update(int v, int tl, int tr, int pos, int new_val) {
            if (tl == tr)
                t[v] = new_val;
            else {
                int tm = (tl + tr) / 2;
                if (pos <= tm)
                    update(v * 2, tl, tm, pos, new_val);
                else
                    update(v * 2 + 1, tm + 1, tr, pos, new_val);
                t[v] = t[v * 2] + t[v * 2 + 1];
            }
        }
    }T;


 
    int main()
    {
        int n, k;
        cin >> n >> k;
        VL dp(k + 1); 
        dp[0] = 1; 
        rep(i, n)
        {
            int x;
            cin >> x; 
            VL v(k + 1); 
            RFOR(used, k+1, 0)
            {
                int l = used + 1;
                int  r = used + min(x, k - used);
                if (l <= r)
                {
                    add(v[l ], dp[used]);
                    if (r + 1 <= k)
                    {
                        sub(v[r + 1], dp[used]); 
                    }
                }
            }
           LL pref = 0;
            rep(i,k+1)
            {
                add(pref, v[i]);
                add(dp[i], pref);  
            }
            
        }
        cout << dp[k] << endl;
    }
   


Measured memory_bytes: 1792