/*#include<bits/stdc++.h>
#define ll long long
#define MOD 1000000007
using namespace std;
ll N,K,niz[200005],prefiks[200005],koliko[200005],pamti[305][305][305];
ll uradi(int k,int l,int r){
    ll ret=0;
    pamti[k][l][r]++;
   // if(pamti[k][l][r]!=-1)
    //    return pamti[k][l][r];
   // cout<<"uradi("<<k<<","<<l<<","<<r<<")"<<endl;
    if(k==0){
        for(int i=l;i<=r;i++)
            koliko[i]++;
       // pamti[k][l][r]=prefiks[r]-prefiks[l-1];
        return prefiks[r]-prefiks[l-1];
    }
    for(int i=l;i<=r;i++)
        for(int j=i;j<=r;j++)
            ret=(ret+uradi(k-1,i,j))%MOD;

   // pamti[k][l][r]=ret;
    return ret;
}
int main(){
    ios_base::sync_with_stdio(false);
    memset(pamti,0,sizeof(pamti));
    cin>>N>>K;
    for(int i=1;i<=N;i++){
        cin>>niz[i];
        prefiks[i]=(prefiks[i-1]+niz[i])%MOD;
    }
    if(K==1){
        ll res=0;
        for(int i=1;i<=N;i++)
            res=(res+(((i)*(N-i+1))%MOD)*niz[i])%MOD;
        cout<<res<<endl;
        return 0;
    }
    cout<<uradi(K,1,N)<<endl;
    for(int i=1;i<=N;i++)
        cout<<i<<" "<<koliko[i]<<endl;
    for(int mk=0;mk<=K;mk++){
        cout<<mk<<endl;
        for(int i=1;i<=N;i++){
            for(int j=1;j<=N;j++){
                if(pamti[mk][i][j]<1000)
                    cout<<" ";
                if(pamti[mk][i][j]<100)
                    cout<<" ";
                if(pamti[mk][i][j]<10)
                    cout<<" ";
                cout<<pamti[mk][i][j]<<" ";
            }
            cout<<endl;
        }
    }
    return 0;
}*/
/*
5 3
1 6 3 4 7
*/

#include<bits/stdc++.h>
#define ll long long
#define MOD 1000000007
using namespace std;
ll N,K,niz[200005],layer[2005][2005],prefiks[2005][2005];
bool pisi=false;
int main(){
    ios_base::sync_with_stdio(false);
    memset(layer,0,sizeof(layer));
    cin>>N>>K;
    layer[1][N]=1;
    for(int i=1;i<=N;i++){
        cin>>niz[i];
    }
    if(K==1){
        ll res=0;
        for(int i=1;i<=N;i++)
            res=(res+(((i)*(N-i+1))%MOD)*niz[i])%MOD;
        cout<<res<<endl;
        return 0;
    }
    for(int mk=K;mk>=0;mk--){
        if(pisi)
            cout<<mk<<endl;
        for(int i=1;i<=N;i++)
            for(int j=1;j<=N;j++)
                prefiks[i][j]=(prefiks[i][j-1]+prefiks[i-1][j]-prefiks[i-1][j-1]+layer[i][j])%MOD;
        for(int i=1;i<=N;i++)
            for(int j=i;j<=N;j++)
                layer[i][j]=(prefiks[i][N]-prefiks[i][j-1])%MOD;
        if(pisi)
            for(int i=1;i<=N;i++){
                for(int j=1;j<=N;j++){
                    if(layer[i][j]<1000)
                        cout<<" ";
                    if(layer[i][j]<100)
                        cout<<" ";
                    if(layer[i][j]<10)
                        cout<<" ";
                    cout<<layer[i][j]<<" ";
                }
                cout<<endl;
            }
    }
    ll res=0;
    for(int i=1;i<=N;i++)
        res=(res+(layer[i][i]*niz[i])%MOD)%MOD;
    cout<<res<<endl;
    return 0;
}
/*
5 3
1 6 3 4 7
*/