Calculating dehydration synthesis results
Python (337 336 chars)
import re
i=input().split()
a,d,o,e=[],{},&quot;&quot;,len(i)-1
for b in i:a.append(dict(re.findall(r&quot;([A-Z][a-z]*)(\d*)&quot;,b)))
a=[{b:int(c[b])if c[b]else 1for b in c}for c in a]
for b in a:
 for c in b:d[c]=c in d and d[c]+b[c]or b[c] 
 if&quot;H&quot;not in b:d[&quot;-&quot;]=0
d[&quot;H&quot;]-=2*e;d[&quot;O&quot;]-=e
for b in d:o+=b+(str(d[b])if d[b]-1else&quot;&quot;)if d[b]else&quot;&quot;
print(o)

Here is an example of how to use this program:
sh3.14$ python dehydrate.py &lt;-Run the program
C6H12O6 HgHO4               &lt;-Input
O9H11C6Hg                   &lt;-Output

Try it!