Problem:
Score : 700 points

Problem Statement

Snuke and Ciel went to a strange stationery store. Each of them got a transparent graph paper with H rows and W columns.

Snuke painted some of the cells red in his paper. Here, the cells painted red were 4-connected, that is, it was possible to traverse from any red cell to any other red cell, by moving to vertically or horizontally adjacent red cells only.

Ciel painted some of the cells blue in her paper. Here, the cells painted blue were 4-connected.

Afterwards, they precisely overlaid the two sheets in the same direction. Then, the intersection of the red cells and the blue cells appeared purple.

You are given a matrix of letters a_{ij} (1≤i≤H, 1≤j≤W) that describes the positions of the purple cells. If the cell at the i-th row and j-th column is purple, then a_{ij} is #, otherwise a_{ij} is .. Here, it is guaranteed that no outermost cell is purple. That is, if i=1, H or j = 1, W, then a_{ij} is ..

Find a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation described. It can be shown that a solution always exists.

Constraints

3≤H,W≤500

a_{ij} is # or ..

If i=1,H or j=1,W, then a_{ij} is ..

At least one of a_{ij} is #.

Input

The input is given from Standard Input in the following format:

H W
a_{11}...a_{1W}
:
a_{H1}...a_{HW}

Output

Print a pair of the set of the positions of the red cells and the blue cells that is consistent with the situation, as follows:

The first H lines should describe the positions of the red cells.

The following 1 line should be empty.

The following H lines should describe the positions of the blue cells.

The description of the positions of the red or blue cells should follow the format of the description of the positions of the purple cells.

Sample Input 1

5 5
.....
.#.#.
.....
.#.#.
.....

Sample Output 1

.....
#####
#....
#####
.....

.###.
.#.#.
.#.#.
.#.#.
.....

One possible pair of the set of the positions of the red cells and the blue cells is as follows:

Sample Input 2

7 13
.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#.###.###.
.............

Sample Output 2

.............
.###########.
.###.###.###.
.###.###.###.
.###.###.###.
.###.###.###.
.............

.............
.###.###.###.
.#.#.#...#...
.###.#...#...
.#.#.#.#.#...
.#.#########.
.............

