#include <bits/stdc++.h>
using namespace std;

template <long long mod>
class Mod
{
    long long value;
    void set_value(const long long x)
    {
        this->value = x % mod;
    }

public:
    Mod()
    {
        set_value(0ll);
    }

    template <typename T>
    Mod(T x = 0)
    {
        set_value((long long)x);
    }

    friend istream &operator>>(istream &is, Mod &x)
    {
        long long tmp;
        is >> tmp;
        x.set_value(tmp);
        return is;
    }

    friend ostream &operator<<(ostream &os, const Mod &x)
    {
        os << x.value;
        return os;
    }

    operator long long() const
    {
        return this->value;
    }

    template <typename T>
    bool operator<(const T x)
    {
        return this->value < (long long)x;
    }

    template <typename T>
    bool operator<=(const T x)
    {
        return this->value <= (long long)x;
    }

    template <typename T>
    bool operator>(const T x)
    {
        return this->value > (long long)x;
    }

    template <typename T>
    bool operator>=(const T x)
    {
        return this->value >= (long long)x;
    }

    template <typename T>
    bool operator==(const T x)
    {
        return this->value == (long long)x;
    }

    template <typename T>
    Mod &operator=(const T x)
    {
        set_value((long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator&=(const T x)
    {
        set_value(this->value & (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator|=(const T x)
    {
        set_value(this->value | (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator^=(const T x)
    {
        set_value(this->value ^ (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator<<=(const T x)
    {
        set_value(this->value << (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator>>=(const T x)
    {
        set_value(this->value >> (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator+=(const T x)
    {
        set_value(this->value + (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator-=(const T x)
    {
        set_value(this->value - (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator*=(const T x)
    {
        set_value(this->value * (long long)x);
        return *this;
    }

    template <typename T>
    Mod &operator/=(const T x)
    {
        long long a = (long long)x;
        long long b = mod;
        long long u = 1;
        long long v = 0;
        while (b)
        {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        u %= mod;
        if (u < 0)
            u += mod;
        *this *= Mod(u);
        return *this;
    }

    template <typename T>
    Mod operator&(const T x) const
    {
        return Mod(*this) &= x;
    }

    template <typename T>
    Mod operator|(const T x) const
    {
        return Mod(*this) |= x;
    }

    template <typename T>
    Mod operator^(const T x) const
    {
        return Mod(*this) ^= x;
    }

    template <typename T>
    Mod operator<<(const T x) const
    {
        return Mod(*this) <<= x;
    }

    template <typename T>
    Mod operator>>(const T x) const
    {
        return Mod(*this) >>= x;
    }

    template <typename T>
    Mod operator+(const T x) const
    {
        return Mod(*this) += x;
    }

    template <typename T>
    Mod operator-(const T x) const
    {
        return Mod(*this) -= x;
    }

    template <typename T>
    Mod operator*(const T x) const
    {
        return Mod(*this) *= x;
    }

    template <typename T>
    Mod operator/(const T x) const
    {
        return Mod(*this) /= x;
    }

    Mod &operator++()
    {
        *this += 1;
        return *this;
    }

    Mod &operator--()
    {
        *this -= 1;
        return *this;
    }

    Mod operator++(auto)
    {
        Mod ret(*this);
        ++*this;
        return ret;
    }

    Mod operator--(auto)
    {
        Mod ret(*this);
        --*this;
        return ret;
    }
};

template <typename T>
class BinaryIndexedTree
{
public:
    vector<T> arr;
    long long size;
    T initial_value;

    BinaryIndexedTree(long long N)
    {
        setSize(N);
    }

    BinaryIndexedTree(long long N, T init)
    {
        setSize(N);
        setInitialValue(init);
        initializeArr();
    }

    void setSize(long long N)
    {
        size = N + 1;
    }

    void setInitialValue(T init)
    {
        initial_value = init;
    }

    void initializeArr()
    {
        arr = vector<T>(size, initial_value);
    }

    void initializeArr(T init)
    {
        setInitialValue(init);
        initializeArr();
    }

    T func(T x, T y);

    void update(long long idx, T value)
    {
        while (idx <= size)
        {
            arr[idx] = func(arr[idx], value);
            idx += (idx & -idx);
        }
    }

    T query(long long idx)
    {
        T ret = initial_value;
        while (idx > 0)
        {
            ret = func(ret, arr[idx]);
            idx -= (idx & -idx);
        }
        return ret;
    }
};

int main()
{
    const long long MOD = 1'000'000'007;

    int N, K;
    cin >> N >> K;

    vector<int> a(N + 1, 0);
    for (int i = 1; i <= N; i++)
    {
        cin >> a[i];
    }

    vector<vector<Mod<MOD>>> dp(N + 1, vector<Mod<MOD>>(K + 1, 0));
    dp[0][K] = 1;
    for (int i = 1; i <= N; i++)
    {
        vector<Mod<MOD>> diff(K + 5, 0);
        for (int j = 0; j <= K; j++)
        {
            diff[j - min(j, a[i])] += dp[i - 1][j];
            diff[j + 1] -= dp[i - 1][j];
        }
        for (int j = 0; j <= K; j++)
        {
            if (j > 0)
            {
                diff[j] += diff[j - 1];
            }
            dp[i][j] += diff[j];
        }
    }
    cout << dp[N][0] + MOD << endl;
}


Measured memory_bytes: 80256