Score : 400 points
Problem Statement
Given are N strings S1,…,SN, each of which is AND or OR.
Find the number of tuples of N+1 variables (x0,…,xN), where each element is True or False, such that the following computation results in yN being True:
- y0=x0;
- for i≥1, yi=yi−1∧xi if Si is
AND, and yi=yi−1∨xi if Si is OR.
Here, a∧b and a∨b are logical operators.
Constraints
- 1≤N≤60
- Si is
AND or OR.
Input is given from Standard Input in the following format:
N
S1
⋮
SN
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=True, as follows:
- y0=x0=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) resulting in y2=True are shown below:
- (True,True,True)
- (True,True,False)
- (True,False,True)
- (False,True,True)
- (False,False,True)
5
OR
OR
OR
OR
OR
63
All tuples except the one filled entirely with False result in y5=True.