#include using namespace std; typedef long long ll; typedef pair l_l; typedef pair i_i; template inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } template inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } const long double EPS = 1e-10; const long long INF = 1e18; const long double PI = acos(-1.0L); //const ll mod = 1000000007; #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair P; ll powmod(ll a, ll k, ll mod){ ll ap=a, ans=1; while(k){ if(k&1){ ans*=ap; ans%=mod; } ap=ap*ap; ap%=mod; k>>=1; } return ans; } ll inv(ll a, ll mod){ return powmod(a, mod-2, mod); } template struct NTT{ ll zeta[30]; NTT(){ int k=0; while(!((MOD-1)&(1<>k, MOD); for(int i=k-1; i>=0; i--) zeta[i]=zeta[i+1]*zeta[i+1]%MOD; } vector fft(vector a, int k, bool inverse=false){ int n=a.size(); vector tmp(n); for(int t=1; t<=k; t++){ ll w=1, z=zeta[t]; if(inverse) z=inv(z, MOD); for(int i=0; i multiply(vector a, vector b){ int n=a.size()+b.size()-1, k=0; while((1< c(n); for(int i=0; i ntt1; NTT ntt2; NTT ntt3; vector multiply(vector a, vector b){ /* cerr << "--------NTT--------" << endl; for(auto val : a) cerr << val << " "; cerr << endl; for(auto val : b) cerr << val << " "; cerr << endl; */ int n=a.size(), m=b.size(); auto c1=ntt1.multiply(a, b); auto c2=ntt2.multiply(a, b); auto c3=ntt3.multiply(a, b); vector c(n+m-1); ll r2=inv(MOD1, MOD2), r3=inv(MOD1*MOD2%MOD3, MOD3); for(int i=0; i> p >> n >> k >> b; vector x(p); for(int i = 0; i < p; i++) { x[i] = powmod(i, k, p); } vector v(p); v[0] = 1; for(int i = 0; i < n; i++) { ll a; cin >> a; //cerr << i << " " << a << endl; vector w(p); for(ll i = 0; i < p; i++) { w[x[i] * a % p] += 1; } /* cerr << "w: "; for(int i = 0; i < p; i++) { cerr << w[i] << " "; } cerr << endl; */ v = multiply(v, w); /* for(auto val : v) { cerr << val << " "; } cerr << endl; */ for(int i = p; i < v.size(); i++) { v[i-p] += v[i]; } v.resize(p); /* for(auto val : v) { cerr << val << " "; } cerr << endl; */ } cout << v[b] << endl; return 0; }