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):


n, m = map(int, raw_input().split())
red = []
blue = []

for i in range(n):
    row = raw_input()
    r = ['
    b = ['.']
    for j in range(1, m - 1):
        if row[j] == '
            r.append('
            b.append('
        else:
            if i % 2 == 0:
                r.append('
                b.append('.')
            else:
                r.append('.')
                b.append('
    r.append('.')
    b.append('
    red.append(''.join(r))
    blue.append(''.join(b))

for r in red:
    print(r)
for b in blue:
    print(b)

Solution (Python):
def recover(purple):
    h = len(purple)
    w = len(purple[0])
    red = []
    blue = []
    for i in xrange(h):
        if (i&1)==0:
            red.append(['
            blue.append(['.' for j in xrange(w-1)]+['
        else:
            red.append(['
            blue.append(['.']+['
        for j in xrange(w):
            if purple[i][j]=='
                red[i][j] = '
                blue[i][j] = '
    return red, blue

def main():
    h, w = [int(i) for i in raw_input().strip().split()]
    purple = []
    for i in xrange(h):
        purple.append(raw_input().strip())
    r, b = recover(purple)
    for line in r:
        print ''.join(line)
    print ''
    for line in b:
        print ''.join(line)

if __name__=='__main__':
    main()

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

ans1 = [['
ans2 = [['.']*(W-1) + ['

for i in range(1,H-1):
    for j in range(1,W-1):
        if i%2:
            ans1[i][j] = '
            ans2[i][j] = src[i][j]
        else:
            ans1[i][j] = src[i][j]
            ans2[i][j] = '

for row in ans1:
    print(''.join(row))
print('')
for row in ans2:
    print(''.join(row))

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10

def check(ans1, ans2, field):
    h, w = len(ans1), len(ans1[0])
    ans = [[0] * w for _ in range(h)]
    for y in range(h):
        for x in range(w):
            c = "
            if field[y][x] != c:
                print(y, x)


def main():
    H, W = map(int, input().split())
    field = []
    for _ in range(H):
        field.append(input())

    ans1, ans2 = [["."] * W for _ in range(H)], [["."] * W for _ in range(H)]
    for i in range(H):
        ans1[i][0] = "
        ans2[i][-1] = "
        if i % 2 == 0:
            ans1[i] = ["
        else:
            ans2[i] = ["."] + ["

    for y in range(H):
        for x in range(W):
            if field[y][x] == "
                if y % 2 == 0:
                    ans2[y][x] = "
                else:
                    ans1[y][x] = "
    
    for line in ans1:
        print("".join(line))
    print()
    for line in ans2:
        print("".join(line))


if __name__ == '__main__':
    main()

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    h,w = LI()
    a = [[c == '
    r = ['
    for c in a[1:-1]:
        t = ''
        for i in range(w):
            ci = c[i]
            if ci or i % 2 == 0:
                t += '
            else:
                t += '.'
        r.append(t)
    r.append('.' * w)
    r.append('')
    r.append('.' * w)
    for c in a[1:-1]:
        t = ''
        for i in range(w):
            ci = c[i]
            if ci or i % 2 == 1:
                t += '
            else:
                t += '.'
        r.append(t)

    r.append('

    return '\n'.join(r)


print(main())

Solution (Python):

import copy
h, w = map(int, input().split())
f = [ list(input()) for _ in range(h) ]
a = copy.deepcopy(f)
b = copy.deepcopy(f)
a[0] = '
for y in range(1, h - 1):
    for x in range(w):
        [a, b][x % 2][y][x] = '
b[h - 1] = '
print(*map(''.join, a), sep='\n')
print()
print(*map(''.join, b), sep='\n')

Solution (Python):

import copy
h, w = map(int, input().split())
f = [ list(input()) for _ in range(h) ]
a = copy.deepcopy(f)
b = copy.deepcopy(f)
for y in range(h):
    for x in range(w):
        if y == 0:
            a[y][x] = '
        elif y == h - 1:
            b[y][x] = '
        else:
            [a, b][x % 2][y][x] = '
print(*map(''.join, a), sep='\n')
print()
print(*map(''.join, b), sep='\n')

Solution (Python):



H, W = map(int, input().split())
blue = [[0] * W for _ in range(H)]
red = [[0] * W for _ in range(H)]

for x in range(W):
    blue[0][x] = 1
    red[-1][x] = 1

for y in range(H-1):
    for x in range(0, W, 2):
        blue[y][x] = 1
        if x + 1 < W:
            red[y+1][x+1] = 1







m = [input() for _ in range(H)]

for color in [red, blue]:
    for y in range(H):
        for x in range(W):
            if m[y][x] == '
                print('
            elif color[y][x] == 1:
                print('
            else:
                print(".", end='')
        print()
    print()

Solution (Python):
import itertools
import random

def genrandom(h, w):
    g = [[0]*w for _ in range(h)]
    for i in range(1, h-1):
        for j in range(1, w-1):
            if random.randint(0,1):
                g[i][j] = 1
    return g

def display(g):
    for i in range(len(g)):
        print(''.join('

h,w = [int(s) for s in input().split()]
g = [[0]*w for _ in range(h)]

for i in range(h):
    s = input()
    for (j,c) in enumerate(s):
        if c == '
            g[i][j] = 1

red = [list(g[i]) for i in range(h)]
blue = [list(g[i]) for i in range(h)]

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

display(red)
print()
display(blue)

Solution (Python):



from __future__ import division, print_function, absolute_import, unicode_literals

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

RED = ["" for _ in range(H)]
BLUE = ["" for _ in range(H)]
for y in range(H):
    s = input()
    RED[y] = s
    BLUE[y] = s
RED[0] = '
BLUE[-1] = '
for y in range(0, H-1):
    tmp = ''
    for x in range(0, W):
        if RED[y][x] == '
            tmp += '
        else:
            tmp += '.'
    RED[y] = tmp
for y in range(1, H-1):
    tmp = ''
    for x in range(0, W):
        if BLUE[y][x] == '
            tmp += '
        else:
            tmp += '.'
    BLUE[y] = tmp

for w in RED:
    print(w)
print()
for w in BLUE:
    print(w)

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

rs = [list("
bs = [list("." + (W-2) * ("

for i, line in enumerate(lines):
    for j, c in enumerate(line):
        if c=="
            rs[i][j] = "
            bs[i][j] = "

print("\n".join(["".join(r) for r in rs]), end="\n"*2)
print("\n".join(["".join(b) for b in bs]), end="\n"*2)

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

def make_red_map():
    red_map = [row[:] for row in a]
    for i in range(0, H, 2):
        for j in range(W - 1):
            if red_map[i][j] == '.':
                red_map[i][j] = '

    for i in range(H):
        
        red_map[i][0] = '

    for i in range(H):
        for j in range(W):
            print(red_map[i][j], end = "")
        print()

def make_blue_map():
    blue_map = [row[:] for row in a]
    for i in range(1, H, 2):
        for j in range(1, W):
            if blue_map[i][j] == '.':
                blue_map[i][j] = '

    for i in range(H):
        
        blue_map[i][W - 1] = '

    for i in range(H):
        for j in range(W):
            print(blue_map[i][j], end = "")
        print()

make_red_map()
print()
make_blue_map()

Solution (Python):
import numpy as np
import copy

a = map(int,raw_input().split())
H = a[0]
W = a[1]
A = []
for idx in xrange(H):
  A.append( list(raw_input()) )

def textMap(A):
  A = np.array(A, dtype='S')
  A[A!='0'] = '
  A[A=='0'] = '.'
  texts = []
  for vec in A:
    texts.append( ''.join(vec) )
  return '\n'.join(texts)

def myfunc(H,W,A):
  A = np.array(A)
  A[A=='
  A[A=='.'] = 0
  A = np.array(A, dtype=np.int)
  T = np.zeros((H,W), dtype=np.int)
  O = np.zeros((H,W), dtype=np.int)
  T[:,0] = 1
  O[:,-1] = 1
  if H%2 == 0:
    for idx in xrange(H/2):
      T[idx*2,1:-1] = 1
      O[idx*2+1,1:-1] = 1
  else:
    for idx in xrange(H/2):
      T[idx*2,1:-1] = 1
      O[idx*2+1,1:-1] = 1
    T[-1,1:-1] = 1
  T[A==1] += 1
  O[A==1] += 1

  tT = textMap(T)
  tO = textMap(O)
  print '\n'.join([tT,'',tO])

myfunc(H,W,A)

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

red = [["." for w in range(W)] for _ in range(H)]
blue = [["." for w in range(W)] for _ in range(H)]

for i in range(H):
    if i % 2 == 0:
        red[i] = ["
        red[i][-1] = "."
    else:
        red[i][0] = "

for i in range(H):
    if i % 2 == 0:
        blue[i][-1] = "
    else:
        blue[i] = ["
        blue[i][0] = "."

for i in range(H):
    for j in range(W):
        if A[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]))

Solution (Python):
h, w = map(int, raw_input().split())
a = [raw_input().strip() for _ in xrange(h)]
for i in xrange(h):
    if i % 2:
        print '
    else:
        print '
print
for i in xrange(h):
    if i % 2:
        print a[i][:-1] + '
    else:
        print '.' + '

Solution (Python):
import bisect
import sys
import math
import itertools
sys.setrecursionlimit(10000)

INF = float('inf')


def i():
    return int(raw_input())
def ii():
    return map(int,raw_input().split(" "))
def s():
    return raw_input()
def ss():
    return raw_input().split(" ")
def slist():
    return list(raw_input())


def join(s):
    return ''.join(s)


def piter(n,m):
    return itertools.permutations(n,m)
def citer(n,m):
    return itertools.combinations(n,m)


def modc(a,b,m):
    c = 1
    for i in xrange(b):
        c = c * (a - i) % m
        c = c * modinv(i + 1,m) % m
    return c
 
def gcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
 
def modinv(a, m):
    (inv, q, gcd_val) = gcd(a, m)
    return inv % m


def index(a, x):
    
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    return -1


def memoize(f):
    cache = {}
    def helper(*args):
        if args not in cache:
            cache[(args)] = f(*args)
        return cache[args]
    return helper

@memoize
def nck(a,b,m):
    b = min([a-b,b])
    if (b>a or b<0 or a<0):
        return 0
    elif a == 0:
        return 1
    return (nck(a-1,b-1,m)+nck(a-1,b,m)) % m

nh=zip([1,0,-1,0],[0,1,0,-1])



h,w=ii()
a=[[""]]*h
red=[[""]]*h
blue=[[""]]*h
nil=[0]*h
for j in range(h):
    sl=slist()
    a[j]=[x for x in sl]
    red[j]=[x for x in sl]
    blue[j]=[x for x in sl]
    nil[j]=not('
    
cnt=0
nilcnt=0
for j in range(h):
    
    if nil[j]:
        nilcnt+=1
    else:
        nilcnt=0

        
    if nilcnt>=2:
        red[j]=red[j-1]
        blue[j]=blue[j-1]
    else:
        cnt+=1
        if cnt%2==0:
            if nil[j]:
                red[j][1:w-1]=["
                blue[j][0]="
                blue[j][w-1]="
            else:
                red[j][0:w]=["
        else:
            if nil[j]:
                blue[j][1:w-1]=["
                red[j][0]="
                red[j][w-1]="
            else:
                blue[j][0:w]=["

                
            

for j in range(h):
    print join(red[j])
print ""


for j in range(h):
    print join(blue[j])

Solution (Python):
h, w = map(int, raw_input().split())
a = [raw_input().strip() for _ in xrange(h)]
t = '.
k = 0
for i in xrange(h):
    c = ['
    print ''.join(c)
    k = 1 - k
print
k = 1
for i in xrange(h):
    c = ['.'] + ['
    print ''.join(c)
    k = 1 - k

Solution (Python):



from copy import deepcopy
def rl(s): return xrange(len(s))

def makeTable(init, *dims):
    if 0 == len(dims): return deepcopy(init)
    return [makeTable(init, *dims[1:]) for i in xrange(dims[0])]

INF = 2147483647


import sys
stdin = sys.stdin

W, H = map(int, stdin.readline().strip().split())
area = [stdin.readline().strip() for _ in range(W)]

rr = makeTable(1, W, H)
for x in range(W):
    rr[x][0] = 2
    if x % 2 == 1:
        for y in range(H-1):
            rr[x][y] = 2

for x in range(W):
    for y in range(H):
        if area[x][y] == '
            rr[x][y] = 3

for x in range(W):
    print ''.join(('

print ""

for x in range(W):
    print ''.join(('