Hexadecimal to Octal Conversion

No attempts yetTime limit1sMemory limit128 MB

Problem

Computers store every number in binary (base 2), that is, using only 0s and 1s.

Write a program that converts an unsigned hexadecimal number (base 16) to its octal (base 8) form. The hexadecimal number has at most 100,000 digits and is made up of the digits 0-9 and the capital letters A-F.

Note: a hexadecimal number represents a value in base 16. The digits 0-9 still mean 0-9, and then A (capital A!) means 10, B means 11, ..., and F means 15.

For example, the hexadecimal number A10B corresponds to the decimal value $10 \times 16^{3} + 1 \times 16^{2} + 0 \times 16^{1} + 11 \times 16^{0} = 41227$. Its octal form is 120413, because $1 \times 8^{5} + 2 \times 8^{4} + 0 \times 8^{3} + 4 \times 8^{2} + 1 \times 8^{1} + 3 \times 8^{0} = 41227$.

Hint: there is an easier way to convert from hexadecimal to octal than going hexadecimal -> decimal -> octal. It helps to think about the digits in binary (base 2).

Input

  • Line 1: a single hexadecimal number. A multi-digit number has no leading zeros (for example A1, not 00A1). A lone 0 is a valid input.

Output

  • Line 1: the octal value with no leading zeros. If the input is 0, the output must also be 0.