#include <bits/stdc++.h>
using namespace std;

#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define inf INT_MAX
#define llinf LLONG_MAX
#define mt make_tuple
#define parll pair<ll,ll>
#define parii pair<int,int>
#define mp make_pair
#define mod 1000000007

int n,k;

ll Nula( int A[] )
{
    ll suma = 0;
    for ( int i = 1; i <= n; i++ )
    {
        suma = (suma+A[i])%mod;
    }
    return suma;
}

ll Prvi( int A[] )
{
    ll suma=0,r;
    for ( int i = 1; i <= n; i++ )
    {
        r = (((n-i+1)*A[i])%mod*i)%mod;
        suma = (suma+r)%mod;
    }
    return suma;
}

int main()
{
    ios;

    cin >> n >> k;
    int A[n+1];
    for ( int i = 1; i <= n; i++ )
    {
        cin >> A[i];
    }

    if ( k == 0 )
    {
        cout << Nula(A);
        return 0;
    }
    if ( k == 1 )
    {
        cout << Prvi(A);
        return 0;
    }
    cout << 0;

    return 0;
}