Under construction

Still being built. Things may change

To and Fro

Interview

Time limit1sMemory limit128 MB

Summary
Decode a message written row by row in alternating left-to-right and right-to-left order back into column-major plaintext.
Level

Easy3 of 10

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

Problem

Mo and Larry have devised a way of encrypting messages. They first decide secretly on the number of columns, then write the message (letters only) down the columns, padding with extra random letters so that the letters form a rectangular array.

For example, if the message is "There's no place like home on a snowy night" and there are five columns, Mo writes down:

t o i o y
h p k n n
e l e a i
r a h s g
e c o n h
s e m o t
n l e w x

Mo includes only letters and writes them all in lower case. In this example Mo used 'x' to pad the message out into a rectangle, although any letter could have been used.

Mo then sends the message to Larry by writing the letters in each row, alternating left-to-right and right-to-left. So the array above is encrypted as:

toioynnkpheleaigshareconhtomesnlewx

Your task is to recover, for Larry, the original message (including any extra padding letters) from the encrypted one.

Input

There are multiple input sets. The input for each set consists of two lines. The first line contains an integer in the range 2 to 20 giving the number of columns used. The second line is a string of up to 200 lower-case letters; its length is always a multiple of the number of columns (it forms a rectangle). The last input set is followed by a line containing a single 0, marking the end of input.

Output

For each input set, print one line giving the original plaintext message, with no spaces.

Examples5

  1. Example 1

    Input
    5
    toioynnkpheleaigshareconhtomesnlewx
    3
    ttyohhieneesiaabss
    0
    
    Expected output
    theresnoplacelikehomeonasnowynightx
    thisistheeasyoneab
    
  2. Example 2

    Input
    2
    abcd
    0
    
    Expected output
    adbc
    
  3. Example 3

    Input
    2
    abcdef
    0
    
    Expected output
    adebcf
    
  4. Example 4

    Input
    20
    abcdefghijklmnopqrst
    0
    
    Expected output
    abcdefghijklmnopqrst
    
  5. Example 5

    Input
    4
    abcdefgh
    2
    xyzw
    3
    abcdefghi
    0
    
    Expected output
    ahbgcfde
    xwyz
    afgbehcdi