#include using namespace std; using ll = long long; int main(){ ll n, k; cin >> n >> k; vector a(n); for(int i = 0; i < n; i++) cin >> a[i]; ll digit = 0; for(int i = 0; i < n; i++) digit += a[i]; ll ans = 0; ll pow = 1; for(int i = 0; i < n; i++){ ans += (pow*a[n-1-i])%digit; ans %= digit; pow *= k; } ans = (ans+digit)%digit; cout << ans << endl; return 0; }