using System;

namespace ConsoleApp34
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            UInt64 n, k, i = 0,j=0,sum=0,sumP=0;
            n = UInt64.Parse(s[0]);
            k = UInt64.Parse(s[1]);
            string[] niz = Console.ReadLine().Split();
            UInt64[] a=new UInt64[n];
            for (i = 0; i < n; i++)
            {
                a[i] = UInt64.Parse(niz[i]);
            }
            if (k < 1)
            {
                for (i = 0; i < n; i++)
                {
                    sum += a[i];
                }
            }
            else
            {
                for (i = 0; i < n; i++)
                {
                    sumP = 0;
                    for (j = i; j < n; j++)
                    {
                        sum += (sumP + a[j]);
                        sumP += a[j];
                    }
                }
            }
            Console.WriteLine(sum%(1000000007));
            Console.ReadLine();
        }
    }
}