Programming contests

DEIK Regionális Programozó Csapatverseny, középiskolai kategória, 2023. december 3.

December 3, 2023, 10:00 AM – December 3, 2023, 3:30 PM

Cryptography for beginners

At the Faculty of Informatics we think it is extremely important to protect our students' data, thus we created a couple cryptographic techniques to achieve state of the art encryption. However we have no idea if our newest algorithm is sufficiently secure, thus - as an aspiring hacker - it is your job to test our system and try to break our code.
The principle of decoding a message is relatively easy: first, as an input you are getting the usable ABC as letters, separated by a single space character, and the encoded message as single non-negative integer. The decoding itself is done in a continous-way, so for example if the input ABC is w x y z, then w=0, x=1, y=2, z=3 and ww=4, xw=5, yw=6, zw=7, wx=8, xx=9, yx=10, zx=11,...,zz=19, www=20, xww=21, yww=22, zww=23, wxw=24, xxw=25, yxw=26, zxw=27,...etc.

Input

The input has two lines: the first line is a subset of the "small" and "capital" letters of the english alphabet separated by a single space character. The number of letters is at most 10. The numbering of the letters starts at the leftmost character with 0 and increases by 1 with each new letter. So the leftmost letter has a value of 0, its neighbour is 1, etc. The second line is a non-negative integer, which represents the encoded message.

Output

The output is the decoded text without any separators between the letters.

Restrictions

  • the number of letters in the alphabet is at most 10. The same letter can appear as a "small" and "capital" letter as well
  • the encoded text can be fit into a 32 bit unsigned integer

Example

Input:
  1. a b c d
  2. 123
download as text file Output:
  1. dbca
download as text file
University of Debrecen; Faculty of Informatics; v. 09/30/2024