#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;

    int* a = (int*)calloc(n, sizeof(int));

    long long suma(0);
    if (k == 0)
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        suma += a[i] % 1000000007;
    }
    else if (k == 1)
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        suma += (a[i] * (n-i) * (i+1)) % 1000000007;
    }

    cout << suma;

    return 0;
}