#C4135. Word Pagination

    ID: 47640 Type: Default 1000ms 256MiB

Word Pagination

Word Pagination

You are given a list of words and a positive integer max_words_per_page. Your task is to split the list into several pages where each page contains at most max_words_per_page words. The pages should preserve the order of words. If the number of words is less than or equal to max_words_per_page, then the resulting output is a single page containing all the words.

In other words, if you have a list of n words and a maximum page length k, then the words will be partitioned as:

\(\text{Page 1: } words_1, words_2, \ldots, words_k\)

\(\text{Page 2: } words_{k+1}, \ldots \)

If max_words_per_page is less than or equal to zero or the list is empty, the output should be empty (i.e. no pages).

inputFormat

The input is provided via stdin and consists of three lines:

  1. An integer n which indicates the number of words.
  2. A line containing n words separated by spaces. (If n is 0, this line may be empty.)
  3. An integer max_words_per_page indicating the maximum number of words allowed per page.

outputFormat

The output should be printed to stdout with each page on a separate line. For each page, print the words separated by a single space. If no pages are produced, output nothing.

## sample
6
This is an example of pagination
2
This is

an example of pagination

</p>