#include <windows.h>
#include <stdio.h>
#include <stdlib.h>

//#define TESTPATH "H:\\A\\Debug\\"
#define TESTPATH ""

int main(void)
{
	FILE * inf = fopen(TESTPATH"input.txt", "rt");
	FILE * outf = fopen(TESTPATH"output.txt", "wt");

	int N;
	fscanf(inf, "%d", &N);
	int N2=N*N;

	#define M(i,j)	m[(i)*N+(j)]
	#define O(i,j)	o[(i)*N+(j)]

	int *m = (int*) malloc(N2*sizeof(int));
	int *o = (int*) malloc(N2*sizeof(int));

	for(int i=0;i<N2;i++) fscanf(inf, "%d", &m[i]);

	#define dist(i,j,p,q) (abs(i-p) + abs(j-q))

	memcpy(o, m, sizeof(int) * N2);

	for(i = 0; i < N; i++) {
		for(int j = 0; j < N; j++) {
			//We have zero in place
			if (M(i,j) == 0) {
				//Find nearest nonzero
				for (int d = 1; d <= N; d++) {	//Distances
					//Check all for this diatance
					int nonzero = -1;
					int nonzerocount = 0;
					for (int t = 0; t <= d; t++) {						
						//Check elements
						int r1 = i - t, r2 = i + t;
						int c1 = j - d + t, c2 = j + d - t;

						if (r1 == r2) {						
							if (r1 >= 0 && r1 < N && c1 >= 0 && c1 < N)
								if (M(r1, c1) > 0) {nonzero = M(r1,c1); nonzerocount++;}
							if (r1 >= 0 && r1 < N && c2 >= 0 && c2 < N)
								if (M(r1, c2) > 0) {nonzero = M(r1,c2); nonzerocount++;}
						}
						else if (c1 == c2) {
							if (r1 >= 0 && r1 < N && c1 >= 0 && c1 < N)
								if (M(r1, c1) > 0) {nonzero = M(r1,c1); nonzerocount++;}
							if (r2 >= 0 && r2 < N && c1 >= 0 && c1 < N)
								if (M(r2, c1) > 0) {nonzero = M(r2,c1); nonzerocount++;}
						}
						else {
							if (r1 >= 0 && r1 < N && c1 >= 0 && c1 < N)
								if (M(r1, c1) > 0) {nonzero = M(r1,c1); nonzerocount++;}
							if (r1 >= 0 && r1 < N && c2 >= 0 && c2 < N)
								if (M(r1, c2) > 0) {nonzero = M(r1,c2); nonzerocount++;}
							if (r2 >= 0 && r2 < N && c1 >= 0 && c1 < N)
								if (M(r2, c1) > 0) {nonzero = M(r2,c1); nonzerocount++;}
							if (r2 >= 0 && r2 < N && c2 >= 0 && c2 < N)
								if (M(r2, c2) > 0) {nonzero = M(r2,c2); nonzerocount++;}
						}
					}

					if (nonzerocount == 1) O(i,j) = nonzero;
					if (nonzerocount > 0) break;
				}
			}

			fprintf(outf, "%d ", O(i,j));
		}
		fprintf(outf, "\n");
	}

	fclose(inf);
	fclose(outf);

	return 0;
}