logo AlgoBeat OnlineJudge
登录 注册

#216920. [NWERC 2018] Kleptography

内存限制:512 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

John likes simple ciphers. He had been using the “Caesar” cipher to encrypt his diary until recently, when he learned a hard lesson about its strength by catching his sister Mary browsing through the diary without any problems.

Rapidly searching for an alternative, John found the famous “Autokey” cipher. He uses a version that takes the lower-case letters a--z and internally translates them in alphabetical order to the numbers to .

The encryption key begins with a secret prefix of letters. Each of the remaining letters of the key is copied from the letters of the plaintext , so that for . Encryption of the plaintext to the ciphertext follows the formula .

Mary was able to get a peek at the last letters John typed before he noticed her, encrypted the text document, and left. This could be her chance.

输入格式

The input consists of:

  • One line with two integers and (, ), where is the keyword length as well as the number of letters Mary saw, and is the length of the text.
  • One line with lower-case letters, the last letters of the plaintext.
  • One line with lower-case letters, the whole ciphertext.

输出格式

Output the plaintext of John's diary.

样例

样例输入 1

5 16
again
pirpumsemoystoal

样例输出 1

marywasnosyagain

样例输入 2

1 12
d
fzvfkdocukfu

样例输出 2

shortkeyword