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# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.Yahoo2019
{
    class F
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string s = Read();
            int[] rCnt = new int[s.Length * 2 + 1];
            int[] bCnt = new int[s.Length * 2 + 1];
            for (int i = 0; i < s.Length; i++)
            {
                switch (s[i])
                {
                    case '0':
                        rCnt[i+1] = 2;
                        break;
                    case '1':
                        rCnt[i+1] = 1;
                        bCnt[i+1] = 1;
                        break;
                    case '2':
                        bCnt[i+1] = 2;
                        break;
                }
                if (i > 0)
                {
                    rCnt[i+1] += rCnt[i];
                    bCnt[i+1] += bCnt[i];
                }
            }
            for (int i = s.Length + 1; i <= s.Length * 2; i++)
            {
                rCnt[i] = rCnt[i - 1];
                bCnt[i] = bCnt[i - 1];
            }
            /*for (int i = 0; i < rCnt.Length; i++)
                Console.WriteLine(rCnt[i] + " " + bCnt[i]);*/
            int[,] dp = new int[s.Length * 2 + 1, s.Length * 2 + 1];
            //i個目まで取り，赤をj個取った時のパターン数
            int mask = 998244353;
            dp[0, 0] = 1;
            for (int i = 1; i <= s.Length * 2; i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    int red = j;
                    int blue = i - j;
                    if (red > rCnt[i] || blue > bCnt[i]) dp[i, j] = 0;
                    else
                    {
                        if (j == 0)
                        {
                            dp[i, j] = blue > bCnt[i] ? 0 : dp[i - 1, j];
                        }
                        else
                        {
                            if (red <= rCnt[i]) dp[i, j] = dp[i - 1, j - 1];
                            if (blue <= bCnt[i]) dp[i, j] += dp[i - 1, j];
                        }
                    }
                    dp[i, j] %= mask;
                }
            }
            Console.WriteLine(dp[s.Length * 2, rCnt[s.Length * 2]]);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}