/* Inline comments below suggest one way of developing the program */

#include "common.h"

int main(int ac, char *av[])
{
    int n, i, j;
    int **A;

    scanf("%d", &n);
    if (n < 0)
        ERR_MESG("Invalid value of n");
    matrix_alloc(A, n, n, int);

    for (i = 0; i < n; i++)
        for (j = 0; j < n; j++)
            scanf("%d", &A[i][j]);

    for (i = 0; i < n; i++) {
        /* Step 3: compute number of leading blanks in each row in the 
         * upper half, and print. Multiple tries may be needed to get
         * the layout exactly as required.
         */
        for (j = 0; j < n-i-1; j++)
            printf("  ");
        /* Step 1: fill in this inner loop first to correctly print
         *  content of the upper half; ignore spacing/arrangement for now. 
         */
        for (j = 0; j <= i; j++)
            printf("%d   ", A[i-j][j]);
        putchar('\n');
    }
    for (i = 1; i < n; i++) {
        /* Step 3: compute number of leading blanks in each row in the
         * lower half, and print. As above, multiple tries may be
         * needed to get the layout exactly as required.
         */
        for (j = 0; j < i; j++)
            printf("  ");
        /* Step 2: fill in this inner loop next to correctly print
         *  content of the lower half; ignore spacing/arrangement for now.
         */
        for (j = 0; j < n-i; j++) {
            printf("%d   ", A[n-j-1][i+j]);
        }
        putchar('\n');
    }

    
    matrix_free(A);
    return 0;
}
