#pragma GCC target("avx") // CPU 処理並列化 #pragma GCC optimize("O3") // CPU 処理並列化 #pragma GCC optimize("unroll-loops") // 条件処理の呼び出しを減らす #include #include // #include // cout, endl, cin // #include // string, to_string, stoi // #include // vector // #include // min, max, swap, sort, reverse, lower_bound, upper_bound // #include // pair, make_pair // #include // tuple, make_tuple // #include // int64_t, int*_t // #include // printf // #include // map // #include // queue, priority_queue // #include // set // #include // stack // #include // deque // #include // unordered_map // #include // unordered_set // #include // bitset // #include // #include // #include // #include // #include // #include using namespace std; #define int long long #define pb push_back #define eb emplace_back // #define F first // #define S second #define FOR(i,a,b) for(int (i)=(a);(i)<(int)(b);(i)++) #define rep(i,n) FOR(i,0,n) #define RFOR(i,a,b) for(int (i)=(a);(i)>=(int)(b);(i)--) #define rrep(i,n) RFOR(i,n,0) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define ve vector #define vi vector #define vp vector> #define vvi vector> #define UNIQUE(a) sort(all(a)), a.erase(unique(all(a)), a.end()) #define Double double // #define endl '\n' template using pq = priority_queue,greater>; using ll = long long; using UnWeightedGraph = vector>; ll INF = LLONG_MAX / 4 - 100; int IINF = INT_MAX / 4; ll mod = 1e9 + 7; int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1}; vector prime; long double pi = 3.141592653589793238; class fact { public: long long fmod = 1e9+7; vector fac, finv, inv; fact (int n, long long Mod = 1e9+7) { fmod = Mod; fac = vector(n + 1, 0); finv = vector(n + 1, 0); inv = vector(n + 1, 0); fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < n + 1; i++) { fac[i] = fac[i-1] * i % fmod; inv[i] = mod - inv[mod%i] * (mod/i) % mod; finv[i] = finv[i-1] * inv[i] % mod; } } ll nCr(ll n, ll r) {if(n < r) return 0; return fac[n] * finv[r] % fmod * finv[n-r] % fmod;} ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;} inline int operator [] (int i) {return fac[i];} ll DeBuG(ll n, ll r); }; void DEBUG(vector a) {for(int i=0;i 0) {if (b & 1) {c = a * c%mod;}a = a * a%mod; b >>= 1;}return c;} void PRI(ll n) {bool a[n + 1]; for (int i = 0; i < n + 1; i++) {a[i] = 1;}for (int i = 2; i < n + 1; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}} template T chmin(T& a, T b) {if(a>b)a=b;return a;} template T chmax(T& a, T b) {if(a>19))^(t^(t>>8)) ); } uint64_t xor64(void) { static uint64_t x = 88172645463325252ULL; x = x ^ (x << 7); return x = x ^ (x >> 9); } int Old[6005], New[6005], A[6005]; void solve() { mod = 998244353; int n, q; cin >> n >> q; rep (i, n) cin >> A[i]; Old[0] = 1; rep (i, n) { rep (j, i+1) { New[j+1] += Old[j]; New[j] += Old[j] * (A[i]-1); } rep (j, i+2) Old[j] = New[j]%mod, New[j] = 0; } rep (i, q) { int a; cin >> a; cout << Old[a] << endl; } } signed main() { cin.tie(0); ios::sync_with_stdio(false); solve(); }