using System.Linq; using System; public class Hello { static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var k = int.Parse(line[1]); line = Console.ReadLine().Trim().Split(' '); var a = Array.ConvertAll(line, int.Parse); getAns(n, k, a); } static void getAns(int n, int k, int[] a) { var asum = a.Sum(); Array.Reverse(a); var p = 1L; var ans = 0L; for (int i = 0; i < n; i++) { ans += a[i] * (p % asum); ans %= asum; p *= k; } Console.WriteLine(ans); } }