Under construction

Still being built. Things may change

Chemistry

Time limit2sMemory limit1024 MB

Summary
Given a chemical formula with C, H, N, O and counts, the task is to print the total molar mass using fixed atomic weights.
Level

Easy2 of 10

Topics
String, Implementation, Simulation
Solved
No attempts yet

Problem

Your task is to compute the mass of a molecule given by its chemical formula. The formula is a list of the elements in the molecule. The notation EnE n means that element EE is repeated nn times. The mass of a molecule is the sum of the weights of all its elements.

Element nameSymbolMass
HydrogenH1
CarbonC12
NitrogenN14
OxygenO16

The input file has one line containing the formula. The formula is at most 20 characters long. It consists of the letters C, H, N, O and the digits 1 to 9. A digit always follows a letter.

Output

Print one number to the output file: the mass of the molecule.

Examples2

  1. Example 1

    Input
    H2O
    
    Expected output
    18
    
  2. Example 2

    Input
    C3H5NO3NO3NO3
    
    Expected output
    227