#!/usr/bin/python

import sys
import optparse

def main():
    parser = optparse.OptionParser()
    parser.add_option(
        '-C', dest='columns', help='columns per pagein output',
        action='store', type='int', default=94,
        )
    parser.add_option(
        '-R', dest='rows', help='rows per pagein output',
        action='store', type='int', default=65,
        )
    parser.add_option(
        '-2', dest='space', action='store_const', const=1,
        help='double space output',
        )
    parser.add_option(
        '-3', dest='space', action='store_const', const=2,
        help='triple space output',
        )
    parser.add_option(
        '-n', dest='space', action='store', type='int', default=0,
        help='number of spaces between output lines',
        )
    (options, args) = parser.parse_args()

    options.rows -= 1
    row = 0
    for line in sys.stdin:
        line = line.strip()
        width = len(line)
        count = (width - 1) / options.columns + 1
        if row + count > options.rows:
            sys.stdout.write(chr(12)); sys.stdout.flush()
            row = 0
        print line
        row += count
        if row > options.rows:
            row = 0
            continue
        if row + options.space >= options.rows:
            sys.stdout.write(chr(12)); sys.stdout.flush()
            row = 0
        elif row != 0:
            for i in xrange(options.space):
                print
                row += 1

if __name__ == '__main__':
    main()

