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 Rust (1.15.1) (judge verdict: Wrong Answer)

macro_rules !read_value {($iter :expr ,($($t :tt ) ,*) ) =>{($(read_value !($iter ,$t ) ) ,*) } ;($iter :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($iter ,$t ) ) .collect ::<Vec <_ >>() } ;($iter :expr ,{chars :$base :expr } ) =>{read_value !($iter ,String ) .chars () .map (|c |(c as u8 -$base as u8 ) as usize ) .collect ::<Vec <usize >>() } ;($iter :expr ,{char :$base :expr } ) =>{read_value !($iter ,{chars :$base } ) [0 ] } ;($iter :expr ,chars ) =>{read_value !($iter ,String ) .chars () .collect ::<Vec <char >>() } ;($iter :expr ,char ) =>{read_value !($iter ,chars ) [0 ] } ;($iter :expr ,usize1 ) =>{read_value !($iter ,usize ) -1 } ;($iter :expr ,$t :ty ) =>{$iter .next () .unwrap () .parse ::<$t >() .unwrap () } ;}
macro_rules !input_inner {($iter :expr ) =>{} ;($iter :expr ,) =>{} ;($iter :expr ,mut $var :ident :$t :tt $($r :tt ) *) =>{let mut $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,mut $var :ident $($r :tt ) *) =>{input_inner !{$iter ,mut $var :usize $($r ) *} } ;($iter :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,$var :ident $($r :tt ) *) =>{input_inner !{$iter ,$var :usize $($r ) *} } ;}
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;(iter =$iter :ident ,$($r :tt ) *) =>{let s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut $iter =s .split_whitespace () ;input_inner !{$iter ,$($r ) *} } ;($($r :tt ) *) =>{let s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut iter =s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;}
pub struct GridGraph {
    height: usize,
    width: usize,
}
impl GridGraph {
    pub fn new(height: usize, width: usize) -> Self {
        GridGraph {
            height: height,
            width: width,
        }
    }
    pub fn len_adjacency(&self, x: usize, y: usize) -> usize {
        (x + 1 < self.height) as usize
            + (y + 1 < self.width) as usize
            + (x > 0) as usize
            + (y > 0) as usize
    }
    pub fn for_each_adjacency<F: FnMut(usize, usize)>(&self, x: usize, y: usize, mut f: F) {
        if x + 1 < self.height {
            f(x + 1, y);
        }
        if y + 1 < self.width {
            f(x, y + 1);
        }
        if x > 0 {
            f(x - 1, y);
        }
        if y > 0 {
            f(x, y - 1);
        }
    }
}
fn main() {
    input!(h, w, a: [chars; h]);
    let mut cnt = 0;
    let gg = GridGraph::new(h, w);
    let mut g = vec![vec![0; w]; h];
    let mut vis = vec![vec![false; w]; h];
    let mut que = std::collections::VecDeque::new();
    let mut p = (0, 0);
    for i in 0..h {
        for j in 0..w {
            if !vis[i][j] && a[i][j] == '#' {
                p = (i, j);
                cnt += 1;
                vis[i][j] = true;
                que.push_back((i, j));
                while let Some((i, j)) = que.pop_front() {
                    g[i][j] = cnt;
                    gg.for_each_adjacency(i, j, |x, y| {
                        if !vis[x][y] && a[x][y] == '#' {
                            vis[x][y] = true;
                            que.push_back((x, y));
                        }
                    });
                }
            }
        }
    }
    let mut r = vec![vec![false; w]; h];
    let mut b = vec![vec![false; w]; h];
    let mut par = vec![vec![None; w]; h];
    let mut connected = std::collections::HashSet::new();
    connected.insert(cnt);
    que.push_back(p);
    while let Some((i, j)) = que.pop_front() {
        gg.for_each_adjacency(i, j, |x, y| {
            if par[x][y].is_some() || r[x][y] {
                return;
            }
            let prevl = connected.len();
            par[x][y] = Some((i, j));
            gg.for_each_adjacency(x, y, |nx, ny| {
                if (i, j) != (nx, ny) {
                    if g[nx][ny] > 0 && !connected.contains(&g[nx][ny]) {
                        connected.insert(g[nx][ny]);
                    }
                }
            });
            if prevl < connected.len() {
                r[x][y] = true;
                let (mut x, mut y) = (x, y);
                while let Some((px, py)) = par[x][y] {
                    x = px;
                    y = py;
                    r[x][y] = true;
                }
            }
            que.push_back((x, y));
        });
        if connected.len() >= cnt {
            que.clear();
        }
    }
    que.push_back(p);
    while let Some((i, j)) = que.pop_front() {
        gg.for_each_adjacency(i, j, |x, y| {
            if r[x][y] || b[x][y] {
                return;
            }
            b[x][y] = true;
            que.push_back((x, y));
        });
    }
    for i in 0..h {
        println!(
            "{}",
            (0..w)
                .map(|j| if r[i][j] || a[i][j] == '#' { '#' } else { '.' })
                .collect::<String>()
        );
    }
    println!("");
    for i in 0..h {
        println!(
            "{}",
            (0..w)
                .map(|j| if b[i][j] || a[i][j] == '#' { '#' } else { '.' })
                .collect::<String>()
        );
    }
}