#include "bits/stdc++.h" using namespace std; namespace util { using ll = long long; using vl = std::vector; using pl = std::pair; constexpr long long kInf = std::numeric_limits::max() / 8; constexpr long long kMax = std::numeric_limits::max(); template inline bool UpdateMax(T &x, const U &y) { if (x < y) { x = y; return true; } return false; } template inline bool UpdateMin(T &x, const U &y) { if (x > y) { x = y; return true; } return false; } // verified inline long long Pow(long long x, long long n) { assert(n >= 0); if (x == 0) return 0; long long res = 1LL; while (n > 0) { if (n & 1) { assert(x != 0 && std::abs(res) <= kMax / std::abs(x)); res = res * x; } if (n >>= 1) { assert(x != 0 && std::abs(x) <= kMax / std::abs(x)); x = x * x; } } return res; } // verified inline long long Mod(long long n, const long long m) { // returns the "arithmetic modulo" // for a pair of integers (n, m) with m != 0, there exists a unique pair of // integer (q, r) s.t. n = qm + r and 0 <= r < |m| returns this r assert(m != 0); if (m < 0) return Mod(n, -m); if (n >= 0) return n % m; else return (m + n % m) % m; } inline long long Quotient(long long n, long long m) { // returns the "arithmetic quotient" assert((n - Mod(n, m)) % m == 0); return (n - Mod(n, m)) / m; } inline long long DivFloor(long long n, long long m) { // returns floor(n / m) assert(m != 0); if (m < 0) { n = -n; m = -m; } if (n >= 0) return n / m; else if (n % m == 0) return -(abs(n) / m); else return -(abs(n) / m) - 1; } inline long long DivCeil(long long n, long long m) { // returns ceil(n / m) assert(m != 0); if (n % m == 0) return DivFloor(n, m); else return DivFloor(n, m) + 1; } template inline T Sum(const std::vector &vec) { return std::accumulate(vec.begin(), vec.end(), T(0)); } } // namespace util using namespace util; inline long long PowMod(long long x, long long n, const long long m) { assert(n >= 0); assert(m != 0); if (x == 0) return 0; long long res = 1; x = Mod(x, m); while (n > 0) { if (n & 1) { assert(x == 0 || std::abs(res) <= kMax / std::abs(x)); res = Mod(res * x, m); } if (n >>= 1) { assert(x == 0 || std::abs(x) <= kMax / std::abs(x)); x = Mod(x * x, m); } } return res; } void solve() { ll n, m, b; cin >> n >> m >> b; vl a(n); for (ll i = 0; i < n; ++i) { cin >> a[i]; } ll ans = 1; for (ll i = 0; i < n; ++i) { ans *= PowMod(m, a[i], b) + 1; ans %= b; } cout << ans << '\n'; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(15); solve(); return 0; }