#include #include #include using namespace std; long long power(long long base, long long exp) { long long res = 1; base %= 998244353; while (exp > 0) { if (exp % 2 == 1) res = (res * base) % 998244353; base = (base * base) % 998244353; exp /= 2; } return res; } long long modInverse(long long n) { return power(n, 998244353 - 2); } int main() { int N; string S; cin >> N >> S; long long fact = 1; for (int i = 1; i <= N; i++) fact = (fact * i) % 998244353; int first_one = -1, last_zero = -1; for (int i = 0; i < N; i++) { if (S[i] == '1' && first_one == -1) first_one = i; if (S[i] == '0') last_zero = i; } // If no 0 exists after a 1, there are no constraints. if (first_one == -1 || last_zero == -1 || first_one > last_zero) { cout << fact << endl; return 0; } // Count 0s that have a 1 to their right int n0 = 0; for (int i = 0; i <= last_zero; i++) { if (S[i] == '0') n0++; } // Count 1s that have a 0 to their left int n1 = 0; for (int i = first_one; i < N; i++) { if (S[i] == '1') n1++; } // The number of ways to pick relative order for these n0 + n1 elements // is (n0 + n1)!, but only n0! * n1! of those are valid (where all n0 < all n1). // So we divide by (n0 + n1)C(n0). long long comb_den = 1; // Calculate (n0 + n1)! / (n0! * n1!) auto nCr = [&](int n, int r) { if (r < 0 || r > n) return 0LL; long long num = 1, den = 1; for (int i = 0; i < r; i++) { num = (num * (n - i)) % 998244353; den = (den * (i + 1)) % 998244353; } return (num * modInverse(den)) % 998244353; }; long long ans = (fact * modInverse(nCr(n0 + n1, n0))) % 998244353; cout << ans << endl; return 0; }