using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, k) = (c[0], c[1]); var a = NList; var mod = a.Sum(); var mul = 1L; var ans = 0L; for (var i = 0; i < n; ++i) { ans = (ans + a[n - i - 1] * mul % mod) % mod; mul = mul * k % mod; } WriteLine(ans); } }