#agc019e. [agc019_e]Shuffle and Swap

[agc019_e]Shuffle and Swap

Problem Statement

You have two strings A=A1A2...AnA = A_1 A_2 ... A_n and B=B1B2...BnB = B_1 B_2 ... B_n of the same length consisting of 00 and 11. The number of 11's in AA and BB is equal.

You've decided to transform AA using the following algorithm:

  • Let a1a_1, a2a_2, ..., aka_k be the indices of 11's in AA.
  • Let b1b_1, b2b_2, ..., bkb_k be the indices of 11's in BB.
  • Replace aa and bb with their random permutations, chosen independently and uniformly.
  • For each ii from 11 to kk, in order, swap AaiA_{a_i} and AbiA_{b_i}.

Let PP be the probability that strings AA and BB become equal after the procedure above.

Let Z=Ptimes(k!)2Z = P \\times (k!)^2. Clearly, ZZ is an integer.

Find ZZ modulo 998244353998244353.

Constraints

  • 1leqA=Bleq10,0001 \\leq |A| = |B| \\leq 10,000
  • AA and BB consist of 00 and 11.
  • AA and BB contain the same number of 11's.
  • AA and BB contain at least one 11.

Partial Score

  • 12001200 points will be awarded for passing the testset satisfying 1leqA=Bleq5001 \\leq |A| = |B| \\leq 500.

Input

Input is given from Standard Input in the following format:

AA BB

Output

Print the value of ZZ modulo 998244353998244353.


Sample Input 1

1010
1100

Sample Output 1

3

After the first two steps, a = \[1, 3\] and b = \[1, 2\]. There are 44 possible scenarios after shuffling aa and bb:

  • a = \[1, 3\], b = \[1, 2\]. Initially, A=1010A = 1010. After swap(A1A_1, A1A_1), A=1010A = 1010. After swap(A3A_3, A2A_2), A=1100A = 1100.
  • a = \[1, 3\], b = \[2, 1\]. Initially, A=1010A = 1010. After swap(A1A_1, A2A_2), A=0110A = 0110. After swap(A3A_3, A1A_1), A=1100A = 1100.
  • a = \[3, 1\], b = \[1, 2\]. Initially, A=1010A = 1010. After swap(A3A_3, A1A_1), A=1010A = 1010. After swap(A1A_1, A2A_2), A=0110A = 0110.
  • a = \[3, 1\], b = \[2, 1\]. Initially, A=1010A = 1010. After swap(A3A_3, A2A_2), A=1100A = 1100. After swap(A1A_1, A1A_1), A=1100A = 1100.

Out of 44 scenarios, 33 of them result in A=BA = B. Therefore, P=3P = 3 / 44, and Z=3Z = 3.


Sample Input 2

01001
01001

Sample Output 2

4

No swap ever changes AA, so we'll always have A=BA = B.


Sample Input 3

101010
010101

Sample Output 3

36

Every possible sequence of three swaps puts the 11's in AA into the right places.


Sample Input 4

1101011011110
0111101011101

Sample Output 4

932171449