using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication69
{
    class Program
    {
        static int f(int[] a, int k, int l, int d)
        {
            if (k == 1)
            {
                int s = 0;
                for (int i = l; i <= d; i++) 
                {
                    s += a[i] * (d + 1 - i) * (i - l + 1);
                }
                return (s);
            }
            else
            {
                int s = 0;
                for (int i = l; i <= d; i++)
                {
                    for(int j = i;j<=d; j++)
                    {
                        s += f(a, k - 1, i, j);
                    }
                }
                return (s);
            }
        }
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int n = int.Parse(s[0]);
            int k = int.Parse(s[1]);
            int[] a = new int[n];
            int s1 = 0; 
            s = Console.ReadLine().Split();
            if(k==0)
            { 
                for(int i = 0; i<n; i++)
                {
                    a[i] = int.Parse(s[i]);
                    s1 += a[i];
                }
                Console.WriteLine(s1);
            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    a[i] = int.Parse(s[i]);
                }
                Console.WriteLine(f(a, k, 0, n - 1)%1000000007);
            }
            Console.ReadKey();
        }
    }
}