cho.sh
Notes
Loading...

House Number Sign

Time limit

1s

Memory limit

128 MB

Problem

Jaeseok makes number signs that are attached to front doors. Each sign contains an address number, and it needs fixed margins between digits and at both ends. Different digits also take different widths.

The rules are as follows.

  1. There is a 1 cm margin between every pair of adjacent digits.
  2. The digit 1 takes 2 cm, and the digit 0 takes 4 cm. Every other digit takes 3 cm.
  3. There is a 1 cm margin between the sign boundary and the nearest digit on both the left and the right.
120.png

For the number 120 shown above, there are two gaps between digits. The digit widths are 2 cm for 1, 3 cm for 2, and 4 cm for 0. Adding the 2 cm of outer margins gives a total width of 2 + 2 + 3 + 4 + 1 + 1 = 13 cm.

For each given address number, determine the total width needed for its number sign.

Input

Each line contains one number N to be written on a sign. N satisfies 1 <= N <= 9999.

Input continues until a line containing 0 appears. The final 0 is a terminator and must not be processed.

Output

For each number, output the total width required for its number sign as an integer.

Print the answers in input order, one per line.