#include using namespace std; #define int long long const int N = 2e3 + 5, mod = 998244353; int dp[N][N], sum[N][N], n; char a[N]; signed main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } dp[0][n] = 1; for (int i = 1; i <= n; i++) { sum[0][i] = 1; } for (int i = 1; i <= n; i++) { for (int j = 0; j <= n; j++) { if (a[i] == '0') { dp[i][j] = sum[i - 1][j + 1] + dp[i - 1][j] * (n - i + 1 - j) % mod; dp[i][j] %= mod; } else { dp[i][j] = (j + 1) * dp[i - 1][j + 1] % mod; } } for (int j = n; j >= 0; j--) { sum[i][j] = sum[i][j + 1] + dp[i][j]; sum[i][j] %= mod; } } cout << dp[n][0]; return 0; }