#include #include using namespace std; void ins() {} templatevoid ins(T& v,Rest&... rest){cin>>v;ins(rest...);} #define rep(i,n) for(int i=0,_i=(n);i<_i;++i) #define rrep(i,n) for(long long i=(n);i>=0;--i) int N, Q; int A[6000]; template struct MInt { long long val; constexpr MInt(long long val = 0) : val(val % MOD) { if (val < 0) val += MOD; } MInt operator+(const MInt& n) const { return MInt(val) += n; } MInt operator*(const MInt& n) const { return MInt(val) *= n; } MInt& operator+=(const MInt& n) { val = (val + n.val) % MOD; return *this; } MInt& operator*=(const MInt& n) { val = (val * n.val) % MOD; return *this; } friend ostream& operator<<(ostream& os, const MInt& n) { os<; int main() { ins(N, Q); vector dp(N+1); rep(i, N) { cin >> A[i]; } dp[0] = 1; dp[1] = 0; rrep(i, N-1) { vector dp_next(N+1); rep(j, N+1-i) { dp_next[j] = dp[j] * (A[i]-1); if (j >= 1) { dp_next[j] = dp[j-1] + dp_next[j]; } } swap(dp, dp_next); } rep(q, Q) { int B; cin >> B; cout << dp[B] << endl; } return 0; }