#CT00041. Mật mã hồi tiếp (Feedback Cipher)

    ID: 231 Loại: Thông thường 2000ms 256MiB Tried: 2 Đã chấp nhận: 2 Độ khó: 1 Đăng bởi: Nhãn>String AlgorithmsString processing basicsFundamentalsInteger arithmeticImplementation techniques

Mật mã hồi tiếp (Feedback Cipher)

Feedback Cipher

Version: Phuoc Hung OJ Extended

Problem Statement

Use lowercase letters a..z with values a =0=0, b =1=1, …\ldots, z =25=25.

Initially the current key is k1=Kk_1=K, where 0≤K≤250\le K\le25. At position ii, let pip_i be the numeric value of the plaintext character and cic_i the numeric value of the ciphertext character.

For encryption,

ci=(pi+ki) mod 26.c_i=(p_i+k_i)\bmod26.

After processing position ii, update

ki+1=(ki+pi+1) mod 26.k_{i+1}=(k_i+p_i+1)\bmod26.

For decryption, recover

pi=(ci−ki+26) mod 26,p_i=(c_i-k_i+26)\bmod26,

then update the key using the recovered pip_i in the same way.

If M=1M=1, encrypt SS. If M=2M=2, decrypt SS. Processing is always performed from left to right.

Input

  • Line 1 contains integers MM and KK, where M∈{1,2}M\in\{1,2\} and 0≤K≤250\le K\le25.
  • Line 2 contains SS, consisting only of lowercase letters a..z.

Output

Print the resulting string after applying the requested mode.

Subtasks

  • Subtask 1 (40 points): 1≤∣S∣≤1031\le|S|\le10^3.
  • Subtask 2 (60 points): 1≤∣S∣≤1061\le|S|\le10^6.

Examples

Example 1

Input

1 3
hello

Output

kpbnc

Explanation

Initially K=3K=3. The value of h is 77, so the first encrypted value is (7+3) mod 26=10(7+3)\bmod26=10, which is k. The key then becomes (3+7+1) mod 26=11(3+7+1)\bmod26=11. Continuing from left to right produces kpbnc.

Example 2

Input

2 3
kpbnc

Output

hello

Explanation

Initially K=3K=3. The value of encrypted k is 1010, so the first plaintext value is (10−3+26) mod 26=7(10-3+26)\bmod26=7, which is h. Updating the key with each recovered plaintext value and continuing left to right reconstructs hello.