#include<bits/stdc++.h>usingnamespacestd;#define ll long long
intN,K;intM=1e9,MOD=1e9+7;vector<ll>v;vector<ll>ansv;inlinellfast_power(llbase,llpower){llresult=1;while(power>0){if(power%2==1){// Can also use (power & 1) to make code even fasterresult=(result*base)%MOD;}base=(base*base)%MOD;power=power/2;// Can also use power >>= 1; to make code even faster}returnresult;}lluse_dp(llval,lllen){vector<ll>dp(len+2);dp[1]=1,dp[0]=1;llx=M-val;for(inti=2;i<=len+1;i++){dp[i]=(dp[i-1]*(x+1))%MOD;if(i-K-1>=0){dp[i]=((dp[i]-(dp[i-K-1]*fast_power(x,K))%MOD)+MOD)%MOD;}}returndp[len+1]%MOD;}intmain(){ifstreamcin("tracking2.in");ofstreamcout("tracking2.out");cin>>N>>K;v.resize(N+1);for(lli=1;i<=N;i++){cin>>v[i];}llans=1;for(inti=1,j;i<=N-K+1;i=j+1){j=i;// i is start of new window, j is endingwhile(v[j+1]==v[i]){j++;}// len of curr windowlllen=j-i+1;// add extra K - 1 from next windowlen+=K-1;// check against previous window// special handling: skip first windowif(i>1&&v[i]<v[i-1]){// already calculated first K values in previous windowlen-=K;}// check against next window// special handling: skip last windowif(j<N-K+1&&v[j]<v[j+1]){// will calculate last K values in next windowlen-=K;}if(len>0){ans*=use_dp(v[i],len);ans%=MOD;}}cout<<ans;}