N, K = map(int, input().split()) A = list(map(int, input().split())) ans = 0 mod = sum(A) p = 1 for i in range(N): ans += p * A.pop() ans %= mod p *= K p %= mod print(ans)