#include #include #include #include using namespace std; using ll = long long; using namespace atcoder; using mint2 = modint998244353; vector rev(vector& f, ll mod) { vector res = { mint2(1) / f[0] }; ll t = 1; while (t < mod) { t *= 2; auto m = convolution(convolution(res, res), f); vector nres(t); for (ll i = 0; i < t; i++) { if (i < res.size()) nres[i] += 2 * res[i]; if (i < m.size()) nres[i] += -m[i]; } res = nres; } return res; } vector div(vector& f, vector& g) { auto rf = f; auto rg = g; reverse(rf.begin(), rf.end()); reverse(rg.begin(), rg.end()); ll siz = f.size() - g.size() + 1; if (siz <= 0) return f; auto rv = rev(rg, siz); auto q = convolution(rf, rv); if (q.size() > siz) q.resize(siz); reverse(q.begin(), q.end()); auto gq = convolution(g, q); auto res = f; for (ll i = 0; i < res.size(); i++) { if (i < gq.size()) res[i] -= gq[i]; } while (res.back() == 0 && res.size() > 1) res.pop_back(); return res; } int main() { ll n; cin >> n; vector a(n); for (ll i = 0; i < n; i++) cin >> a[i]; ll m = 1; while (m < n) m *= 2; vector def = { 1 }; vector> muls(m * 2, def); for (ll i = 0; i < n; i++) muls[i + m] = { a[i],-1 }; for (ll i = m - 1; i > 0; i--) muls[i] = convolution(muls[i * 2], muls[i * 2 + 1]); mint2 ans = 1; vector> divs(m * 2, def); for (ll i = 2; i < m + n; i++) { if (muls[i].size() <= 1) continue; divs[i] = convolution(divs[i], divs[i / 2]); if (i % 2) divs[i] = convolution(muls[i - 1], divs[i]); divs[i] = div(divs[i], muls[i]); if (m <= i) ans *= divs[i][0]; } cout << ans.val() << endl; return 0; }