Problem Five:
Squaring Rectangles

We'll spare you the entertaining story on this one.

A latin rectangle is an R x N matrix (R rows and N columns, R less than N), containing the numbers 1, 2, ..., N, such that the same number does not appear more than once in any row or column. For example,

   1 2 3
   2 3 1
is a 2 x 3 latin rectangle.

Write a program that takes an R x N latin rectangle and extends it into an N x N latin square. The first R rows are left unchanged.

The data will be R lines, each consisting of N space-separated integers between 1 and N, inclusive. For example,

Input:
   1 2 3
   2 3 1
Output:
   1 2 3
   2 3 1
   3 1 2

Doug Lea
Last modified: Fri Oct 15 12:14:48 EDT 1999