LogiQuest

346. Word Wrap

MediumGreedy

Wrap the words into lines of at most w characters (words separated by single spaces; a word longer than w gets its own line). Fill lines greedily and print them.

Input format

Line 1: w Line 2: the text

Output format

The wrapped lines.

Example 1

Input

10
the quick brown fox jumps over the lazy dog

Output

the quick
brown fox
jumps over
the lazy
dog

Example 2

Input

5
supercalifragilistic is long

Output

supercalifragilistic
is
long

Constraints

1 ≤ w ≤ 100

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

Loading the MyLoginn IDE…