Given the license plate of a car and the number of cars that were registered after that car, calculate the license plate of the last registered car.

Input

x : starting license plate n : number of subsequent registered cars

Output

y : license plate of the last car registered

Constraints

1 ≤ n ≤ 100 000 000

Solution

The idea behind this problem is to generate a number system based on the license plates. The number system has different symbols, the digit positions have different weights and the order of the position is not increasing, that's the difference to a classical number system, but as for the Project Euler Problem 24 we even had a number system with a factorial base. To convert the license plate symbols from the actual to a decimal representation we introduce the following helper functions:

The first few steps bring the license plate into the right format. This is done by creating an index array, at which position what information can be found, what parsers and formatters are available and what base every position in our number system has. After this configuration part, the license plate is converted to a number and added to the offset we get as a parameter. From now on it's just the typical base convert routine from base 10 to our custom system: