cho.sh
Notes
Loading...

Cipher Decryption

Time limit

2s

Memory limit

128 MB

Problem

Consider the following encryption method, which turns a plaintext into a ciphertext using a key. The plaintext, ciphertext, and key are all uppercase English strings with no spaces.

Let N be the length of the key. First, split the plaintext from left to right into groups of N characters and place each group as a row. For example, if the plaintext is MEETMEBYTHEOLDOAKTREENTH and the key is BATBOY, the table is arranged as follows.

BATBOY
MEETME
BYTHEO
LDOAKT
REENTH

The top row containing the key is shown only for explanation. Next, sort the columns stably by their key characters. In other words, the columns of BATBOY are ordered by the sorted key ABBOTY. If the same character appears multiple times, the column that was farther left in the original table comes first.

ABBOTY
EMTMEE
YBHETO
DLAKOT
ERNTEH

In this example, among the two B columns, the original left column (B)MBLR comes first. Reading the sorted table column by column from left to right, and within each column from top to bottom, produces the ciphertext. Thus the ciphertext for this example is EYDEMBLRTHANMEKTETOEEOTH.

Given the key and the ciphertext, write a program that recovers the original plaintext.

Input

The first line contains the key. The second line contains the ciphertext.

Both strings consist only of uppercase English letters. The length of the ciphertext is always a multiple of the length of the key. The key has length at most 10, and the ciphertext has length at most 100.

Output

Print the recovered plaintext on the first line.