#include #include #include #include #include #include #include #include #include #include #define ll long long #define db double using namespace std; const ll N = 1e5 + 100; ll tt,n,m,b,dp[N]; ll ksm(ll p,ll q) { ll res = 1; if (p == 0) { return 0; } while(q) { if (q & 1) { res *= p; res %= b; } p *= p; p %= b; q /= 2; } return res; } void solve() { scanf("%lld%lld%lld",&n,&m,&b); m %= b; dp[0] = 0; for (ll i = 1;i <= n;i++) { dp[i] = (dp[i - 1] + 1) % b; ll x; scanf("%lld",&x); dp[i] *= ksm(m,x); dp[i] %= b; } ll ans = 1; for (ll i = 1;i <= n;i++) { ans += dp[i]; ans %= b; } printf("%lld\n",ans); } int main() { tt = 1; while(tt) { solve(); tt--; } return 0; }