P2643 A Big Shot Appeared in the Computer Room!
Background
A big shot named Kurunie appeared in the computer room! As a big shot, of course they like solving problems. However, with the NOIp second round approaching, the big shot needs to spend more time on OI problems, so they are giving you some simple ones.
Description
Obviously, any problem is easy for K-chu, but K-chu is worried you might not be able to write it, so they gave you the simplest chemistry worksheet.
It turns out K-chu is preparing for a chemical equation balancing contest, so the worksheet is full of balancing exercises.
K-chu gave you a simple example. For instance, balance the chemical equation for burning the following substance in oxygen:

Of course K-chu knows this is chlorogenic acid (C16H18O9) (be careful to distinguish O and 0). Its combustion equation is:
C16H18O9+O2=CO2+H2O
What? You said “balance it”? Such a simple task is naturally left to you.
Input Format
A single line string representing the chemical equation to be balanced. An equals sign separates reactants and products, and substances are separated by plus signs. Digits in the input appear after elements as subscripts.
Output Format
A single line string representing the balanced chemical equation. Do not add precipitate or gas symbols.
Explanation/Hint
- The input string length is at most 50, and it contains only uppercase and lowercase English letters, digits, parentheses, plus signs, and an equals sign.
- The substances involved do not include waters of crystallization.
- Element symbols have at most two letters.
- Parentheses are not nested inside parentheses.
- After balancing, each substance’s coefficient and all subscripts in the original string fit within the 32-bit signed integer range.
Translated by ChatGPT 5