Factorial Base

No attempts yetTime limit1sMemory limit128 MB

Problem

Sanggeun lives a little differently from most people. Feeling burdened by others' stares, he invented his own way of writing numbers and named it the factorial base.

Like decimal, the factorial base lets each digit be from $0$ to $9$. What differs is how you read it. Number the positions from the right, with the rightmost digit being position $1$. If the digit at position $i$ is $a_i$, then that position contributes $a_i \times i!$ to the value.

For example, $719$ in factorial base equals $53$ in decimal, because $7 \times 3! + 1 \times 2! + 9 \times 1! = 42 + 2 + 9 = 53$.

Given a number written in factorial base, write a program that computes its value read in decimal.

Input

The input consists of several test cases. Each test case is a single line containing one factorial-base number of at most $5$ digits. The last line of the input contains a single $0$, which must not be processed.

Output

For each test case, print the decimal value of the given factorial-base number on its own line.