One possible pair of the set of the positions of the red cells and the blue cells is as follows:

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
static class Program{
	const int mod=1000000007;
	static readonly int[][] di=new int[][]{new int[]{-1,0},new int[]{1,0},new int[]{0,-1},new int[]{0,1}};
	static int[] s,b;
	static string[] st;
	static char[][] c;
	static void Main(){
		Sc sc=new Sc();
		s=sc.Ia;
		int m=0,f=0;
		b=new int[s[0]*s[1]];
		st=new string[s[0]];
		c=new char[s[0]][];
		Uf uf=new Uf(s[0]*s[1]);
		bool[] h=new bool[s[0]*s[1]];
		for(int i = 0;i<s[0];i++){
			st[i]=sc.S;
			c[i]=new string('.',s[1]).ToCharArray();
			for(int j = 0;j<s[1];j++){
				if(st[i][j]=='#'){m++;}
				if(i!=0&&st[i][j]==st[i-1][j]){uf.Union(i*s[1]+j,(i-1)*s[1]+j);}
				if(j!=0&&st[i][j]==st[i][j-1]){uf.Union(i*s[1]+j,i*s[1]+j-1);}
				if(i==0||j==0||i==s[0]-1||j==s[1]-1){b[i*s[1]+j]|=4;}
			}
		}
		var pq=new Pq<Mo<int[]>>(32,true);
		pq.Push(new Mo<int[]>(0,new int[]{1,1,-1,-1}));
		while(f!=m&&pq.cnt>0){
			Mo<int[]> q=pq.Top;
			pq.Pop();
			if(b[q.d[0]*s[1]+q.d[1]]%2==1){continue;}
			if(st[q.d[0]][q.d[1]]=='#'){f++;}
			else{
				int g=0;
				for(int i=0;i<4;i++){
					if(b[(q.d[0]+di[i][0])*s[1]+q.d[1]+di[i][1]]%2==1&&st[q.d[0]+di[i][0]][q.d[1]+di[i][1]]=='.'){g+=10;}
					else if(b[(q.d[0]+di[i][0])*s[1]+q.d[1]+di[i][1]]%2==1){g++;}
					if(b[(q.d[0]+di[i][0])*s[1]+q.d[1]+di[i][1]]>=16){g+=100;break;}
				}
				if(g>10){continue;}
			}
			b[q.d[0]*s[1]+q.d[1]]|=1;
			b[uf.Root(q.d[0]*s[1]+q.d[1])]|=2;
			for(int i=0;i<4;i++){
				if((b[(q.d[0]+di[i][0])*s[1]+q.d[1]+di[i][1]]&5)==0){
					if(st[q.d[0]][q.d[1]]=='#'&&st[q.d[0]+di[i][0]][q.d[1]+di[i][1]]=='#'){pq.Push(new Mo<int[]>(0,new int[]{q.d[0]+di[i][0],q.d[1]+di[i][1],q.d[0],q.d[1]}));}
					else if(st[q.d[0]+di[i][0]][q.d[1]+di[i][1]]=='#'){pq.Push(new Mo<int[]>(1,new int[]{q.d[0]+di[i][0],q.d[1]+di[i][1],q.d[0],q.d[1]}));}
					else if(q.d[2]==q.d[0]+di[i][0]||q.d[3]==q.d[1]+di[i][1]){pq.Push(new Mo<int[]>(2,new int[]{q.d[0]+di[i][0],q.d[1]+di[i][1],q.d[0],q.d[1]}));}
					else{pq.Push(new Mo<int[]>(3,new int[]{q.d[0]+di[i][0],q.d[1]+di[i][1],q.d[0],q.d[1]}));}
				}
				if(st[q.d[0]+di[i][0]][q.d[1]+di[i][1]]=='#'&&uf.Total((q.d[0]+di[i][0])*s[1]+q.d[1]+di[i][1])==1){b[(q.d[0]+di[i][0])*s[1]+q.d[1]+di[i][1]]+=8;}
			}
		}
		Fu(0,0);
		StringBuilder sb=new StringBuilder();
		for(int i = 0;i<s[0];i++){
			for(int j = 0;j<s[1];j++){sb.Append(b[i*s[1]+j]%2==1?'#':'.');}
			sb.Append("\n");
		}
		sb.Append("\n");
		for(int i = 0;i<s[0];i++){sb.Append(String.Join("",c[i])+"\n");}
		Console.Write(sb);
	}
	static void Fu(int y,int x){
		c[y][x]='#';
		for(int i=0;i<4;i++){
			if(y+di[i][0]!=-1&&y+di[i][0]!=s[0]&&x+di[i][1]!=-1&&x+di[i][1]!=s[1]&&c[y+di[i][0]][x+di[i][1]]=='.'&&(b[(y+di[i][0])*s[1]+x+di[i][1]]%2==0||st[y+di[i][0]][x+di[i][1]]=='#')){Fu(y+di[i][0],x+di[i][1]);}
		}
	}
}
public class Mo<T>:IComparable{
	public int n;
	public T d;
	public Mo(int n,T d){this.n=n;this.d=d;}
	public int CompareTo(object obj){
		Mo<T> mymo=(Mo<T>)obj;
		if(mymo.n>n){return -1;}
		else if(mymo.n<n){return 1;}
		else{return 0;}
	}
}
public class Pq<T> where T:IComparable{
	private T[] he;
	public int cnt=0,max=0;
	private Func<T,T,int> compare;
	public Pq(int max,bool mm){
		this.max=max;
		he=new T[max];
		if(mm){compare=Ao;}
		else{compare=Do;}
	}
	public void Push(T x){
		if(cnt==max){Extend();}
		int j=cnt;
		while(j!=0&&compare(x,he[(j-1)/2])>0){he[j]=he[(j-1)/2];j=(j-1)/2;}
		he[j]=x;
		cnt++;
	}
	public void Pop(){
		cnt--;
		T r=he[cnt];
		int j=0;
		while(true){
			if(j*2+1<cnt){
				if(compare(he[j*2+1],he[j*2+2])>0){j=j*2+1;}
				else{j=j*2+2;}
			}
			else if(j*2<cnt){j=j*2+1;}
			else{break;}
			if(compare(he[j],r)<=0){j=(j-1)/2;break;}
			he[(j-1)/2]=he[j];
		}
		he[j]=r;
	}
	private int Ao(T x,T y){return y.CompareTo(x);}
	private int Do(T x,T y){return x.CompareTo(y);}
	public T Top{get{return he[0];}}
	private void Extend(){
		T[] nhe=new T[max<<1];
		Array.Copy(he,nhe,max);
		he=nhe;
		max<<=1;
	}
}
public class Uf{
	private int[] arr,hi;
	public int all;
	public Uf(int n){
		arr=new int[n];
		hi=new int[n];
		all=n;
		for(int i=0;i<n;i++){arr[i]=-1;}
	}
	public void Union(int a,int b){
		a=Root(a);
		b=Root(b);
		if(a!=b){
			if(hi[a]<hi[b]){
				int v=b;
				b=a;
				a=v;
			}
			arr[a]+=arr[b];
			hi[a]=Math.Max(hi[a],hi[b]+1);
			arr[b]=a;
			all--;
		}
	}
	public bool Same(int a,int b){return Root(a)==Root(b);}
	public int Total(int a){return -arr[Root(a)];}
	public int Root(int a){return arr[a]<0?a:arr[a]=Root(arr[a]);}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}