Under construction

Still being built. Things may change

Encryption

Time limit1sMemory limit1024 MB

Summary
Given a string encrypted with the rule x -> x^3 mod 29 + 1, recover and print the original symbols.
Level

Easy3 of 10

Topics
Implementation, Math, String, Hash map
Solved
No attempts yet

Problem

Ignas and Simonas both became interested in classical cryptography and decided to encrypt text messages to each other. The encryption process they agreed on is as follows.

  • Messages use only the following symbols, numbered from 1 to 29:

    • the uppercase Latin letters A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, numbered from 1 to 26 in alphabetical order;
    • the underscore _, used in place of a space — number 27;
    • the comma , and the period . — numbers 28 and 29, respectively.
  • The message is encrypted symbol by symbol:

    1. The symbol's number is cubed, then the remainder of dividing it by 29 is taken, and 1 is added to that remainder.
    2. Find the new symbol whose number equals the value obtained in step 1. This is the encrypted symbol.
  • Continue in the same way for every symbol of the message.

For convenience, the table of symbol numbers is given below.

№Symbol№Symbol№Symbol
1A11K21U
2B12L22V
3C13M23W
4D14N24X
5E15O25Y
6F16P26Z
7G17Q27_
8H18R28,
9I19S29.
10J20T

For example, the text GERI_ORAI. is encrypted as YJDEVLDBEA by this algorithm. This is easy to check. Take the first letter G:

  • the number of the letter G is 7,
  • its cube is 73=3437^3 = 343,
  • the remainder of dividing 343 by 29 is 343 mod 29=24343 \bmod 29 = 24,
  • adding 1 gives 24+1=2524 + 1 = 25,
  • and the number 25 belongs to the letter Y.

So, encrypting G gives Y. The encryption of the other symbols can be checked in the same way.

The period ., whose number is 29, is encrypted as the letter A. Since 29329^3 is divisible by 29, the remainder is 0, and adding 1 gives 1, i.e. the letter A.

Ignas's older brother noticed that this encryption algorithm is, unfortunately, very easily "cracked", because the original text can be quickly recovered from the encrypted text, i.e. decrypted.

Write a program that decrypts a line of text encrypted by this algorithm.

Input

The first line contains the encrypted text string.

Output

Print the decrypted text string.

Examples3

  1. Example 1

    Input
    YJDEVLDBEA
    
    Expected output
    GERI_ORAI.
    
  2. Example 2

    Input
    BI,GJNYTEO_RWSLHMDPZKFQUXC
    
    Expected output
    ABCDEFGHIJKLMNOPQRSTUVWXYZ
    
  3. Example 3

    Input
    TJRRLVQLDRGA
    
    Expected output
    HELLO_WORLD.