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