n, k = map(int, input().split()) alst = list(map(int, input().split())) MOD = sum(alst) ans = 0 times = 1 for a in alst[::-1]: ans += a * times ans %= MOD times *= k times %= MOD print(ans)