You are given a string formula made of the symbols C, H and O, digits, and parentheses. Each symbol has a fixed weight:
C weighs 12H weighs 1O weighs 8A symbol may be followed by a count, meaning the symbol appears that many times. For example, H4 stands for four H symbols.
Part of the formula can be wrapped in parentheses to form a group. A group may also be followed by a count, meaning everything inside it appears that many times. Groups can be nested inside other groups.
A symbol or group with no count appears once.
Return the total weight of formula, which is the sum of the weights of all the symbols it stands for.
Input: formula = "H(CH4)2"
Output: 33
Explanation: The group "CH4" weighs 12 + 4 * 1 = 16. Its count is 2, so it adds 2 * 16 = 32.
The leading "H" adds 1, for a total of 33.
Input: formula = "((CH3)2O)3"
Output: 114
Explanation: The innermost group "CH3" weighs 12 + 3 = 15, and its count of 2 makes 30.
Adding "O" gives 30 + 8 = 38 for the outer group. Its count of 3 makes 3 * 38 = 114.
formula.length ≤104formula consists only of C, H, O, digits, ( and ).), has no leading zeros, and is between 2 and 999.formula is at most 109.