#include #include using namespace atcoder; using ml=modint;using m1=std::vector; auto&operator>>(std::istream&i,ml&x){long long t;i>>t;x=t;return i;} auto&operator<<(std::ostream&o,const ml&x){return o<0;) #define FOR(i,...) for(au[i,i##O,i##E]=rng(0,__VA_ARGS__);i=i##O;i-=i##E) #define debug(...) pp(#__VA_ARGS__,__VA_ARGS__) #define JO(s,t) s##t #define jo(s,t) JO(s,t) #define I(...) template<__VA_ARGS__> #define J typename #define O operator #define au auto #define cs const #define ce constexpr #define ifc if ce #define rr return #define uu using uu std::tuple,std::cin,std::cout,std::deque,std::swap,std::move,std::bitset; uu std::begin,std::end,std::rbegin,std::minmax,std::gcd,std::lcm,std::is_same_v; uu std::array,std::true_type,std::false_type; I(J T)uu ilis=std::initializer_list; uu vo=void; vo solve(); uu bo=bool; uu is=std::istream;uu os=std::ostream; uu dd=long double;uu ll=long long; uu ull=unsigned long long; uu lll=__int128_t;uu ulll=__uint128_t; uu str=std::string; I(J T,J U=T)uu map=std::map; I(J T,J U=T)uu umap=std::unordered_map; ll oo=3e18,l998=998244353,l107=1e9+7; dd ee=1e-12; str sp=" ",nc="",nl="\n"; struct edg{ ll t,w;edg(){} edg(ll t,ll w=1):t(t),w(w){} friend os&O<<(os&o,cs edg&e){rr o<p):a(p.first),b(p.second){} bo O<(cs cp&c)cs{rr a!=c.a?a(cs cp&c)cs{rr a!=c.a?a>c.a:b>c.b;} friend os&O<<(os&o,cs cp&c){rr o<; I(J A,J B=A,J C=A)struct tr{ A a={};B b={};C c={}; tr(){} tr(A a,B b,C c):a(a),b(b),c(c){} bo O<(cs tr&t)cs{rr a!=t.a?a(cs tr&t)cs{rr a!=t.a?a>t.a:b!=t.b?b>t.b:c>t.c;} };uu tl=tr; I(J T,ll n,J...A)struct TP{uu t=J TP::t;}; I(J T,J...A)struct TP{uu t=tuple;}; I(J T,ll n)uu tp=J TP::t;I(ll n)uu tpl=tp; tpl<3>rng(bo s,ll a,ll b=oo,ll c=1){if(b==oo)b=a,a=0;rr{a,b-s,c};} I(J T)ll len(cs T&a){rr a.size();} I(J T)bo add(T&a,cs T&b){rr a+=b,1;} I(J T,J U)bo amax(T&a,cs U&b){rr ab?a=b,1:0;} I(J A,J B)ce bo same=is_same_v; I(J T)struct is_tp:false_type{}; I(J...A)struct is_tp>:true_type{}; I(J T)constexpr bo is_tp_v = is_tp::value; I(J T)struct is_ar:false_type{}; I(J T,ll n)struct is_ar>:true_type{}; I(J T)constexpr bo is_ar_v = is_ar::value; I(J T)struct is_cp:false_type{}; I(J A,J B)struct is_cp>:true_type{}; I(J T)constexpr bo is_cp_v = is_cp::value; I(J T)struct is_tr:false_type{}; I(J A,J B,J C)struct is_tr>:true_type{}; I(J T)constexpr bo is_tr_v = is_tr::value; I(J V)struct ve; I(J V)constexpr bo isv=0; I(J V)constexpr bo isv> =1; I(J V)constexpr bo isv> =1; I(J V)au pure_val(V){ifc(isv)rr pure_val(J V::value_type());else rr V();} I(J V)struct ve:std::vector{ uu std::vector::vector; uu pure_type=decltype(pure_val(J std::vector::value_type())); ve(cs std::vector&v={}){fe(v,e)this->eb(e);} au&O+=(cs ve&u){au&v=*this;fo(i,len(v))v[i]+=u[i];rr v;} au&O-=(cs ve&u){au&v=*this;fo(i,len(v))v[i]-=u[i];rr v;} I(J U)au&O+=(cs U&x){au&v=*this;fe(v,e)e+=x;rr v;} I(J U)au&O-=(cs U&x){au&v=*this;fe(v,e)e-=x;rr v;} au O+(cs ve&u){rr ve(*this)+=u;} au O-(cs ve&u){rr ve(*this)-=u;} I(J U)au O+(cs U&x){rr ve(*this)+=x;}au&O++(){rr*this+=1;} I(J U)au O-(cs U&x){rr ve(*this)-=x;}au&O--(){rr*this-=1;} au&O^=(cs ve&u){fe(u,e)this->eb(e);rr*this;} au O^(cs ve&u){rr ve(*this)^=u;} I(J U)au lower_bound(cs U&x){rr std::lower_bound(all(*this),x);} I(J U)au upper_bound(cs U&x){rr std::upper_bound(all(*this),x);} I(J U)ll arglb(cs U&x){rr lower_bound(x)-begin(*this);} I(J U)ll argub(cs U&x){rr upper_bound(x)-begin(*this);} ll argmax(){rr std::max_element(all(*this))-begin(*this);} ll argmin(){rr std::min_element(all(*this))-begin(*this);} vo af(V e={}){this->ep(begin(*this),e);} vo df(){this->erase(begin(*this));} I(bo f(pure_type&,cs pure_type&),J U)static au scan(cs U&v){ cpr; ifc(!isv)r={v,1}; else fe(v,x)if(au t=scan(x);t.b)!r.b?r=t,0:f(r.a,t.a); rr r; } au sum(){rr scan(*this).a;} au max(){rr scan(*this).a;} au min(){rr scan(*this).a;} vo fill(pure_type x={}){fill(*this,x);} au zt(){rr zt(*this);} au mb(){rr mb(*this);} friend is&O>>(is&i,ve&v){fe(v,e)i>>e;rr i;} friend os&O<<(os&o,cs ve&v){ str s=nl; ifc(!isv)s=sp;else ifc(isv)s+=nl; fe(v,e)o<){ ver; fe(*this,e)r.eb(e.de(b)); rr r; }else{ str r; fe(*this,e)r+=len(b)==1?e+b[0]:0<=e&&e&v,pure_type x={}){ fe(v,e)ifc(isv)fill(e,x);else e=x; } I(J U)static au zt(U v){ ifc(isv){fe(v,e)e=zt(e);fo(i,len(v)-1)v[i+1]+=v[i];}rr v; } I(J U)static au mb(U v){ ifc(isv){fe(v,e)e=mb(e);of(i,len(v)-1)v[i+1]-=v[i];}rr v; } }; I(J T)uu V1=ve; I(J T)uu V2=V1>; uu u1=V1; uu u2=V2; I(J T=ll,ll n,ll i=0)au vec(cs ll(&s)[n],T x={}){ ifc(n==i+1)rr V1(s[i],x); else{au X=vec(s,x);rr V1(s[i],X);} } I(ll n,J...A)vo resize(cs ll(&l)[n],A&...a){ ((a=vec(l,pure_val(a))),...); } I(J T)struct uset:std::unordered_set{ uset(cs V1&a={}){fe(a,e)this->ep(e);} friend os&O<<(os&o,cs uset&s){fe(s,e)o<{ set(cs V1&a={}){fe(a,e)this->ep(e);} auto ika_max(cs T&x){ auto p=this->upper_bound(x); rr p!=this->begin()?prev(p):this->end(); } auto ijo_min(cs T&x){ rr this->lower_bound(x); } auto between(cs T&l,cs T&r){ auto p=this->lower_bound(l),q=this->lower_bound(r); rr cp{p,q}; } friend os&O<<(os&o,cs set&s){fe(s,e)o<{ mset(cs V1&a={}){fe(a,e)this->ep(e);} vo uerase(cs T&x){if(this->contains(x))this->erase(this->find(x));} auto ika_max(cs T&x){ auto p=this->upper_bound(x); rr p!=this->begin()?prev(p):this->end(); } auto ijo_min(cs T&x){ rr this->lower_bound(x); } auto between(cs T&l,cs T&r){ auto p=this->lower_bound(l),q=this->lower_bound(r); rr cp{p,q}; } friend os&O<<(os&o,cs mset&s){fe(s,e)o<; I(J T)uu qmin=std::priority_queue,std::greater<>>; uu cls=V1;uu tls=V1;uu strs=V1;uu gra=V2; u1 dx{-1,0,1,0,-1,1,1,-1},dy{0,-1,0,1,-1,-1,1,1}; ll rnd(ll l,ll r=oo){ static ull x=76,y=53,z=20,w=41; ull t=x^(x<<11); x=y,y=z,z=w,w=(w^(w>>19))^(t^(t>>8)); rr r==oo?w%l:w%(r-l)+l;} bo odd(ll x){rr x&1;}bo eve(ll x){rr~x&1;} ll pwm1(ll x){rr 1-2*(x&1);}ll pw2(ll n){rr 1LL<>i&1;} ll l2(ulll x){x|=1;ll r=0;wh(x)x>>=1,++r;rr r;} ll l10(ulll x){x|=1;ll r=0;wh(x)x/=10,++r;rr r;} I(J T,J U,J V)bo in(T l,U x,V r){rr l<=x&&x=0?x/y:(x+1)/y-1;} I(J T)T cei(T x,T y){rr y<0?x=-x,y=-y:x<=0?x/y:(x-1)/y+1;} I(J T)T zz(T x){rr x<0?-x:x;}I(J T)T sq(T a){rr a*a;} I(J T)T&srt(T&a){sort(all(a));rr a;} I(J T)T&rv(T&a){reverse(all(a));rr a;} I(J T)T&rsr(T&a){rr rv(srt(a));} I(J T)T&uq(T&a){srt(a).erase(unique(all(a)),end(a));rr a;} I(J T)decltype(au)bg(T&a){rr*begin(a);} I(J T)decltype(au)rb(T&a){rr*rbegin(a);} I(J T)decltype(au)rb(T&a,ll x){rr*(rbegin(a)+x);} I(J T)au pof(T&q){au r=bg(q);q.pop_front();rr r;} I(J T)au pob(T&q){au r=rb(q);q.pop_back();rr r;} I(J T)au pot(T&a){au r=a.top();a.pop();rr r;} I(J...A)au max(cs A&...a){rr max(ilis>{a...});} I(J...A)au min(cs A&...a){rr min(ilis>{a...});} struct fio{fio(){ cin.tie(0)->sync_with_stdio(0); cout<&t){ apply([&](cs au&...a){ll i=0;(((o<&v){fe(v,e)o<&m){fe(m,e)o<>(is&i,V1&v){fe(v,e)i>>e;rr i;} I(J...A)vo li(A&...a){(cin>>...>>a);} I(J...A)vo vi(A&...a){fo(i,(len(a)&...))(cin>>...>>a[i]);} vo Yes(bo y=1){pp(y?"Yes":"No");}vo No(){Yes(0);} gra tog(cs u2&a){gra g;fe(a,e){g.eb();fe(e,v)rb(g).eb(v);}rr g;} u2 tou(cs gra&g){u2 a;fe(g,e){a.eb();fe(e,v,w)rb(a).eb(v);}rr a;} au gi(gra&g,ll m,bo y=0){ UV(m,a,b,c);--a,--b; fo(i,m)g[a[i]].eb(b[i],c[i]),!y?g[b[i]].eb(a[i],c[i]),0:0;rr tuple{a,b,c};} au gi(u2&g,ll m,bo y=0){ UV(m,a,b);--a,--b; fo(i,m)g[a[i]].eb(b[i]),!y?g[b[i]].eb(a[i]):0;rr tuple{a,b};} I(J G)au ti(G&g,bo y=0){rr gi(g,len(g)-1,y);} u1 en(cs str&s,cs str&b="a"){ u1 r;fe(s,e)r.eb(len(b)==1?e-b[0]:b.find_first_of(e));rr r;} u1 sien(cs str&b="a"){ST(s);rr en(s,b);} u2 en(cs strs&s,cs str&b="a"){u2 r;fe(s,e)r.eb(en(e,b));rr r;} u2 sien(ll n,cs str&b="a"){u2 r;fo(n)r.eb(sien(b));rr r;} I(J F)struct rec:F{ rec(F&&f):F(std::forward(f)){} I(J...A)decltype(au)O()(A&&...a)cs{ rr F::O()(*this,std::forward(a)...);}}; I(J...A)vo dec(A&...a){((--a),...);} u1 it(ll n,ll x=0){u1 a;fo(i,n)a.eb(i+x);rr a;} I(J...A)u1 zp(A&...a){ u1 v=(a^...);uq(v);([&](u1&u){fe(u,e)e=v.arglb(e);}(a),...);rr v;} I(J F,J...A)u1 vs(F f,A&...a){ u1 o=it((len(a)&...));sort(all(o),f); ([&](au&e){au c=e;fo(i,len(e))e[i]=c[o[i]];}(a),...);rr o;} I(J F)dd bsd(F f,dd o,dd n){fo(l2(zz(o-n)/ee)+5)(f((o+n)/2)?o:n)=(o+n)/2;rr o;} I(J F)ll bsl(F f,ll o,ll n){wh(zz(o-n)>1)(f((o+n)/2)?o:n)=(o+n)/2;rr o;} ll sqr(ll x){ll r=sqrt(zz(x-ee));wh(r+1<=x/(r+1))++r;rr r;} u1 divs(ll n){u1 r;fo(i,1,sqr(n)+1)if(n%i==0)r.eb(i),r.eb(n/i);rr uq(r);} cls fact(ll n){ umapm;fo(i,2,sqr(n)+1)wh(n%i==0)++m[i],n/=i;if(n>1)++m[n]; cls r;fe(m,e)r.eb(e);rr srt(r);} cls rle(cs u1&a){cls r;fe(a,e)len(r)&&e==rb(r).a?++rb(r).b:r.eb(e,1).b;rr r;} cls rce(u1 a){rr rle(srt(a));} lll pow(lll x,lll n,ll m=0){ lll r=1;wh(n)n&1?r*=x:r,x*=x,m?r%=m,x%=m:r,n>>=1;rr r;} int main(){ll T=1;fo(T)solve();} vo solve(){ LL(N,M,B); M%=B; ml::set_mod(B); UL(N,a); m1 b(N); fo(i,N)b[i]=ml(M).pow(a[i]); au dp=vec({N},ml()); dp[0]=1; fo(i,N)dp[i+1]+=dp[i]*(b[i]+1); pp(dp[N]); }