LogiQuest

120. Zigzag Conversion

MediumSimulation

Write the string in a zigzag on numRows rows (down then diagonally up) and read it row by row. Print the result.

Input format

Line 1: s Line 2: numRows

Output format

The converted string.

Example 1

Input

PAYPALISHIRING
3

Output

PAHNAPLSIIGYIR

Example 2

Input

PAYPALISHIRING
4

Output

PINALSIGYAHRPI

Constraints

1 ≤ |s| ≤ 1000 1 ≤ numRows ≤ 1000

Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.

Loading the MyLoginn IDE…