#include #include using namespace std; using mint = atcoder::modint998244353; // A : A[i] >= A[i+1] mint solve(vector A){ int H = A.size(); int sum = 0; for(int i=0; i cnt(A[0]+1, 0); for(int i=H-1; i>=0; i--){ for(int j=1; j<=A[i]; j++){ cnt[j]++; int w = A[i]-j+1; int h = cnt[j]; ret /= w+h-1; } } return ret; } int main(){ int n; cin >> n; vector a(n); int sum = 0; for(int i=0; i> a[i]; sum += a[i]; } if(sum%2 == 1){ cout << 0 << endl; return 0; } string s = string(a[0], '1') + "0"; for(int i=1; i A(1, 0), B(1, 0); for(int i=0; i<(int)s.size(); i++){ if(s[i] == '1'){ A.back()++; } else{ A.push_back(A.back()); } swap(A, B); } A.pop_back(); B.pop_back(); reverse(A.begin(), A.end()); reverse(B.begin(), B.end()); int suma = 0, sumb = 0; for(int x : A){ suma += x; } for(int y : B){ sumb += y; } mint ans = solve(A)*solve(B); for(int i=1; i<=suma+sumb; i++) ans *= i; for(int i=1; i<=suma; i++) ans /= i; for(int i=1; i<=sumb; i++) ans /= i; cout << ans.val() << endl; }