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