#abc189d. [abc189_d]Logical Expression

[abc189_d]Logical Expression

Problem Statement

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

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

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

Here, alandba \\land b and alorba \\lor b are logical operators.

Constraints

  • 1leqNleq601 \\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\\vdots SNS_N

Output

Print the answer.


Sample Input 1

2
AND
OR

Sample Output 1

5

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

  • y0=x0=textTruey_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=textTruey_2 = \\text{True} are shown below:

  • (textTrue,textTrue,textTrue)(\\text{True},\\text{True},\\text{True})
  • (textTrue,textTrue,textFalse)(\\text{True},\\text{True},\\text{False})
  • (textTrue,textFalse,textTrue)(\\text{True},\\text{False},\\text{True})
  • (textFalse,textTrue,textTrue)(\\text{False},\\text{True},\\text{True})
  • (textFalse,textFalse,textTrue)(\\text{False},\\text{False},\\text{True})

Sample Input 2

5
OR
OR
OR
OR
OR

Sample Output 2

63

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