#include #include #include using namespace std; using ll = long long; using mint = atcoder::modint998244353; using maxt = atcoder::modint1000000007; int main() { int N, K; cin >> N >> K; vector A(N); ll sum = 0; for(int &o : A) { cin >> o; sum += o; } ll a = 0; ll tmp = 1; for(int i = N - 1; i >= 0; i--) { a += A.at(i) * tmp; tmp *= K; } cout << a % sum << endl; }