R, C = [int(x) for x in input().split()]
dx, dy = [0, 1, 0, -1], [1, 0, -1, 0]
# 위로/오른쪽으로/아래로/왼쪽으로
ranch = [list(input()) for i in range(R)]
is_ok = True
for r in range(R):
for c in range(C):
if ranch[r][c] == 'W':
for move in range(4):
new_x, new_y = r+dx[move], c+dy[move]
if new_x < 0 or new_x == R or new_y < 0 or new_y == C:
continue
if ranch[new_x][new_y] == 'S':
is_ok = False
if is_ok:
print(1)
for r in range(R):
for c in range(C):
if ranch[r][c] not in 'SW':
ranch[r][c] = 'D'
for i in ranch:
print(''.join(i))
else:
print(0)
R, C = map(int, input().split())
M = [list(input()) for i in range(R)]
dx, dy = [0,1,0,-1],[1,0,-1,0]
ck = False
for i in range(R):
for j in range(C):
if M[i][j] == 'W':
for w in range(4):
ii, jj = i +dx[w], j+dy[w]
if ii < 0 or ii == R or jj < 0 or jj == C:
continue
if M[ii][jj] == 'S':
ck = True
if ck:
print(0)
else:
print(1)
for i in range(R):
for j in range(R):
if M[i][j] not in 'SW':
M[i][j] = 'D'
for i in M:
print(''.join(i))
dx, dy = [0, 1, 0, -1], [1, 0, -1, 0]
# 위로/오른쪽으로/아래로/왼쪽으로