#P8997. Helena's Math Homework
Helena's Math Homework
Helena's Math Homework
Helena has a math homework problem involving a special kind of expression. A legal expression is defined as follows:
?
is a legal expression (representing an unknown number).- If A and B are legal expressions, then both
min(A,B)
andmax(A,B)
are legal expressions. They denote taking the minimum or maximum of A and B respectively.
Suppose the number of question marks ?
in the expression is N. We then replace each ?
with a distinct integer from 1 to N (each number is used exactly once). After evaluating the expression (using the usual meanings: min
returns the smaller of its two arguments and max
returns the larger), different assignments may result in different answers. Your task is to determine the number of distinct evaluation results that can be obtained.
Note: The input expression is guaranteed to be valid and follows the above rules.
inputFormat
The input consists of a single line containing the legal expression. The expression only contains the characters ?
, (
, )
, ,
, and the strings min
and max
without any extra spaces.
outputFormat
Output an integer which is the number of distinct outcomes obtained by evaluating the expression after replacing each ?
with a unique integer between 1 and N.
sample
?
1
</p>