#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using pint = pair; //const ll mod = 1000000007; const ll mod = 998244353; const ld pi = 3.14159265358979; long long gcd(long long a,long long b){ if(a < b)swap(a , b); if(a == 0 || b == 0)return a; if(a % b == 0)return b; else return gcd(b , a%b); } int main() { //ios::sync_with_stdio(false); //cin.tie(0); //cout << fixed << setprecision(15); int n , k; cin >> n >> k; vector a(n); ll sum = 0; for(int i = 0; i < n; i++){ cin >> a[i]; sum += a[i]; } reverse(a.begin() , a.end()); ll ans = 0; ll kk = 1; for(int i = 0; i < n; i++){ if(i >= 1)kk *= k; kk %= sum; ans += kk * a[i]; ans %= sum; } cout << ans << endl; return 0; }