n,k=map(int,input().split()) L=list(map(int,input().split())) a=sum(L) b=0 for i in L:b=(b*k+i)%a print(b)