#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int mxN = 1e3, MOD = 1e9+7;
int n, k;
ll a[mxN+10], pre[mxN+10], previous[mxN+10][mxN+10], curr[mxN+10][mxN+10];


int main(){

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

    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    pre[0] = 0;
    for (int i = 1; i <= n; i++)
        pre[i] = pre[i-1] + a[i-1], pre[i] %= MOD;

    previous[0][n-1] = 1;
    for (int i = 1; i <= k; i++){
        for (int i = 0; i < n; i++){
            for (int j = n-1; j >= i; j--){
                curr[i][j] = previous[i][j];
                if (i > 0) curr[i][j] += curr[i-1][j];
                if (j < n-1) curr[i][j] += curr[i][j+1];
                if (i > 0 && j < n-1) curr[i][j] -= curr[i-1][j+1];
                curr[i][j] %= MOD;
            }
        }
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                swap(previous[i][j], curr[i][j]);
    }

    ll ans = 0;
    for (int i = 0; i < n; i++)
        for (int j = i; j < n; j++)
            ans += (previous[i][j] * (pre[j+1] - pre[i])) % MOD, ans %= MOD;

    cout << ans << '\n';

    return 0;
}