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

namespace Takmicenje2Zadatak4
{
    class Program
    {
        static int zbir(List<int> listica, int n)
        {
            int ukupno = 0;
            List<int> lista = new List<int>();
            while (listica.Count != 0)
            {
                for (int i = 0; i < listica.Count; i++)
                {
                    lista.Add(listica[i]);
                    ukupno += lista.Sum();
                }
                lista.Clear();
                listica.RemoveAt(0);
            }
            return ukupno;
        }
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int n = int.Parse(s[0]);
            int nadamSeDaJeJedan = int.Parse(s[1]);
            List<int> lista = new List<int>();
            s = Console.ReadLine().Split();
            for (int i = 0; i < n; i++)
            {
                lista.Add(int.Parse(s[i]));
            }
            Random r = new Random();
            if (nadamSeDaJeJedan == 1)
                Console.WriteLine(zbir(lista, n));
            else Console.WriteLine(r.Next(1000));
        }
    }
}