Booklet Printing

Time limit1sMemory limit128 MB

Summary
For each page count, print which page numbers (or Blank) go on each side of every sheet in fold-over booklet order.
Level

Easy3 of 10

Topics
Array, Implementation, Simulation
Solved
No attempts yet

Problem

When printing a document, pages are normally printed in order: page 1 first, then page 2, then page 3, and so on until the last page. However, when printing a fold-over booklet, the printing order must be changed.

A fold-over booklet holds four pages on each sheet of paper: two on the front and two on the back. When all sheets are stacked in order and the whole stack is folded in half, the page numbers appear in the correct order, just like in an ordinary book. For example, a 4-page booklet prints on a single sheet: the front holds page 4 then page 1 (left to right), and the back holds page 2 then page 3.

Front              Back
-------------      -------------
|     |     |      |     |     |
|  4  |  1  |      |  2  |  3  |
|     |     |      |     |     |
-------------      -------------

Given the number of pages to print, write a program that produces the printing order.

Input

The input consists of one or more test cases, followed by a line containing a single 0 that marks the end of the file. Each test case is a single positive integer nn on its own line, the number of pages to print. nn does not exceed 100.

Output

For each test case, print a report describing which pages go on each sheet.

First print a line of the form Printing order for n pages: (where n is the number of pages). Then, in ascending order of sheet number, print each sheet's front first and its back second.

A front line has the form Sheet k, front: a, b, and a back line has the form Sheet k, back : a, b (note the single space after back that aligns it with front). Here k is the sheet number, and a and b are the page numbers printed at those positions.

If the number of pages does not completely fill a sheet, print the word Blank instead of a number in each empty position. If the entire front or the entire back of a sheet is blank, do not print a line for that side.

Print one blank line between the outputs of consecutive test cases.

Examples4

  1. Example 1

    Input
    1
    14
    4
    0
    
    Expected output
    Printing order for 1 pages:
    Sheet 1, front: Blank, 1
    
    Printing order for 14 pages:
    Sheet 1, front: Blank, 1
    Sheet 1, back : 2, Blank
    Sheet 2, front: 14, 3
    Sheet 2, back : 4, 13
    Sheet 3, front: 12, 5
    Sheet 3, back : 6, 11
    Sheet 4, front: 10, 7
    Sheet 4, back : 8, 9
    
    Printing order for 4 pages:
    Sheet 1, front: 4, 1
    Sheet 1, back : 2, 3
    
  2. Example 2

    Input
    2
    0
    
    Expected output
    Printing order for 2 pages:
    Sheet 1, front: Blank, 1
    Sheet 1, back : 2, Blank
    
  3. Example 3

    Input
    3
    0
    
    Expected output
    Printing order for 3 pages:
    Sheet 1, front: Blank, 1
    Sheet 1, back : 2, 3
    
  4. Example 4

    Input
    8
    0
    
    Expected output
    Printing order for 8 pages:
    Sheet 1, front: 8, 1
    Sheet 1, back : 2, 7
    Sheet 2, front: 6, 3
    Sheet 2, back : 4, 5