e-olymp
favorite We need a little bit of your help to keep things running, click on this banner to learn more
Competitions

Summer School 2011 in Sevastopol, Day 3

Number

In some institutions,the documentsare numberedin a strange way.Oneset of figuresis usedfor oddbitsand, in general, a different setfor the evenbits(bitsarenumberedfrom right to leftstarting from 1).Moreover, in different yearscan be used bydifferent sets ofdigits.The only thing thatis strictly adhered toin this place-is the factthat the numbersin thegiven constraintsare not droppedandpreserveorderin ascending order.

For example, ifthe odddigitsusing the numbers0, 5, 6, andeven0 and 7, the first fewnumberswould look like this:: 0, 5, 6, 70, 75, 76, 500, 505, 506, 570, 575, 576, 600, ...

We need towrite a program thatfor a given setof numbersforthe even and oddpositionsand the knownsequence numberof the document,measured from the1,will determine thenumber assigned to thatdocumentin this organization.

Input

The firstline containsthree numbersN, K, L. N -requestedan official number, Kand L -respectively the number ofdigits usedin oddandeven positions.In the second rowareseparated by a spacefigures usedinodd positions, and in thethird line- the figuresused in theeven positions.

1N1055, 2K, L10.

Output

The output fileis the onlystring containing theresponse tothe problem.

Time limit 1 second
Memory limit 64 MiB
Input example #1
12 3 2
0 6 5
0 7
Output example #1
576