Alien Codebreaking
시간 제한13초메모리 제한1024 MB
반복된 아핀 함수 값으로 만든 X 곱하기 X 격자의 각 열 합을 이어붙여 거대한 십진수를 만들고, 이를 27진수로 바꾼 뒤 자릿수로 암호문을 이동해 복호화한다.
문제
You've intercepted encrypted communications between Martian diplomats. Since Martian diplomats are often spies, you decide to decrypt the messages. While the Martians have skilled rocket tech, they lag behind in number theory considerably, which compromises their encryption protocol.
Fortunately for you, spies friendly to you have reverse engineered the Martian protocol. It turns out that the Martians are using a shift-based cipher combined with a very long one-time pad. More specifically, the decryption procedure works as follows:
Step 1: Define the function .
Further define , , , and so on.
Step 2: Create a by size grid, fill the upper left corner with , the next cell to the right with , etc. Once the top row is filled, continue to the cell below the upper left cell, and fill with . Continue this process until all rows are filled.
Step 3: Sum all the values in every column, and take those values mod .
Step 4: Concatenate the base-10 representations of the column sums together, to get a very long base-10 number. For instance, if you had column sums of 10 and 12 for the first and second column, the leftmost four digits of the resulting value would be 1012.
Step 5: Convert the result of step 4 from base to base . This will yield the one-time pad the Martians used.
Step 6: For each letter of the intercepted message, shift the letter by the amount given by the corresponding digit of step 5, base .
You know that the both the encrypted and the decrypted message consist of only uppercase English characters 'A' through 'Z' and spaces, which are assigned values . (A = 0, B = 1, ... Z = 25, SPACE = 26. Shifting means to add the digit at the corresponding position of the pad to the value of the letter in the encrypted message. For instance, if the encrypted message has letter 'D' in position , and the base-27 digit of the pad is , the decrypted letter would be which is 'B'.
Step 7: Output the decrypted message.
입력
The first line of the input contains two positive integers, (), and (). It is guaranteed that the base result of step 5 will be longer or equal to the length of the intercepted message. The second line of the input contains a string consisting of uppercase letters and spaces of length , the encrypted text.
출력
Output the decrypted text.