f=lambda:[*map(int,input().split())] N,K=f() A=f() B=sum(A) u=0 for a in A:u=(u*K+a)%B print(u)