This page is still under construction.

Parts of this page are still being built. What you see may change.

String Encryption

Interview

Time limit1sMemory limit128 MB

Summary
Clean the plaintext (drop spaces, uppercase), then invert the given transposition decryption rule to produce the matching ciphertext.
Level

Medium5 of 10

Topics
String, Implementation, Simulation, Math
Solved
No attempts yet

Problem

To keep others from reading their messages freely, many people use encryption algorithms to turn a plaintext (message) into a ciphertext. A transposition cipher does not change the characters themselves; it only rearranges the order in which they appear, and it must be possible to turn the ciphertext back into the plaintext later.

The decryption rule (ciphertext → plaintext) used in this problem is as follows. Read the first character of the ciphertext, then read the character NN positions away (skipping the N−1N-1 characters in between). Keep repeating this; once you move past the end of the string, go back to the second character and repeat the same process. Continuing this way until every character of the ciphertext has been read exactly once yields the plaintext.

Your task is the reverse process: encryption. First remove every space between words from the plaintext and convert every letter to uppercase. Then output the ciphertext that, when the decryption process above is applied to it, reproduces exactly that cleaned string.

Input

The input consists of several test cases.

Each test case is given on two lines. The first line contains an integer NN (1≤N≤10001 \le N \le 1000), and the second line contains the plaintext.

The plaintext is between 1 and 10,000 characters long and consists only of uppercase and lowercase letters and spaces.

When N=0N = 0 is given on the first line, the input ends and that test case is not processed.

Output

For each test case, print the ciphertext produced by the method described above, one per line. The ciphertext is the string obtained from the plaintext by removing spaces, converting every letter to uppercase, and rearranging the order of the characters.

Examples1

  1. Example 1

    Input
    2
    CTU Open Programming Contest
    7
    This is a secret message that noone should ever see Lets encrypt it
    15
    text too short
    0
    
    Expected output
    CMTMUIONPGECNOPNRTOEGSRTA
    TESNUECHCAOLERIRGODLYSEENEEPITTEVTTSMHSESIAEAHRETSSTOSN
    TEXTTOOSHORT