#include<bits/stdc++.h>
#define ll long long
#define ldb long double
#define fi first
#define se second
#define sza(a) (int)a.size()
#define pir pair<int,int>
#define pirll pair<ll,ll>
using namespace std;
const int maxn = 4e3 + 5;
const int modu = 1e9 + 7;
inline void add(ll &x,ll y){x = (x + y) % modu;}
ll dp[maxn][maxn],a[maxn],f[maxn][maxn],predq[maxn][maxn];
void absorb_f(int p,int nxt,int m){
for (int i = 0 ; i <= m ; i++){
add(f[p][i],f[nxt][i]);
if (a[nxt] < a[p])
add(f[p][i],dp[nxt][i]);
}
}
void get_dp(int p,int lst,int m){
for (int i = a[p] ; i <= m ; i++)
add(dp[p][i],predq[lst][i - a[p]]);
}
void get_predq(int p,int lst,int m){
for (int i = 0 ; i <= m ; i++)
predq[p][i] = ((ll)predq[lst][i] + (ll)f[p][i]) % modu;
}
void perform_dynamic_programming(int n,int m){
deque <int> dq,tdq;
for (int i = 1 ; i <= n ; i++){
//a[i] cannot be chosen, as a[i] > -> seen together
while (dq.size() && a[i] > a[dq.back()]){
absorb_f(i,dq.back(),m);
dq.pop_back();
}
while (tdq.size() && a[i] >= a[tdq.back()]) tdq.pop_back();
//self case
dp[i][a[i]]++;
if (tdq.size())
get_dp(i,tdq.back(),m);
if (dq.size())
get_predq(i,dq.back(),m);
else
get_predq(i,0,m);
dq.push_back(i);
tdq.push_back(i);
}
}
int solve(int n,int m){
ll res = 0;
perform_dynamic_programming(n,m);
for (int i = 1 ; i <= n ; i++){
for (int j = 0 ; j <= m ; j++)
res = (res + dp[i][j]) % modu;
}
res++;
if (res < 0) res += modu;
return res;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n,m;
cin >> n >> m;
for (int i = 1 ; i <= n ; i++) cin >> a[i];
cout << solve(n,m);
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBsbCBsb25nIGxvbmcKI2RlZmluZSBsZGIgbG9uZyBkb3VibGUKI2RlZmluZSBmaSBmaXJzdAojZGVm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