#include using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) int main(){ ll n,k; cin>>n>>k; vectora(n); ll wa=0; rep(i,n){ cin>>a[i]; wa+=a[i]; } ll sum=0; ll bai=1; for(int i=n-1;i>=0;i--){ sum+=bai*a[i]; sum%=wa; bai*=k; bai%=wa; } ll ans=sum%wa; //cout<