#include using namespace std; const int N = 2005, mod = 998244353; int n, d[N], dp[N][N]; char c; int main(){ cin >> n; dp[0][n] = 1; for(int i = 1; i <= n; ++i){ cin >> c; for(int j = 0; j <= n; ++j){ d[j] = 0; } for(int j = 0; j <= n; ++j){ if(c == '1'){ if(j){ dp[i][j - 1] = (dp[i][j - 1] + 1ll * dp[i - 1][j] * j % mod) % mod; } } else{ dp[i][j] = (dp[i][j] + 1ll * dp[i - 1][j] * max(0, n - i + 1 - j) % mod) % mod; d[0] = (d[0] + dp[i - 1][j]) % mod; d[j] = (d[j] + mod - dp[i - 1][j]) % mod; } } for(int j = 0; j <= n; ++j){ d[j] = ((j ? d[j - 1] : 0) + d[j]) % mod; dp[i][j] = (dp[i][j] + d[j]) % mod; } } cout << dp[n][0]; return 0; }