Time limit
2s
Memory limit
128 MB
A chemical formula consists of the atom symbols H, C, and O, digits, and parentheses. A digit immediately after an atom tells how many copies of that atom are present; if there is no digit, the count is 1. Every digit is a single digit from 2 through 9.
The same atom may appear several times in one formula. For the calculation, add the masses of all atoms that appear in the formula.
A parenthesized part is treated as one unit. If a digit follows a closing parenthesis, the entire parenthesized unit is repeated that many times. If the parentheses are empty, treat that unit as having mass 0.
The mass of one atom is 1 for hydrogen H, 12 for carbon C, and 16 for oxygen O. Given a chemical formula, compute the sum of the masses of all atoms in it.
The first line contains a chemical formula. The formula is a string made only of H, C, O, (, ), and the digits 2 through 9, and its length does not exceed 100.
Print the formula mass on the first line. No input whose formula mass exceeds 10,000 is given.