#include <bits/stdc++.h>
#define fi first
#define se second
#define all(v) v.begin() , v.end()
#define sz(v) int(v.size())
#define unq(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
using namespace std;
typedef long long ll;
typedef pair<int , int> ii;
typedef pair<long long , int> lli;
const int maxN = 4007;
const int mod = int(1e9)+7;
int add(int x , int y){
x += y;
if (x >= mod) x -= mod;
return x;
}
void self_add(int &x , int y){
x = add(x , y);
}
int sub(int x , int y){
x -= y;
if (x < 0) x += mod;
return x;
}
void self_sub(int &x , int y){
x = sub(x , y);
}
int mul(int x , int y){
return (1ll * x * y) % mod;
}
int n , m , a[maxN] , dp[maxN][maxN];
bool mark[maxN][maxN];
namespace sub1{
bool check(){
return (n <= 100 && m <= 400);
}
void solve(){
for (int i = 1 ; i <= n ; i++){
int cur = INT_MIN;
for (int j = i ; j <= n ; j++){
cur = max(cur , a[j]);
if (i > 1 && j < n){
mark[i - 1][j + 1] = (cur > max(a[i - 1] , a[j + 1]));
}
}
}
for (int i = 1 ; i <= n ; i++){
dp[i][a[i]] = 1;
for (int t = a[i] ; t <= m ; t++){
for (int j = 1 ; j < i ; j++){
if (mark[j][i] == 1) self_add(dp[i][t] , dp[j][t - a[i]]);
}
}
}
int ans = 1;
for (int i = 1 ; i <= n ; i++){
for (int t = 1 ; t <= m ; t++){
self_add(ans , dp[i][t]);
}
}
cout << ans << "\n";
}
}
namespace sub2{
int pre[maxN][maxN] , sum_pre[maxN];
bool del[maxN];
void solve(){
deque<int> dq;
for (int i = 1 ; i <= n ; i++){
while (dq.empty() == 0 && a[dq.back()] <= a[i]){
int j = dq.back();
for (int t = 1 ; t <= m ; t++){
self_sub(sum_pre[t] , pre[j][t]);
self_add(pre[i][t] , pre[j][t]);
}
if (a[j] < a[i]){
for (int t = 1 ; t <= m ; t++){
self_add(pre[i][t] , dp[j][t]);
}
}
else{
del[j] = 1;
for (int t = 1 ; t <= m ; t++){
self_add(dp[i][t] , dp[j][t]);
}
}
dq.pop_back();
}
self_add(dp[i][a[i]] , 1);
for (int t = a[i] ; t <= m ; t++){
self_add(dp[i][t] , sum_pre[t - a[i]]);
}
dq.push_back(i);
for (int t = 1 ; t <= m ; t++) self_add(sum_pre[t] , pre[i][t]);
}
int ans = 1;
for (int i = 1 ; i <= n ; i++){
for (int t = 1 ; t <= m ; t++){
if (del[i] == 0) self_add(ans , dp[i][t]);
}
}
cout << ans << "\n";
}
}
void solve(){
cin >> n >> m;
for (int i = 1 ; i <= n ; i++) cin >> a[i];
//if (sub1::check()) return sub1::solve();
return sub2::solve();
}
#define name "K"
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen(name".INP" , "r")){
freopen(name".INP" , "r" , stdin);
freopen(name".OUT" , "w" , stdout);
}
int t = 1; //cin >> t;
while (t--) solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgZmkgZmlyc3QKI2RlZmluZSBzZSBzZWNvbmQKI2RlZmluZSBhbGwodikgdi5iZWdpbigpICwgdi5lbmQoKQojZGVmaW5lIHN6KHYpIGludCh2LnNpemUoKSkKI2RlZmluZSB1bnEodikgc29ydChhbGwodikpOyB2LnJlc2l6ZSh1bmlxdWUoYWxsKHYpKSAtIHYuYmVnaW4oKSk7CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKdHlwZWRlZiBwYWlyPGludCAsIGludD4gaWk7CnR5cGVkZWYgcGFpcjxsb25nIGxvbmcgLCBpbnQ+IGxsaTsKCmNvbnN0IGludCBtYXhOID0gNDAwNzsKY29uc3QgaW50IG1vZCA9IGludCgxZTkpKzc7CgppbnQgYWRkKGludCB4ICwgaW50IHkpewogICAgeCArPSB5OwogICAgaWYgKHggPj0gbW9kKSB4IC09IG1vZDsKICAgIHJldHVybiB4Owp9Cgp2b2lkIHNlbGZfYWRkKGludCAmeCAsIGludCB5KXsKICAgIHggPSBhZGQoeCAsIHkpOwp9CgppbnQgc3ViKGludCB4ICwgaW50IHkpewogICAgeCAtPSB5OwogICAgaWYgKHggPCAwKSB4ICs9IG1vZDsKICAgIHJldHVybiB4Owp9Cgp2b2lkIHNlbGZfc3ViKGludCAmeCAsIGludCB5KXsKICAgIHggPSBzdWIoeCAsIHkpOwp9CgppbnQgbXVsKGludCB4ICwgaW50IHkpewogICAgcmV0dXJuICgxbGwgKiB4ICogeSkgJSBtb2Q7Cn0KCmludCBuICwgbSAsIGFbbWF4Tl0gLCBkcFttYXhOXVttYXhOXTsKYm9vbCBtYXJrW21heE5dW21heE5dOwoKbmFtZXNwYWNlIHN1YjF7CiAgICBib29sIGNoZWNrKCl7CiAgICAgICAgcmV0dXJuIChuIDw9IDEwMCAmJiBtIDw9IDQwMCk7CiAgICB9CgogICAgdm9pZCBzb2x2ZSgpewogICAgICAgIGZvciAoaW50IGkgPSAxIDsgaSA8PSBuIDsgaSsrKXsKICAgICAgICAgICAgaW50IGN1ciA9IElOVF9NSU47CiAgICAgICAgICAgIGZvciAoaW50IGogPSBpIDsgaiA8PSBuIDsgaisrKXsKICAgICAgICAgICAgICAgIGN1ciA9IG1heChjdXIgLCBhW2pdKTsKICAgICAgICAgICAgICAgIGlmIChpID4gMSAmJiBqIDwgbil7CiAgICAgICAgICAgICAgICAgICAgbWFya1tpIC0gMV1baiArIDFdID0gKGN1ciA+IG1heChhW2kgLSAxXSAsIGFbaiArIDFdKSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZm9yIChpbnQgaSA9IDEgOyBpIDw9IG4gOyBpKyspewogICAgICAgICAgICBkcFtpXVthW2ldXSA9IDE7CiAgICAgICAgICAgIGZvciAoaW50IHQgPSBhW2ldIDsgdCA8PSBtIDsgdCsrKXsKICAgICAgICAgICAgICAgIGZvciAoaW50IGogPSAxIDsgaiA8IGkgOyBqKyspewogICAgICAgICAgICAgICAgICAgIGlmIChtYXJrW2pdW2ldID09IDEpIHNlbGZfYWRkKGRwW2ldW3RdICwgZHBbal1bdCAtIGFbaV1dKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpbnQgYW5zID0gMTsKICAgICAgICBmb3IgKGludCBpID0gMSA7IGkgPD0gbiA7IGkrKyl7CiAgICAgICAgICAgIGZvciAoaW50IHQgPSAxIDsgdCA8PSBtIDsgdCsrKXsKICAgICAgICAgICAgICAgIHNlbGZfYWRkKGFucyAsIGRwW2ldW3RdKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBjb3V0IDw8IGFucyA8PCAiXG4iOwogICAgfQp9CgpuYW1lc3BhY2Ugc3ViMnsKICAgIGludCBwcmVbbWF4Tl1bbWF4Tl0gLCBzdW1fcHJlW21heE5dOwogICAgYm9vbCBkZWxbbWF4Tl07CgogICAgdm9pZCBzb2x2ZSgpewogICAgICAgIGRlcXVlPGludD4gZHE7CiAgICAgICAgZm9yIChpbnQgaSA9IDEgOyBpIDw9IG4gOyBpKyspewogICAgICAgICAgICB3aGlsZSAoZHEuZW1wdHkoKSA9PSAwICYmIGFbZHEuYmFjaygpXSA8PSBhW2ldKXsKICAgICAgICAgICAgICAgIGludCBqID0gZHEuYmFjaygpOwogICAgICAgICAgICAgICAgZm9yIChpbnQgdCA9IDEgOyB0IDw9IG0gOyB0KyspewogICAgICAgICAgICAgICAgICAgIHNlbGZfc3ViKHN1bV9wcmVbdF0gLCBwcmVbal1bdF0pOwogICAgICAgICAgICAgICAgICAgIHNlbGZfYWRkKHByZVtpXVt0XSAsIHByZVtqXVt0XSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoYVtqXSA8IGFbaV0pewogICAgICAgICAgICAgICAgICAgIGZvciAoaW50IHQgPSAxIDsgdCA8PSBtIDsgdCsrKXsKICAgICAgICAgICAgICAgICAgICAgICAgc2VsZl9hZGQocHJlW2ldW3RdICwgZHBbal1bdF0pOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGVsc2V7CiAgICAgICAgICAgICAgICAgICAgZGVsW2pdID0gMTsKICAgICAgICAgICAgICAgICAgICBmb3IgKGludCB0ID0gMSA7IHQgPD0gbSA7IHQrKyl7CiAgICAgICAgICAgICAgICAgICAgICAgIHNlbGZfYWRkKGRwW2ldW3RdICwgZHBbal1bdF0pOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGRxLnBvcF9iYWNrKCk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgc2VsZl9hZGQoZHBbaV1bYVtpXV0gLCAxKTsKICAgICAgICAgICAgZm9yIChpbnQgdCA9IGFbaV0gOyB0IDw9IG0gOyB0KyspewogICAgICAgICAgICAgICAgc2VsZl9hZGQoZHBbaV1bdF0gLCBzdW1fcHJlW3QgLSBhW2ldXSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZHEucHVzaF9iYWNrKGkpOwogICAgICAgICAgICBmb3IgKGludCB0ID0gMSA7IHQgPD0gbSA7IHQrKykgc2VsZl9hZGQoc3VtX3ByZVt0XSAsIHByZVtpXVt0XSk7CiAgICAgICAgfQogICAgICAgIGludCBhbnMgPSAxOwogICAgICAgIGZvciAoaW50IGkgPSAxIDsgaSA8PSBuIDsgaSsrKXsKICAgICAgICAgICAgZm9yIChpbnQgdCA9IDEgOyB0IDw9IG0gOyB0KyspewogICAgICAgICAgICAgICAgaWYgKGRlbFtpXSA9PSAwKSBzZWxmX2FkZChhbnMgLCBkcFtpXVt0XSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgY291dCA8PCBhbnMgPDwgIlxuIjsKICAgIH0KfQoKdm9pZCBzb2x2ZSgpewogICAgY2luID4+IG4gPj4gbTsKICAgIGZvciAoaW50IGkgPSAxIDsgaSA8PSBuIDsgaSsrKSBjaW4gPj4gYVtpXTsKICAgIC8vaWYgKHN1YjE6OmNoZWNrKCkpIHJldHVybiBzdWIxOjpzb2x2ZSgpOwogICAgcmV0dXJuIHN1YjI6OnNvbHZlKCk7Cn0KCiNkZWZpbmUgbmFtZSAiSyIKCmludCBtYWluKCl7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApOyBjaW4udGllKDApOyBjb3V0LnRpZSgwKTsKICAgIGlmIChmb3BlbihuYW1lIi5JTlAiICwgInIiKSl7CiAgICAgICAgZnJlb3BlbihuYW1lIi5JTlAiICwgInIiICwgc3RkaW4pOwogICAgICAgIGZyZW9wZW4obmFtZSIuT1VUIiAsICJ3IiAsIHN0ZG91dCk7CiAgICB9CiAgICBpbnQgdCA9IDE7IC8vY2luID4+IHQ7CiAgICB3aGlsZSAodC0tKSBzb2x2ZSgpOwogICAgcmV0dXJuIDA7Cn0KCg==