#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; int N, K, A[101010], powK[101010]; ll sum, ans; int main() { cin >> N >> K; for (int i = N; i >= 1; i--) { cin >> A[i]; sum += A[i]; } powK[1] = 1; for (int i = 2; i <= N; i++) { powK[i] = (powK[i - 1] * K) % sum; } for (int i = 1; i <= N; i++) { ans = (ans + (A[i] * powK[i]) % sum) % sum; } cout << ans << endl; return 0; }