#B3926. Unit Conversion

    ID: 11583 Type: Default 1000ms 256MiB

Unit Conversion

Unit Conversion

Little Yang's math homework for this week involves unit conversion. Since he loves programming, he decided to write a program to help him with his homework.

The homework focuses on converting from a larger unit to a smaller unit in two categories: length and weight.

Length units: kilometer (km), meter (m) and millimeter (mm). Their relationships are given by: \(1\,km = 1000\,m = 1000000\,mm\).

Weight units: kilogram (kg), gram (g) and milligram (mg). Their relationships are given by: \(1\,kg = 1000\,g = 1000000\,mg\).

The assignments only include the following conversion problems:

  • m to mm
  • km to mm
  • km to m
  • g to mg
  • kg to mg
  • kg to g

Your task is to help Little Yang by writing a program that reads an input value along with its source and target unit and outputs the converted value.

inputFormat

The input consists of a single line containing a non-negative integer and two strings separated by spaces. The first token is the numerical value, the second token is the source unit, and the third token is the target unit. The conversion will always be from a larger unit to a smaller unit among the following pairs:

  • m to mm
  • km to mm
  • km to m
  • g to mg
  • kg to mg
  • kg to g

For example: 5 m mm means convert 5 meters to millimeters.

outputFormat

Output the converted value as an integer.

sample

1 km m
1000