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

using namespace std;

int N;
int k;
ll A[200010];
ll suma0;
ll suma1;
int puta1;
int puta2;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> N >> k;
	puta1 = 1;
	puta2 = N;
	for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        suma0 = (suma0 + A[i]) % 1000000007;
        suma1 = (suma1 + puta1 * puta2 * A[i]) % 1000000007;
        puta1++;
        puta2--;
    }
    if (k == 0)
        cout << suma0;
    else if (k == 1)
        cout << suma1;
	return 0;
}