
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
//#include <mem.h>

typedef  unsigned int uint;

int main()
{
	FILE* i_file;
	uint N, i, j, tmp, cnt, flag, r, I, J;
	uint **MATRIX;

	i_file=fopen("input.txt","rt");
	printf("%d",i_file);

	fscanf(i_file,"%d",&N);
	MATRIX = (uint**)malloc(4 * N);
	for(i = 0; i < N; i++)
	{
		MATRIX[i] = (uint*)malloc(sizeof(uint) * N);
		for(j = 0; j < N; j++)
		{
			fscanf(i_file,"%d", &tmp);
			MATRIX[i][j] = tmp;
		}
	}
	fclose(i_file);
	
	for(i = 0; i < N; i++)
	{
		for(j = 0; j < N; j++)
		{
			if(MATRIX[i][j]==0)
			{
				tmp = 1; // maximal variabale "radius"
				cnt = 0; //counter of non-zeros
				flag = 1;
				while(flag) //do
				{
					for(r = 0; r < tmp+1; r++)
					{
						if((r < i)&&((tmp - r) < j))
							if(MATRIX[i-r][j-(tmp-r)]!=0) cnt++;
						if(cnt==1)
						{
							I = i - r;
							J = j - (tmp - r);
						}//if  cnt
						if((i + r <= N)&&(j + tmp - r <= N))
							if(MATRIX[i + r][j + tmp - r]!=0) cnt++;
						if(cnt >= 1)
						{
							flag = 0;
							break;
						}//if cnt
					}//for r
					tmp++;
					if(tmp >= N) flag = 0;
				}//while
				if (cnt==1)
					MATRIX[i][j] = MATRIX[I][J];
			}//if MATRIX
		} //for j
	}//for i
	i_file = fopen("output.txt","wt");
	for(i = 0; i < N; i++)
	{
		for(j = 0; j < N; j++)
			fprintf(i_file,"%u ",MATRIX[i][j]);
		if(i < N-1) fprintf(i_file,"\n");

	}
	fclose(i_file);
	return 0;
}