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 (Python):
h, w = (int(x) for x in input().split())
A = [list(input()) for _ in range(h)]
R = [["."] * w for _ in range(h)]
B = [["."] * w for _ in range(h)]


for i in range(h):
    for j in range(w):
        if 0 < i < h - 1 and 0 < j < w - 1:
            if i % 2 == 1 or (i % 4 == 2 and j == w - 2) or (i % 4 == 0 and j == 1):
                R[i][j] = "
        if R[i][j] != "
            B[i][j] = "

for i in range(h):
    for j in range(w):
        if A[i][j] == "
            R[i][j] = "
            B[i][j] = "

for r in R:
    print("".join(r))
print()
for b in B:
    print("".join(b))

Solution (Python):
h, w = map(int, input().split())
a = [list(input()) for i in range(h)]
ta = [["."] * w for i in range(h)]
ao = [["."] * w for i in range(h)]
for i in range(h):
    if i % 2 == 0:
        for j in range(w - 1):
            ta[i][j] = "
        ao[i][-1] = "
    else:
        for j in range(1, w):
            ao[i][j] = "
        ta[i][0] = "
for i in range(h):
    for j in range(w):
        if a[i][j] == "
            ta[i][j] = "
            ao[i][j] = "
for i in range(h):
    print(*ta[i], sep="")
print()
for i in range(h):
    print(*ao[i], sep="")

Solution (Python):
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
A = np.frombuffer(read(), 'S1').reshape(N, -1)[:, :M] == b'

R = np.full((N, M), '.')
B = np.full((N, M), '.')
s = '
R[A] = s
B[A] = s
R[:, 0] = s
B[:, -1] = s
R[::2, :-1] = s
B[1::2, 1:] = s

print('\n'.join(''.join(row) for row in R.tolist()))
print()
print('\n'.join(''.join(row) for row in B.tolist()))

