#line 1 "Main.cpp" #include #include #include #include #include #include #line 3 "nachia\\math\\combination.hpp" namespace nachia{ template class Comb{ private: std::vector F; std::vector iF; public: void extend(int newN){ int prevN = (int)F.size() - 1; if(prevN >= newN) return; F.resize(newN+1); iF.resize(newN+1); for(int i=prevN+1; i<=newN; i++) F[i] = F[i-1] * Modint::raw(i); iF[newN] = F[newN].inv(); for(int i=newN; i>prevN; i--) iF[i-1] = iF[i] * Modint::raw(i); } Comb(int n = 1){ F.assign(2, Modint(1)); iF.assign(2, Modint(1)); extend(n); } Modint factorial(int n) const { return F[n]; } Modint invFactorial(int n) const { return iF[n]; } Modint invOf(int n) const { return iF[n] * F[n-1]; } Modint comb(int n, int r) const { if(n < 0 || n < r || r < 0) return Modint(0); return F[n] * iF[r] * iF[n-r]; } Modint invComb(int n, int r) const { if(n < 0 || n < r || r < 0) return Modint(0); return iF[n] * F[r] * F[n-r]; } Modint perm(int n, int r) const { if(n < 0 || n < r || r < 0) return Modint(0); return F[n] * iF[n-r]; } Modint invPerm(int n, int r) const { if(n < 0 || n < r || r < 0) return Modint(0); return iF[n] * F[n-r]; } Modint operator()(int n, int r) const { return comb(n,r); } }; } // namespace nachia #line 8 "Main.cpp" using namespace std; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; #define rep(i,n) for(int i=0; i<(int)(n); i++) const i64 INF = 1001001001001001001; using Modint = atcoder::static_modint<998244353>; nachia::Comb comb(3000); Modint hook(string s){ vector A, B; int a = 0, b = 0; for(char c : s) if(c == '0') a++; for(char c : s){ if(c == '0'){ B.push_back(b); a--; } if(c == '1'){ A.push_back(a); b++; } } reverse(B.begin(), B.end()); int lambda = 0; for(int a : A) lambda += a; Modint ans = comb.factorial(lambda); rep(i,A.size()) rep(j,B.size()){ if(A[i] <= j || B[j] <= i) continue; ans *= comb.invOf(A[i] + B[j] - i - j - 1); } return ans; } int opcount(string s){ int ans = 0; rep(i,s.size()) rep(j,i) if(s[i] == '0' && s[j] == '1') ans++; return ans; } int main(){ int N; cin >> N; vector A(N+1); rep(i,N) cin >> A[i+1]; string S; rep(i,N){ rep(j,A[i+1]-A[i]) S.push_back('1'); S.push_back('0'); } string S2[2]; rep(i,S.size()) S2[i%2].push_back(S[i]); Modint ans = hook(S2[0]) * hook(S2[1]); ans *= comb.comb(opcount(S2[0]) + opcount(S2[1]), opcount(S2[0])); rep(t,2) sort(S2[t].begin(), S2[t].end()); string S3; rep(i,S.size()) S3.push_back(S2[i%2][i/2]); if(S3.find("10") != string::npos) ans = 0; cout << ans.val() << '\n'; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance;