//Luka Mitrovic
#include <iostream>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <vector>
using namespace std;

int mod = 1000000007;
long long sum = 0;
int arr[10000];
int arr2[10000];


long long racunanje(int niz[], int k, int n) {
	//cout << "+1" << endl;
	if (k == 1) {
		int end = n-1;
		int mult = 1;
		int b2;
		for (int i = 0; i < n/2; i++,end--,mult++) { // i [0,3)
			int b = (n-i)*mult;
			b2 = b;
			//cout << arr[i] << " " << arr[end] << endl;
			sum = (sum + b*(niz[i] + niz[end]))%mod; //
		}
		b2 = (n - n/2)*mult;
		if (n%2 == 1) {
			sum = (sum + b2*niz[n/2])%mod;
		}
		//cout << "::" << sum << endl;
	} else {
		for (int i = 0; i < n; i++) {
			for (int j = i; j < n; j++) {
				for (int o = i, c = 0; o <= j; o++,c++) {
					arr2[c] = arr[o];
					//cout << arr2[c] << " ";
				}
				//cout << endl;
				//if (j == 0) j++;
				racunanje(arr2, k-1, j+1-i);
			}
		}
		return sum;
	}
	return 1;
}


int main() {

	int n,k;
	cin >> n >> k;

	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}

	if (k == 0) {
		for (int i = 0; i < n; i++) {
			sum = (sum + arr[i])%mod;
		}
	} else if (k == 1) {
		int end = n-1;
		int mult = 1;
		int b2;
		for (int i = 0; i < n/2; i++,end--,mult++) { // i [0,3)
			int b = (n-i)*mult;
			b2 = b;
			//cout << arr[i] << " " << arr[end] << endl;
			sum = (sum + b*(arr[i] + arr[end]))%mod; //
		}
		b2 = (n - n/2)*mult;
		if (n%2 == 1) {
			sum = (sum + b2*arr[n/2])%mod;
		} else {

		}
	} else {
		racunanje(arr, k, n);
	}
	
	cout << sum << endl;
}