Time limit
1s
Memory limit
128 MB
A bracket string is made only from the four characters (, ), [, and ]. A valid bracket string is defined as follows.
() and [], each consisting of one matching pair, are valid bracket strings.X is a valid bracket string, then (X) and [X] are also valid bracket strings.X and Y are valid bracket strings, then their concatenation XY is also a valid bracket string.For a valid bracket string X, define its value as follows.
() is 2.[] is 3.(X) is 2 × value(X).[X] is 3 × value(X).X and Y are concatenated, then value(XY) = value(X) + value(Y).For example, (()[[]]) is valid because the inside ()[[]] has value 2 + 3 × 3 = 11, so (()[[]]) has value 2 × 11 = 22. Also, ([]) has value 2 × 3 = 6, so (()[[]])([]) has total value 22 + 6 = 28.
Given one bracket string, compute and print its value according to these rules. If the input string is not a valid bracket string, print 0.
The first line contains a string representing a bracket string. Its length is between 1 and 30, inclusive.
Print one integer: the value of the bracket string. If the input is not a valid bracket string, print 0.