Capybara's friend CABI-bara is a chemist who is currently learning about organic chemistry. His work is to analyze various elements. However, the machine in his lab is malfunctioning and can only output complex chemical formulas. He needs the students' help to analyze the elements!
Given a chemical formula (a string), please parse all the chemical elements inside and calculate the total amount of each element.
Finally, you MUST output the results sorted by their Atomic Number in ascending order.
The chemical formula strictly follows these rules:
) will always be immediately followed by a number , meaning the quantities of all elements inside the parentheses are multiplied by . For example, Ca(OH)2 contains 1 Ca, 2 O, and 2 H. Parentheses are guaranteed to be valid, balanced, and can be nested.To help you sort the elements, CABI-bara has provided the periodic table used in this homework.
(Note: Although the chart shows the entire periodic table, CABI-bara guarantees that you only need to handle the first 36 elements, from Hydrogen (1) to Krypton (36).)
The input contains only one line, which is a valid chemical formula string .
(, and ).Output multiple lines. For each element present in the formula, output in the format:Element: Quantity.
The output lines MUST be sorted in ascending order of their Atomic Numbers.