n,k = map(int, input().split()) A = list(map(int, input().split())) A.reverse() mod = sum(A) table = [0]*(10**5+1) table[0] = 1 for i in range(1, 10**5+1): table[i] = table[i-1]*k table[i] %= mod ans = 0 for i, a in enumerate(A): ans += a*table[i] ans %= mod print(ans)