Zigzag Conversion

Practice this coding question on Coding Gurukul.

Problem statement

Write a string in rows by moving down from row 0 to the last row, then diagonally upwards to row 0, repeatedly. Each character belongs to the current row before moving to the next row. Concatenate the rows from top to bottom to obtain the converted string. With one row, the input stays unchanged.

Input format

First line: number of rows r. Second line: nonempty string s.

Output format

Print the concatenation of the rows from top to bottom.

Constraints

1 <= r <= 1000; 1 <= length of s <= 10000; English letters only.

Sample input

3
PAYPALISHIRING

Sample output

PAHNAPLSIIGYIR

Sign in to run or submit a solution in C++, Java or Python.