Problem:
Score : 900 points

Problem Statement

There are N Snukes lining up in a row.
You are given a string S of length N. The i-th Snuke from the front has two red balls if the i-th character in S is 0; one red ball and one blue ball if the i-th character in S is 1; two blue balls if the i-th character in S is 2.

Takahashi has a sequence that is initially empty. Find the number of the possible sequences he may have after repeating the following procedure 2N times, modulo 998244353:

Each Snuke who has one or more balls simultaneously chooses one of his balls and hand it to the Snuke in front of him, or hand it to Takahashi if he is the first Snuke in the row.

Takahashi receives the ball and put it to the end of his sequence.

Constraints

1 \leq |S| \leq 2000

S consists of 0,1 and 2.

Note that the integer N is not directly given in input; it is given indirectly as the length of the string S.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of the possible sequences Takahashi may have after repeating the procedure 2N times, modulo 998244353.

Sample Input 1

02

Sample Output 1

3

There are three sequences that Takahashi may have: rrbb, rbrb and rbbr, where r and b stand for red and blue balls, respectively.

Sample Input 2

1210

Sample Output 2

55

Sample Input 3

12001021211100201020

Sample Output 3

543589959

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define IL inline
using namespace std;
typedef long long LL;
typedef unsigned int U;
typedef unsigned long long LLU;
typedef pair<int,int> PII;
typedef long double LD;
IL LL read()
{
	LL x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*f;
}
#define io read()
const int mod=998244353;
const int N=2008;
char s[N];
int n; 
int nr[N*2],nb[N*2];
int f[N*2][N*2],ans;
IL void upd(int &x,int y)
{
	x+=y;
	if(x>=mod)	x-=mod;	
}
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;++i){
		int t=0,p=0;
		if(s[i]=='0')	t=2,p=0;
		else if(s[i]=='1')	t=1,p=1;
		else	t=0,p=2;
		nr[i]=nr[i-1]+t;	
		nb[i]=nb[i-1]+p;
	}
	for(int i=n+1;i<=n+n;++i){
		nr[i]=nr[n];
		nb[i]=nb[n];	
	}
	for(int i=1;i<=n+n;++i){
	//	cout<<"!!"<<i<<' '<<nr[i]<<' '<<nb[i]<<'\n';	
	}
	f[0][0]=1;
	for(int i=0;i<n+n;++i){
		for(int j=0;j<=i;++j){
			//cout<<i<<' '<<j<<' '<<f[i][j]<<'\n';
			if(nr[i+1]>j){
				upd(f[i+1][j+1],f[i][j]);
			}	
			if(nb[i+1]>i-j){
				upd(f[i+1][j],f[i][j]);	
			}
		}
	}
	for(int j=0;j<=n+n;++j){
		upd(ans,f[n+n][j]);	
	}
	printf("%d",ans);
	return 0;
}