Golden Dust

Zynoulus the Wizard has invented a new magical way of multiplying
magical dust. In a single day he is able to transform a single piece of
golden dust into two pieces of golden dust and three pieces of silver
dust. He is also able to transform a single piece of silver dust into
three pieces of golden dust and five pieces of silver dust.

He has bought a single piece of golden dust. Using his process, he will
have two pieces of golden dust and three pieces of silver dust next day.
After the next day, he will have 2 ⋅ 2 + 3 ⋅ 3 = 13 pieces of golden
dust and 3 ⋅ 5 + 2 ⋅ 3 = 21 pieces of silver dust.

Whenever he collects 1000000000 (10⁹) pieces of dust of the same type,
he immediately sells them for a big profit.

Given an integer D, calculate the number of pieces of dust Zynoulus the
Wizard will possess after D days.

Input

Input may consist of several test cases.

A description of each test case has two lines. The first line contains a
number d, 1 ≤ d ≤ 1000000. The second line contains D written as a
d-digit number, 0 ≤ D < 10^(d).

After the last test case input contains a single digit 0.

Output

For each number D in the input, output the number of pieces of dust
Zynoulus the Wizard will possess after D days.

Problem information

Author: Eryk Kopczynski

Generation: 2026-01-25T22:59:24.614Z

© Jutge.org, 2006–2026.
https://jutge.org
