#include <iostream>

using namespace std;

int funkcija (int m, int n, int a[])
{
    int u = 0;
    for (int i = m; i <= n; i++)
        u += a[i];
    return u;
}

int main()
{
    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    if (k == 0)
    {
        int u = 0;
        for (int i = 0; i < n; i++)
            u += a[i];
        cout << u % (1000000000 + 7);
    }
    else
    {
        int rez = 0;
        for (int i = 0; i < n; i++)
        {
            for (int j = i; j < n; j++)
            {
                rez += funkcija (i, j, a);
            }
        }
        cout << rez % (1000000000 + 7);
    }
}