One of the problems in the International Parsing Contest caught your attention.
Two expressions are given as input, each representing a procedure to generate a single tree. The gen eration procedure is randomized, meaning different trees may be generated each time the procedure is performed. You are asked to count the number of trees that can possibly be generated from both of the expressions.
The syntax of an expression is as follows.
$E$ $::=$ '1' $|$ '(' $E$ $E$ ')'
A tree is generated from an expression according to the following procedure.
For example, the expression (11) can generate only the leftmost tree in Figure D.1, while (1(11)) can generate the remaining two trees.
The same tree may be generated from different expressions. The middle tree can also be generated from ((11)1).
For given two expressions of the same length, count the number of trees that can be generated from both of the expressions. Note that the trees generated from them always have the same number of vertices. Two trees are considered different if there exist two indices $i$ and $j$ such that vertices labeled $i$ and $j$ are connected by an edge in one tree but not in the other.
The input consists of two lines, each containing an expression string. The two strings have the same length, between $1$ and $7 \times 10^5$, inclusive, and follow the syntax given above.
Output the number of trees that can be generated from both expressions modulo 998244353.
((1(11))1) ((11)(11))
1
(1(11)) (1(11))
2
(((11)(11))((11)1)) ((1(11))(1(1(11))))
3
((11)(((1(11))1)((11)1))) (1(((11)((11)(11)))(11)))
4
For Sample Input 1, the trees that can be generated from the two expressions are shown in Figure D.2. The top six trees correspond to the first expression and the bottom four correspond to the second. Only the leftmost tree in each row can be generated from both.