#include using namespace std; #define int long long signed main(){ int N,K; cin>>N>>K; vector A(N); for(int i=0;i>A[i]; int sum = 0; for(int i=0;i=0;i--){ ans += (now*A[i])%sum; now *= K; now %= sum; } cout<