N,K = map(int, input().split()) A = list(map(int, input().split())) mod = sum(A) temp = 0 for i in range(N): temp = (temp*K+A[i])%mod print(temp)