Solution (Python):
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
u = [["."] * w for _ in range(h)]
v = [["."] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if a[i][j] == "
            u[i][j], v[i][j] = "
        else:
            if i == 0:
                u[i][j] = "
            elif i == h - 1:
                v[i][j] = "
            else:
                if j % 2 == 0:
                    u[i][j] = "
                else:
                    v[i][j] = "
for s in u:
    print("".join(s))
print()
for t in v:
    print("".join(t))

Solution (Python):
h, w = map(int, input().split())
G = [input() for _ in range(h)]
R = [["."]*w for _ in range(h)]
B = [["."]*w for _ in range(h)]
for i in range(1, h-1):
  if i%2:
    R[i] = list("." + "
    B[i] = list(G[i])
  else:
    B[i] = list("." + "
    R[i] = list(G[i])
    
for i in range(h):
  R[i][0] = "
  B[i][-1] = "
for r in R:
  print("".join(r))
print()
for b in B:
  print("".join(b))

Solution (Python):
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))


def main():
	H, W = getlist()
	L = []
	for i in range(H):
		l = list(input())
		L.append(l)

	redTable = [["."] * W for i in range(H)]
	blueTable = [["."] * W for i in range(H)]
	for i in range(H):
		redTable[i][0] = "
		blueTable[i][-1] = "

	for i in range(H):
		if i % 2 == 0:
			for j in range(1, W - 1):
				redTable[i][j] = "
		else:
			for j in range(1, W - 1):
				blueTable[i][j] = "

	
	
	
	
	

	for i in range(H):
		for j in range(1, W - 1):
			if L[i][j] == "
				if i % 2 == 0:
					blueTable[i][j] = "
				else:
					redTable[i][j] = "

	for i in range(H):
		print("".join(redTable[i]))
	print()
	for i in range(H):
		print("".join(blueTable[i]))

if __name__ == '__main__':
	main()

Solution (Python):
h, w= map(int, input().split())
a = [['.']*w for _ in range(h)]
b = [['.']*w for _ in range(h)]
for i in range(h):
  s = input()
  for j in range(w):
    if i % 2 and j != w - 1 or j == 0 or s[j] == '
      a[i][j] = '
    if (i+1) % 2 and j != 0 or j == w - 1 or s[j] == '
      b[i][j] = '
for x in a + [[]] + b :
  print(''.join(x))

Solution (Python):
import sys
input = sys.stdin.readline

H, W = map(int, input().split())
state = [list(input().rstrip()) for _ in range(H)]

ans = [[["."]*W for _ in range(H)] for _ in range(2)]

color = 0 
was_blank = False 
for h in range(H):
    must_color = []
    for w in range(W):
        if state[h][w] == "
            must_color.append(w)
    if not must_color:
        if not was_blank:
            color ^= 1
        for w in range(1, W):
            ans[color][h][w] = "
        ans[color^1][h][0] = "
        was_blank = True
    else:
        color ^= 1
        for w in range(W):
            ans[color][h][w] = "
        for w in must_color:
            ans[color^1][h][w] = "
        was_blank = False

for h in range(H):
    print("".join(ans[0][h]))
print()
for h in range(H):
    print("".join(ans[1][h]))

Solution (Python):
h, w = map(int, input().split())
empty_row = ['.'] * w
a_empty_row = ['
a_filled_row = ['
b_empty_row = ['.'] * (w - 1) + ['
b_filled_row = ['.'] + ['

violet = [input() for _ in range(h)]

aaa = []
bbb = []
for i in range(h):
    if i % 2 == 0:
        aaa.append(a_filled_row.copy())
        bbb.append(b_empty_row.copy())
    else:
        aaa.append(a_empty_row.copy())
        bbb.append(b_filled_row.copy())
for i in range(1, h - 1):
    for j in range(1, w - 1):
        if violet[i][j] == '
            aaa[i][j] = '
            bbb[i][j] = '
print('\n'.join(''.join(row) for row in aaa))
print()
print('\n'.join(''.join(row) for row in bbb))

Solution (Python):
h,w=[int(x) for x in input().split()]

a=[input() for i in range(h)]

r=[['.' for i in range(w)]for j in range(h)]
b=[['.' for i in range(w)]for j in range(h)]

for i in range(h):
  r[i][0]='
  b[i][w-1]='
  if i%2==0:
    for j in range(w-1):
      r[i][j]='
  else:
    for j in range(1,w):
      b[i][j]='

for i in range(h):
  for j in range(w):
    if a[i][j]=='
      r[i][j]='
      b[i][j]='
  
for i in range(h):
  print("".join(r[i]))
  
print()
for i in range(h):
  print("".join(b[i]))

Solution (Python):

"""
Writer: SPD_9X2
https://atcoder.jp/contests/agc004/tasks/agc004_c
i = 0は全て青
i = H-1は全て赤に塗る

それ以外に関して、
j % 2 == 0なら全て青、
j % 2 == 1なら全て赤に塗れば、あとはどこを紫にしても連結条件が保たれる

あとは紫にするポイントを紫にしてしまえば終わり!

"""

H,W = map(int,input().split())

a = []
for i in range(H):
    A = list(input())
    a.append(A)

ans1 = [["."] * W for i in range(H)]
ans2 = [["."] * W for i in range(H)]

for i in range(H):

    for j in range(W):

        if i == 0:
            ans1[i][j] = "
            continue
        if i == H-1:
            ans2[i][j] = "
            continue

        if a[i][j] == "
            ans1[i][j] = "
            ans2[i][j] = "
        elif j % 2 == 0:
            ans1[i][j] = "
        else:
            ans2[i][j] = "

for i in ans1:
    print ("".join(i))
print ("")
for i in ans2:
    print ("".join(i))

Solution (Python):
def examA():
    A, B, C = LI()
    ans = min(A*B*(C%2),A*C*(B%2),B*C*(A%2))
    print(ans)
    return

def examB():
    class segment_():
        def __init__(self, A, n, segfunc):
            
            self.ide_ele = inf
            
            self.num = 1 << (n - 1).bit_length()
            self.seg = [self.ide_ele] * 2 * self.num
            self.segfunc = segfunc
            
            for i in range(n):
                self.seg[i + self.num] = A[i]
                
            for i in range(self.num - 1, 0, -1):
                self.seg[i] = self.segfunc(self.seg[2 * i], self.seg[2 * i + 1])

        def update(self, k, r):
            k += self.num
            self.seg[k] = r
            while k:
                k >>= 1
                self.seg[k] = self.segfunc(self.seg[k * 2], self.seg[k * 2 + 1])

        
        def update1(self, k):
            k += self.num
            self.seg[k] += 1
            while k:
                k >>= 1
                self.seg[k] = self.segfunc(self.seg[k * 2], self.seg[k * 2 + 1])

        def updateneg1(self, k):
            k += self.num
            self.seg[k] -= 1
            while k:
                k >>= 1
                self.seg[k] = self.segfunc(self.seg[k * 2], self.seg[k * 2 + 1])

        def query(self, p, q):
            if q < p:
                return self.ide_ele
            p += self.num;
            q += self.num
            res = self.ide_ele
            while p < q:
                if p & 1 == 1:
                    res = self.segfunc(res, self.seg[p])
                    p += 1
                if q & 1 == 1:
                    q -= 1
                    res = self.segfunc(res, self.seg[q])
                p >>= 1;
                q >>= 1
            return res
    N, x = LI()
    A = LI()
    Seg_min = segment_(A, N, lambda a, b: min(a,b))
    ans = inf
    for k in range(N):
        cur = 0
        for j in range(N):
            if j-k>=0:
                now = Seg_min.query(j-k,j+1)
            else:
                now = min(Seg_min.query(0,j+1),Seg_min.query(N-(k-j),N))

            cur += now
        ans = min(ans,cur+k*x)

    print(ans)
    return

def examC():
    H, W = LI()
    A = [SI()for _ in range(H)]
    T = [""for _ in range(H)]
    S = [""for _ in range(H)]
    for h in range(H):
        T[h] += "
        S[h] += "."
    for h in range(H):
        for w in range(1,W-1):
            if h%2==0:
                T[h] += "
            elif A[h][w]=="
                T[h] += "
            else:
                T[h] += "."
            if h%2==1:
                S[h] += "
            elif A[h][w]=="
                S[h] += "
            else:
                S[h] += "."
    for h in range(H):
        T[h] += "."
        S[h] += "
    for v in T:
        print(v)
    print()
    for v in S:
        print(v)
    return

def examD():
    N, K = LI()
    A = LI()
    V = [[]for _ in range(N)]
    ans = 0
    if A[0]!=1:
        ans += 1
        A[0] = 1
    for i in range(1,N):
        V[A[i]-1].append(i)
    def dfs(p,s):
        depth = 0
        cnt = 0
        for i in V[s]:
            d,c = dfs(s,i)
            depth = max(depth,d)
            cnt += c
        depth += 1
        if depth==K and p!=0:
            depth = 0
            cnt += 1
        return depth,cnt
    _,cnt = dfs(0,0)
    ans += cnt
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LFI(): return list(map(float,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examC()

"""

"""

Solution (Python):
h,w = map(int,input().split())
grid = [list(input()) for i in range(h)]
black = [[1 for i in range(w)] for j in range(h)]
white = [[1 for i in range(w)] for j in range(h)]
for i in range(h):
  for j in range(w):
    if i%2 and j%2 == 0:
      black[i][j] = 0
    elif i%2 == 0 and j%2:
      white[i][j] = 0
for i in range(h):
  for j in range(w):
    if grid[i][j] == "
      black[i][j] = 1
      white[i][j] = 1
    else:
      if i%2 == 0:
        white[i][j] = 0
      else:
        black[i][j] = 0
for i in range(h):
  black[i][0] = 0
  black[i][w-1] = 1
  white[i][0] = 1
  white[i][w-1] = 0
for i in range(w):
  black[0][i] = 1
  black[h-1][i] = 0
  white[0][i] = 0
  white[h-1][i] = 1

for i in range(h):
  for j in range(w):
    if black[i][j]:
      print("
    else:
      print(".",end="")
  print()
print()
for i in range(h):
  for j in range(w):
    if white[i][j]:
      print("
    else:
      print(".",end="")
  print()

Solution (Python):
h, w = map(int, input().split())
ans1 = [['.'] * w for _ in range(h)]
ans2 = [['.'] * w for _ in range(h)]
for i in range(h):
    ans1[i][0] = '
    ans2[i][-1] = '
    if i % 2:
        for j in range(w - 1):
            ans1[i][j] = '
    else:
        for j in range(1, w):
            ans2[i][j] = '
for i in range(h):
    s = input()
    for j in range(w):
        if s[j] == '
            ans1[i][j] = '
            ans2[i][j] = '
for row in ans1:
    print(''.join(row))
print()
for row in ans2:
    print(''.join(row))

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline

    H, W = map(int, input().split())
    grid_p = []
    for _ in range(H):
        grid_p.append(input().rstrip('\n'))

    grid_r = [['.'] * W for _ in range(H)]
    grid_b = [['.'] * W for _ in range(H)]
    for w in range(W):
        grid_r[0][w] = '
        grid_b[-1][w] = '
    for h in range(1, H-1):
        for w in range(W):
            if w%2:
                grid_r[h][w] = '
            else:
                grid_b[h][w] = '
    for h in range(H):
        for w in range(W):
            if grid_p[h][w] == '
                grid_r[h][w] = '
                grid_b[h][w] = '

    [print(''.join(line)) for line in grid_r]
    print('')
    [print(''.join(line)) for line in grid_b]

    '''
    ans = [['.'] * W for _ in range(H)]
    for h in range(H):
        for w in range(W):
            if grid_r[h][w] == grid_b[h][w] == '
                ans[h][w] = '
    print('')
    [print(''.join(line)) for line in ans]
    '''


if __name__ == '__main__':
    main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

H,W = map(int,readline().split())
A = (np.frombuffer(read(),'S1').reshape(H,-1)[:,:W] == b'

R = np.zeros((H,W),np.int8)
R[0] = 1
R[:-1,::2] = 1
B = 1 - R

R |= A; B |= A

R = np.where(R,'
B = np.where(B,'

print('\n'.join(''.join(row) for row in R))
print()
print('\n'.join(''.join(row) for row in B))

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

H,W = map(int,readline().split())
A = np.frombuffer(read(),'S1').reshape(H,-1)[:,:W]

red = np.full((H,W),'.','U1')
blue = np.full((H,W),'.','U1')

red[0] = '
red[:-1,::2] = '
blue[-1] = '
blue[1:,1::2] = '

both = (A == b'
red[both] = '
blue[both] = '

def output_grid(A):
    print('\n'.join(''.join(row) for row in A))

output_grid(red)
print()
output_grid(blue)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    h,w = LI()
    a = [input() for i in range(h)]
    r = [list("
    b = [list("."*(w-1)+"
    for i in range(h):
        if i&1:
            r[i] = list("
        else:
            b[i] = list("."+"

    for i in range(h):
        for j in range(w):
            if a[i][j] == "
                r[i][j] = "
                b[i][j] = "
    for i in r:
        print(*i,sep = "")
    print()
    for i in b:
        print(*i,sep = "")
    return


if __name__ == "__main__":
    solve()

Solution (Python):
H, W = map(int, input().split())
G = [list(map(lambda x: x == '
Takahashi = [[False]*W for _ in range(H)]
Aoki = [[False]*W for _ in range(H)]

for h in range(H):
    for w in range(W):
        if w == 0:
            Takahashi[h][w] = True
        elif not h & 1:
            Aoki[h][w] = True
        if w == W-1:
            Aoki[h][w] = True
        elif h & 1:
            Takahashi[h][w] = True
        
        if G[h][w]:
            Takahashi[h][w] = True
            Aoki[h][w] = True

print('\n'.join([''.join(['
print('')
print('\n'.join([''.join(['

Solution (Python):
import sys

import numpy as np

H,W = map(int,sys.stdin.buffer.readline().split())
purple = np.frombuffer(sys.stdin.buffer.read(),dtype='S1').reshape(H,-1)[:,:W].astype(str)

red = np.full((H,W),'.',dtype='U1')
blue = np.full((H,W),'.',dtype='U1')

red[:,::2] = '
red[-1] = '.'
red[0] = '
blue[:,1::2] = '
blue[-1] = '
blue[0] = '.'

is_purple = purple == '
red[is_purple] = '
blue[is_purple] = '

print('\n'.join(''.join(row) for row in red))
print()
print('\n'.join(''.join(row) for row in blue))

Solution (Python):
H, W = map(int, input().split())
A1 = ["
A2 = ["."*W]
input()
for i in range(H-2):
    A = input()
    s = ""
    for j, c in enumerate(A):
        if j%2 or c=="
            s += "
        else:
            s += "."
    A1.append(s)
    s = ""
    for j, c in enumerate(A):
        if j%2==0 or c=="
            s += "
        else:
            s += "."
    A2.append(s)
A1.append("."*W)
A2.append("
print("\n".join(A1))
print()
print("\n".join(A2))

Solution (Python):
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


H, W = list(map(int, sys.stdin.readline().split()))
A = [list(sys.stdin.readline().rstrip()) for _ in range(H)]

R = []
B = []

for h in range(H):
    if h & 1:
        red = list('.' * (W - 1) + '
        blue = list('
    else:
        red = list('.' + '
        blue = list('
    R.append(red)
    B.append(blue)

for h, w in itertools.product(range(H), range(W)):
    if A[h][w] == '
        R[h][w] = '
        B[h][w] = '

print('\n'.join(map(lambda r: ''.join(r), R)))
print()
print('\n'.join(map(lambda r: ''.join(r), B)))

Solution (Python):
def main():
    H, W = map(int, input().split())
    A = [input() for _ in range(H)]
    ansr = [None for _ in range(H)]
    ansb = [None for _ in range(H)]
    for i in range(0, H):
        if i % 2 == 0:
            ansr[i] = ["
            ansb[i] = ["."] * (W-1) + ["
        else:
            ansr[i] = ["
            ansb[i] = ["."] + ["
    for i in range(H):
        for j in range(W):
            if A[i][j] == "
                ansr[i][j] = "
                ansb[i][j] = "
    for i in range(H):
        print("".join(ansr[i]))
    print()
    for i in range(H):
        print("".join(ansb[i]))


if __name__ == "__main__":
    main()

Solution (Python):
h,w = map(int,input().split())
a = [list(input()) for _ in range(h)]

def printboard(board):
    for i in board:
        print(*i, sep='')

red = [['.'] * w for _ in range(h)]
blue = [['.'] * w for _ in range(h)]

for i in range(h):
    red[i][0] = '
    blue[i][-1] = '
    for j in range(1, w - 1):
        if i % 2 == 0:
            red[i][j] = '
        else:
            blue[i][j] = '

for i in range(h):
    for j in range(w):
        if a[i][j] == '
            red[i][j] = '
            blue[i][j] = '

printboard(red)
print()
printboard(blue)

Solution (Python):



ae,be='',''
h,w=map(int,input().split())
a=[['
b=[['

a[-1]=['.' for i in range(w)]
b[0]=['.' for i in range(w)]

if w%2==1:
        ae='
        be='.'

for i in range(1,h-1):
    x,y='
    for j in range(w):
        a[i][j]=x
        b[i][j]=y
        x,y=y,x

for i in range(h):
    s=input()
    for j in range(w):
        if s[j]=='
            a[i][j]='
            b[i][j]='

for i in range(h):
    print(''.join(a[i]))
print('')
for i in range(h):
    print(''.join(b[i]))

Solution (Python):
H,W = list(map(int,input().split()))

a = [input() for i in range(H)]

b = [[] for i in range(H)]
r = [[] for i in range(H)]
for i in range(H):
    for j in range(W):
        if i==0:
            b[i].append("
            r[i].append(".")
        elif i==H-1:
            b[i].append(".")
            r[i].append("
        elif a[i][j]=="
            b[i].append("
            r[i].append("
        elif j%2==0:
            b[i].append(".")
            r[i].append("
        elif j%2==1:
            b[i].append("
            r[i].append(".")

for i in range(H):
    ans = ""
    for j in range(W):
        ans = ans+b[i][j]

    print(ans)
print("")

for i in range(H):
    ans = ""
    for j in range(W):
        ans = ans+r[i][j]

    print(ans)

Solution (Python):
H, W = map(int, input().split())
Ass = [input() for _ in range(H)]

redss = [['
bluess = [['.']*(W-1)+['

for i in range(H):
    if i % 2:
        redss[i]= ['
    else:
        bluess[i] = ['.']+['

for i in range(H):
    for j in range(W):
        if Ass[i][j] == '
            redss[i][j] = '
            bluess[i][j] = '

print('\n'.join(map(''.join, redss)))
print()
print('\n'.join(map(''.join, bluess)))

Solution (Python):
import sys
input = sys.stdin.readline
import copy
from collections import deque

H,W=map(int,input().split())
A=[[0]*W for i in range(H)]
for i in range(H):
    S=input()
    for j in range(W):
        A[i][j]=S[j]
C=copy.deepcopy(A)
for h in range(W):
    C[0][h]='
for j in range(W):
    if j%2==1:
        for i in range(H-1):
            C[i][j]='
D=copy.deepcopy(A)
for h in range(W):
    D[-1][h]='
for j in range(W):
    if j%2==0:
        for i in range(1,H):
            D[i][j]='
for i in range(H):
    print(''.join(C[i]))
print()
for i in range(H):
    print(''.join(D[i]))

Solution (Python):
H, W = map(int, input().split())
A = []
for _ in range(H):
    A.append(input())

x, y = [], []
for i, a in enumerate(A):
    if i % 2:
        y.append('
        x.append('.' + '
    else:
        x.append(a[:-1] + '
        y.append('

print(*x, sep='\n')
print('')
print(*y, sep='\n')

Solution (Python):
readline = open(0).readline
writelines = open(1, 'w').writelines
H, W = map(int, readline().split())
S = []; T = []
for i in range(H):
    for j, a in enumerate(readline().strip()):
        if a == "
            S.append("
        else:
            if j == 0:
                S.append("
            elif j == W-1:
                S.append("."); T.append("
            elif i % 2 == 0:
                S.append("
            else:
                S.append("."); T.append("
    S.append("\n")
    T.append("\n")
S.append("\n")

writelines(S)
writelines(T)

Solution (Python):
H, W = map(int, input().split())
a = [list(input()) for _ in range(H)]
ans = [["r" for _ in range(W)]] + [["." for _ in range(W)] for _ in range(H-2)] + [["b" for _ in range(W)]]

for h in range(1, H-1):
	for w in range(W):
		if a[h][w] == "
			ans[h][w] = "p"
		elif w % 2 == 0:
			ans[h][w] = "r"
		else:
			ans[h][w] = "b"

r = [["." for _ in range(W)] for _ in range(H)]
for h in range(H):
	for w in range(W):
		if ans[h][w] == "p" or ans[h][w] == "r":
			r[h][w] = "
for h in range(H):
	print("".join(r[h]))

print("\n")

b = [["." for _ in range(W)] for _ in range(H)]
for h in range(H):
	for w in range(W):
		if ans[h][w] == "p" or ans[h][w] == "b":
			b[h][w] = "
for h in range(H):
	print("".join(b[h]))

Solution (Python):
H,W=map(int,input().split())
Map=[input() for i in range(H)]
Base1,Base2=[],[]
for i in range(H):
  if i%2==0:
    Base1.append(["
    Base2.append(["."]*(W-1)+["
  elif i%2==1:
    Base1.append(["
    Base2.append(["."]+["
for i in range(H):
  for j in range(W):
    if Map[i][j]=="
      Base1[i][j],Base2[i][j]="
for i in range(H):
  print("".join(Base1[i]))
print()
for i in range(H):
  print("".join(Base2[i]))

Solution (Python):
h,w = (int(i) for i in input().split())
a = [input() for i in range(h)]
r,b = [["
x = ["
for i in range(h):
	for j in range(1,w-1):
		if a[i][j]=="
			r[i].append("
			b[i].append("
		else:
			r[i].append(x[i%2])
			b[i].append(x[1-i%2])
	r[i].append(".")
	b[i].append("
for i in range(h): print("".join(r[i]))
print()
for i in range(h): print("".join(b[i]))

Solution (Python):
h, w = map(int, input().split())

arr = []
exist = []

for i in range(h):
    s = input()
    a = []
    f = 0
    for j in range(w):
        if s[j] == '
            a.append(1)
            f = 1
        else:
            a.append(0)
    arr.append(a)
    if f == 1:
        exist.append(1)
    else:
        exist.append(0)
    
red = [[0 for i in range(w)] for j in range(h)]
blue = [[0 for i in range(w)] for j in range(h)]

flag = 0 
pre_non_exist = 0
for i in range(h):
    if i == 0:
        for j in range(w):
            red[i][j] = 1
        flag = 1
    elif exist[i] == 1 and flag == 1:
        pre_non_exist = 0
        for j in range(w):
            blue[i][j] = 1
            if arr[i][j] == 1:
                red[i][j] = 1
        flag = 0
    elif exist[i] == 1 and flag == 0:
        pre_non_exist = 0
        for j in range(w):
            red[i][j] = 1
            if arr[i][j] == 1:
                blue[i][j] = 1
        flag = 1
    else:
        if pre_non_exist == 0:
            flag = (flag + 1) % 2
        pre_non_exist = 1
        if flag == 0:
            for j in range(w):
                if j == 0 or j == w-1:
                    red[i][j] = 1
                else:
                    blue[i][j] = 1
        else:
            for j in range(w):
                if j == 0 or j == w-1:
                    blue[i][j] = 1
                else:
                    red[i][j] = 1
                    
                    
for i in range(h):
    s = ""
    for j in range(w):
        if red[i][j] == 1:
            s = s + '
        else:
            s = s + '.'
    print(s)

print()

for i in range(h):
    s = ""
    for j in range(w):
        if blue[i][j] == 1:
            s = s + '
        else:
            s = s + '.'
    print(s)

Solution (Python):
H,W=map(int,input().split())
a=[list(input()) for i in range(H)]
b=[["." for i in range(W)] for i in range(H)]
c=[["." for i in range(W)] for i in range(H)]
for i in range(H):
    c[i][0]="
    b[i][-1]="
for i in range(H):
    for j in range(W):
        if i%2==0:
            b[i][j]="
        else:
            c[i][j]="
for i in range(H):
    c[i][-1]="."
    b[i][0]="."
for i in range(H):
    for j in range(W):
        if a[i][j]=="
            b[i][j]="
            c[i][j]="

for i in b:
    print("".join(i))
print()
for i in c:
    print("".join(i))

Solution (Python):
H, W = map( int, input().split())
V = [ input() for _ in range(H)]
B = [ '' for _ in range(H)]
R = [ '' for _ in range(H)]
N = '
for i in range(H):
    if i%2 == 0:
        B[i] = N+V[i][-1]
        R[i] = V[i][:W-1] + '
    else:
        R[i] = V[i][-1] + N
        B[i] = '
for i in range(H):
    print(B[i])
print('')
for i in range(H):
    print(R[i])

Solution (Python):
h,w=map(int,input().split());r=[list('
for i in range(h):
  t=input()
  for j in range(w):
    if t[j]=='
for t in r:print(''.join(t))
print()
for t in b:print(''.join(t))

Solution (Python):
h,w=map(int,input().split());r=[list('
for i in range(h):
  t=input()
  for j in range(w):
    if t[j]=='
for t in r:print(''.join(t))
print()
for t in b:print(''.join(t))

Solution (Python):


INF = float('inf')


def inpl(): return list(map(int, input().split()))


H, W = inpl()

X = [list(input()) for _ in range(H)]

A = [['.' for _ in range(W)] for _ in range(H)]
B = [['.' for _ in range(W)] for _ in range(H)]
tmp = ['
for i in range(H):
    if i % 2 == 0:
        A[i][:-1] = tmp
        B[i][-1] = '
    else:
        B[i][1:] = tmp
        A[i][0] = '

for h in range(H):
    for w in range(W):
        if X[h][w] == '
            A[h][w] = '
            B[h][w] = '

for a in A:
    print(''.join(a))
print('')
for b in B:
    print(''.join(b))

Solution (Python):
H,W=[int(i) for i in input().split()]
a=[input() for i in range(H)]

R = [[False for i in range(W)] for j in range(H)]
B = [[False for i in range(W)] for j in range(H)]


for i in range(H):
	R[i][0] = B[i][-1] = True
	if i%2 == 0:
		for j in range(1,W-1):
			R[i][j] = True
	else:
		for j in range(1,W-1):
			B[i][j] = True


for i in range(H):
	for j in range(W):
		if a[i][j] == '
			R[i][j] = B[i][j] = True


for row in R:
	for col in row:
		print('
	print()
print()
for row in B:
	for col in row:
		print('
	print()

Solution (Python):
H,W=map(int,input().split())
P=[input() for _ in range(H)]

red=[['.' for x in range(W)]for y in range(H)]
blue=[['.' for x in range(W)]for y in range(H)]

for i in range(H):
  red[i][0]='
  blue[i][W-1]='
  for j in range(1,W-1):
    if i%2==0:
      red[i][j]='
    else:
      blue[i][j]='

for i in range(1,H-1):
  for j in range(1,W-1):
    if P[i][j]=='
      red[i][j]='
      blue[i][j]='
      
for i in range(H):
  print(''.join(red[i]))
print("")
for i in range(H):
  print(''.join(blue[i]))