#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define endl "\n"

using namespace std;

const ll mod=1e9+7;

ll pref[2005];
ll A[2005];
int n;

ll mul(ll a, ll b) {
    return ((a%mod)*(b%mod))%mod;
}

ll mul(ll a, ll b, ll c) {
    return mul(mul(a,b),c);
}

ll add(ll a, ll b) {
    return (a%mod+b%mod)%mod;
}

ll suma(int L, int R) {
    if(!L)
        return pref[R];
    else
        return pref[R]-pref[L-1];
}

ll f(int k, int L, int R)
{
    if(!k)
        return suma(L,R);  //8 2 4 1 7 6 5   L=2 R=5
    if(k==1) {
        ll ret=0;
        for(int i=L;i<=R;i++) {
            ret=add(ret,mul(A[i],R+1-i,i+1-L));
        }
        return ret;
    }

    ll gotovo=0;
    for(int i=L;i<=R;i++) {
        for(int j=i;j<=R;j++) {
            gotovo=add(gotovo,f(k-1,i,j));
        }
    }

    return gotovo;
}

void solve()
{
    int k;
    cin >> n >> k;
    for(int i=0;i<n;i++) {
        cin >> A[i];
        if(i)
            pref[i]=pref[i-1]+A[i];
        else
            pref[i]=A[i];
    }

    if(n==1) {
        cout << A[0] << endl;
        return;
    }

    cout << f(k,0,n-1) << endl;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int t=1; //cin >> t;
    while(t--)
        solve();

    return 0;
}