cho.sh
Notes
Loading...

Bracket Value

Time limit

1s

Memory limit

128 MB

Problem

A bracket string is made only from the four characters (, ), [, and ]. A valid bracket string is defined as follows.

  1. The strings () and [], each consisting of one matching pair, are valid bracket strings.
  2. If X is a valid bracket string, then (X) and [X] are also valid bracket strings.
  3. If both 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.

  1. The value of () is 2.
  2. The value of [] is 3.
  3. The value of (X) is 2 × value(X).
  4. The value of [X] is 3 × value(X).
  5. If valid bracket strings 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.

Input

The first line contains a string representing a bracket string. Its length is between 1 and 30, inclusive.

Output

Print one integer: the value of the bracket string. If the input is not a valid bracket string, print 0.