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

namespace petilja_1feladat
{
    class Program
    {
        static void Main(string[] args)
        {
            string asd = Console.ReadLine();
            string[] asdTomb = asd.Split(' ');
            int N = Convert.ToInt32(asdTomb[0]);
            int k = Convert.ToInt32(asdTomb[1]);

            string asd2 = Console.ReadLine();
            string[] asd2Tomb = asd2.Split(' ');
            int[] sorozat = new int[N];

            for (int i = 0; i < N; i++)
            {
                sorozat[i] = Convert.ToInt32(asd2Tomb[i]);
            }

            int sum = 0;

            switch (k)
            {
                case 0:
                    for (int i = 0; i < N; i++)
                    {
                        sum += sorozat[i];
                    }
                    break;
                    
                case 1:
                    sum = szamol(sorozat);
                    break;

                default:
                    Console.WriteLine("2020")
                    break;
            }

            Console.WriteLine(sum % 1000000007);

        }

        static int szamol(int[] ertek)
        {
            int sum = 0;
            for(int i = 0; i < ertek.Length; i++)
            {
                int sum2 = 0;
                for (int j = i; j < ertek.Length; j++)
                {
                    int sum3 = 0;
                    for (int k = j; k < ertek.Length; k++)
                    {
                        sum3 += ertek[j];
                    }
                    sum2 += sum3;
                }
                sum += sum2;
            }
            return sum;
        }


    }
}