#include using namespace std; typedef long long ll; typedef long double ld; #define rep(i,n) for (int i = 0; i < (n); ++i) templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> n >> q; vector a(n); ll mul=1; rep(i,n){ cin >> a[i]; a[i]%=mod; } vector dp(n+1,-1); dp[0]=1; for(int i=0;i tmp(n+1); for(int j=0;j<=n;j++){ if(dp[j]==-1){ continue; } (tmp[j]+=dp[j])%=mod; (tmp[j+1]+=(dp[j]*(a[i]-1+mod)%mod)%mod)%=mod; } for(int j=0;j<=n;j++){ dp[j]=tmp[j]; } } rep(i,q){ int b;cin >> b; cout << dp[n-b] << endl; } }