#ABC189D. [ABC189D] Logical Expression

[ABC189D] Logical Expression

题目描述

N N 個の文字列 S1,,SN S_1,\ldots,S_N が与えられます。各文字列は AND または OR です。

値が True \text{True} または False \text{False} であるような N+1 N+1 個の変数の組 (x0,,xN) (x_0,\ldots,x_N) であって、 以下のような計算を行った際に、yN y_N True \text{True} となるようなものの個数を求めてください。

  • y0=x0 y_0=x_0
  • i 1 i\geq\ 1 のとき、Si S_i AND なら yi=yi1  xi y_i=y_{i-1}\ \land\ x_i Si S_i OR なら yi=yi1  xi y_i=y_{i-1}\ \lor\ x_i

a  b a\ \land\ b a a b b の論理積を表し、a  b a\ \lor\ b a a b b の論理和を表します。

输入格式

入力は以下の形式で標準入力から与えられる。

N N S1 S_1 \vdots SN S_N

输出格式

答えを出力せよ。

题目大意

题目翻译

nn 个字符串 ANDOR。填入 n+1n + 1 个值,每个值是 TRUEFALSE,请问有多少种方案可以使这个表达式最后的结果是 TRUE。表达式的结果就是将这 nn 个字符串按顺序插入 n+1n + 1 个值之间,从左往右计算。

1n601\leq n\leq 60

2
AND
OR
5
5
OR
OR
OR
OR
OR
63

提示

制約

  • 1  N  60 1\ \leq\ N\ \leq\ 60
  • Si S_i AND または OR

Sample Explanation 1

例えば $ (x_0,x_1,x_2)=(\text{True},\text{False},\text{True}) $ のとき - y0=x0=True y_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} $ となり、y2 y_2 True \text{True} になります。 y2 y_2 True \text{True} となるような (x0,x1,x2) (x_0,x_1,x_2) の組み合わせは、 - (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 5 通りで全てです。

Sample Explanation 2

全てが False \text{False} のときを除く 261 2^6-1 通りで y5 y_5 True \text{True} になります。