#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) using ll = long long; constexpr int inf=1e9+7; constexpr ll longinf=1LL<<60 ; constexpr ll mod=1e9+7 ; ll powmod(ll n,ll k, ll p){ ll ret=1; while(k){ if(k&1)ret=ret*n%p; n=n*n%p; k>>=1; } return ret; } ll gcd(ll x,ll y){ return y?gcd(y,x%y):x; } ll dp[501][100001]; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int p,n,k,b; cin>>p>>n>>k>>b; int m=p-1; k = gcd(k,p-1); vector div; for(int i=2;i c; rep(i,(p-1)/k)c.push_back(powmod(r,k*i,p)); vector par(p,-1); rep(i,p){ if(par[i]!=-1)continue; for(auto e:c)par[i*e%p]=i; } vector d((p-1)/k); rep(i,(p-1)/k)d[i]=powmod(r,k*i,p); dp[0][0]=1; rep(i,n){ int x; cin>>x; rep(j,p){ if(dp[i][j]==0)continue; dp[i][j]%=mod; rep(l,(p-1)/k)dp[i+1][par[(j+x*d[l])%p]]+=dp[i][j]*k; dp[i+1][j]+=dp[i][j]; } } if(b==0)cout<