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

namespace ConsoleApplication1
{
    class Program
    {

        static void Main(string[] args)
        {
            int n, k;
            long zbir = 0;
            string[] s = Console.ReadLine().Split();
            n = int.Parse(s[0]);
            k = int.Parse(s[1]);
            int[] a = new int[n];
            s = Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
                a[i] = int.Parse(s[i]);
            if (k == 0)
            {
                for (int i = 0; i < n; i++)
                    zbir += a[i];
                Console.WriteLine(zbir % 1000000007);
            }
            else if (k == 1)
            {
                for (int i = 0; i < n; i++)
                    for (int j = 0; j <= i; j++)
                        for (int m = j; m <= i; m++)
                            zbir += a[m];
                Console.WriteLine(zbir % 1000000007);
            }
            else
                Console.WriteLine(5);
        }
    }
}