#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
using namespace std;
ll n,k,a[200005],mod=1e9+7,pref[200005],res;
void subtask1(){
  for(int i=1;i<=n;i++){
    for(int j=i;j<=n;j++){
         res+=pref[j]-pref[i-1]+mod;
         if(res>mod)res-=mod;
    }
  }
}
void subtask2(){
queue<pair<pair<ll,ll>,ll>>q;
q.push({{1,n},k});
while(q.size()){
    ll left=q.front().ff.ff;
    ll right=q.front().ff.ss;
    ll vr=q.front().ss;
    if(vr==0){
        res+=pref[right]-pref[left-1]+mod;
        if(res>mod)res-=mod;
    }
    else {
        for(int i=left;i<=right;i++){
            for(int j=i;j<=right;j++){
                q.push({{i,j},vr-1});
            }
        }
    }
    q.pop();
}
}
int main () {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
cin>>n>>k;
for(int i=1;i<=n;i++){
    cin>>a[i];
    pref[i]=pref[i-1]+a[i];
    if(pref[i]>mod)pref[i]-=mod;
}
if(k==1){
subtask1();
}
else {
subtask2();
}
cout<<res<<endl;
return 0;
}