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 PyPy3 (2.4.0) (judge verdict: Accepted)

s = input()
N = len(s)
P = 998244353
B = 0
R = 0

Y = [[0] * (2*N+1) for _ in range(2*N+1)] # Block

for i in range(N):
    if s[i] == "0":
        R += 2
    elif s[i] == "1":
        B += 1
        R += 1
    else:
        B += 2
        
    # print(i, B, R)
    if R < i+1:
        for j in range(i+1-R):
            Y[R+1][j] = 1
    
    if B < i+1:
        for j in range(i+1-B):
            Y[j][B+1] = 1

X = [[0] * (B+1) for _ in range(R+1)]

for i in range(R+1):
    for j in range(B+1):
        if i == 0 and j == 0:
            X[i][j] = 1
            continue
        
        if Y[i][j]:
            continue
            
        if j > 0:
            X[i][j] += X[i][j-1]
        
        if i > 0:
            X[i][j] += X[i-1][j]
            
        X[i][j] %= P

print(X[-1][-1])