#ABC189D. [ABC189D] Logical Expression

[ABC189D] Logical Expression

Score : 400400 points

Problem Statement

Given are NN strings S1,,SNS_1,\ldots,S_N, each of which is AND or OR.

Find the number of tuples of N+1N+1 variables (x0,,xN)(x_0,\ldots,x_N), where each element is True\text{True} or False\text{False}, such that the following computation results in yNy_N being True\text{True}:

  • y0=x0y_0=x_0;
  • for i1i\geq 1, yi=yi1xiy_i=y_{i-1} \land x_i if SiS_i is AND, and yi=yi1xiy_i=y_{i-1} \lor x_i if SiS_i is OR.

Here, aba \land b and aba \lor b are logical operators.

Constraints

  • 1N601 \leq N \leq 60
  • SiS_i is AND or OR.

Input

Input is given from Standard Input in the following format:

NN

S1S_1

\vdots

SNS_N

Output

Print the answer.

2
AND
OR
5

For example, if $(x_0,x_1,x_2)=(\text{True},\text{False},\text{True})$, we have y2=Truey_2 = \text{True}, as follows:

  • y0=x0=Truey_0=x_0=\text{True}
  • $y_1=y_0 \land x_1 = \text{True} \land \text{False}=\text{False}$
  • $y_2=y_1 \lor x_2 = \text{False} \lor \text{True}=\text{True}$

All of the five tuples (x0,x1,x2)(x_0,x_1,x_2) resulting in y2=Truey_2 = \text{True} are shown below:

  • (True,True,True)(\text{True},\text{True},\text{True})
  • (True,True,False)(\text{True},\text{True},\text{False})
  • (True,False,True)(\text{True},\text{False},\text{True})
  • (False,True,True)(\text{False},\text{True},\text{True})
  • (False,False,True)(\text{False},\text{False},\text{True})
5
OR
OR
OR
OR
OR
63

All tuples except the one filled entirely with False\text{False} result in y5=Truey_5 = \text{True}.