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

namespace BUG
{
    class Program
    {
        static double KjeNula(int [] A, int n)
        {
            int Sum = 0;
            for (int i = 0; i < n; i++)
                Sum += A[i];
            return Sum;
        }
        static double KnijeNula(int[] A, int n)
        { 
            int Sum = 0;
            for (int j = 0; j < n; j++)
                for (int m = n; m > j; m--)
                    for (int i = j; i < m; i++)
                        Sum += A[i];
            return Sum;
        }
        static void Main(string[] args)
        {
            string[] niz, niz2;
            double Sum;
            niz = Console.ReadLine().Split();
            int n = int.Parse(niz[0]);
            int k = int.Parse(niz[1]);
            int[] A = new int[n];
            niz2 = Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
                A[i] = int.Parse(niz2[i]);
            if (k == 0)
                Sum = KjeNula(A, n);
            else
                Sum = KnijeNula(A, n);
            Sum %= (Math.Pow(10, 9) + 7);
            Console.WriteLine(Sum.ToString());
            Console.ReadKey();
        }
    }
}