Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.

The pasture is a rectangle consisting of R × C cells. Each cell is either empty, contains a sheep, a wolf or a dog. Sheep and dogs always stay in place, but wolves can roam freely around the pasture, by repeatedly moving to the left, right, up or down to a neighboring cell. When a wolf enters a cell with a sheep, it consumes it. However, no wolf can enter a cell with a dog.

Initially there are no dogs. Place dogs onto the pasture in such a way that no wolf can reach any sheep, or determine that it is impossible. Note that since you have many dogs, you do not need to minimize their number. 


-----Input-----

First line contains two integers R (1 ≤ R ≤ 500) and C (1 ≤ C ≤ 500), denoting the number of rows and the numbers of columns respectively.

Each of the following R lines is a string consisting of exactly C characters, representing one row of the pasture. Here, 'S' means a sheep, 'W' a wolf and '.' an empty cell.


-----Output-----

If it is impossible to protect all sheep, output a single line with the word "No".

Otherwise, output a line with the word "Yes". Then print R lines, representing the pasture after placing dogs. Again, 'S' means a sheep, 'W' a wolf, 'D' is a dog and '.' an empty space. You are not allowed to move, remove or add a sheep or a wolf.

If there are multiple solutions, you may print any of them. You don't have to minimize the number of dogs.


-----Examples-----
Input
6 6
..S...
..S.W.
.S....
..W...
...W..
......

Output
Yes
..SD..
..SDW.
.SD...
.DW...
DD.W..
......

Input
1 2
SW

Output
No

Input
5 5
.S...
...S.
S....
...S.
.S...

Output
Yes
.S...
...S.
S.D..
...S.
.S...



-----Note-----

In the first example, we can split the pasture into two halves, one containing wolves and one containing sheep. Note that the sheep at (2,1) is safe, as wolves cannot move diagonally.

In the second example, there are no empty spots to put dogs that would guard the lone sheep.

In the third example, there are no wolves, so the task is very easy. We put a dog in the center to observe the peacefulness of the meadow, but the solution would be correct even without him.

Source: codeforces | Difficulty: EASY
Tags: Graph algorithms

Graph traversal

Implementation

Complete search


Solutions:
(r, c) = list(map(int, input().split()))
l = [input() for i in range(r)]
for i in range(r):
	for j in range(c - 1):
		if l[i][j] == 'S' and l[i][j + 1] == 'W' or (l[i][j] == 'W' and l[i][j + 1] == 'S'):
			print('No')
			exit()
for j in range(c):
	for i in range(r - 1):
		if l[i][j] == 'S' and l[i + 1][j] == 'W' or (l[i][j] == 'W' and l[i + 1][j] == 'S'):
			print('No')
			exit()
print('Yes')
for i in range(r):
	for j in range(c):
		if l[i][j] == '.':
			print('D', end='')
		else:
			print(l[i][j], end='')
	print('')


import sys, bisect
from sys import stdin, stdout
from bisect import bisect_left, bisect_right, bisect, insort, insort_left, insort_right
from math import gcd, ceil, floor, sqrt
from collections import Counter, defaultdict, deque, OrderedDict
from queue import Queue, PriorityQueue
from string import ascii_lowercase
from heapq import *
from itertools import islice
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 998244353
mod = 10 ** 9 + 7

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	for i in range(5, ceil(sqrt(n)) + 1, 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def st():
	return list(stdin.readline().strip())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def DFS(dictionary, vertex, visited):
	visited[vertex] = True
	stack = [vertex]
	print(vertex)
	while stack:
		a = stack.pop()
		for i in dictionary[a]:
			if not visited[i]:
				print(i)
				visited[i] = True
				stack.append(i)

def BFS(dictionary, vertex, visited):
	visited[vertex] = True
	q = deque()
	q.append(vertex)
	while q:
		a = q.popleft()
		for i in dictionary[a]:
			if not visited[i]:
				visited[i] = True
				q.append(i)
				print(i)

def soe(limit):
	l = [1] * (limit + 1)
	l[0] = 0
	l[1] = 0
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def gcd(a, b):
	while b:
		a = a % b
		(b, a) = (a, b)
	return a

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
		a *= a
		n = n >> 1
	return r

def don(d, ans, vi, i):
	vi[i] = i
	stack = [i]
	ans[i] = 1
	while stack:
		a = stack.pop()
		for x in d[a]:
			if vi[x] == -1:
				ans[i] += 1
				vi[x] = i
				stack.append(x)

def solve():
	l = []
	(n, m) = mp()
	for i in range(n):
		x = st()
		l.append(x)
	for i in range(n):
		for j in range(m):
			if l[i][j] == 'S':
				if i - 1 >= 0:
					if l[i - 1][j] == 'W':
						pr('NO')
						return
				if i + 1 < n:
					if l[i + 1][j] == 'W':
						pr('NO')
						return
				if j - 1 >= 0:
					if l[i][j - 1] == 'W':
						pr('NO')
						return
				if j + 1 < m:
					if l[i][j + 1] == 'W':
						pr('NO')
						return
	print('YES')
	for i in range(n):
		for j in range(m):
			if l[i][j] == '.':
				print('D', end='')
			else:
				print(l[i][j], end='')
		print()
for _ in range(1):
	solve()


(r, c) = map(int, input().split())
Map = []
for _ in range(r):
	x = input().replace('.', 'D')
	Map.append('#' + x + '#')
Map = ['#' * (c + 2)] + Map + ['#' * (c + 2)]
for i in range(r + 2):
	for j in range(c + 2):
		if Map[i][j] == 'W':
			if Map[i - 1][j] == 'S' or Map[i + 1][j] == 'S' or Map[i][j - 1] == 'S' or (Map[i][j + 1] == 'S'):
				print('NO')
				exit()
print('YES')
for i in range(1, r + 1):
	print(Map[i][1:-1])


(y, x) = input().split()
x = int(x)
y = int(y)
peta = []
for i in range(0, y):
	peta.append(list(input()))
found = False
foundW = False
foundS = False
foundM = False
for j in range(0, y):
	for i in range(0, x):
		if peta[j][i] == 'S':
			foundS = True
			if i != x - 1:
				if peta[j][i + 1] == 'W':
					foundM = True
			if i != 0:
				if peta[j][i - 1] == 'W':
					foundM = True
			if j != y - 1:
				if peta[j + 1][i] == 'W':
					foundM = True
			if j != 0:
				if peta[j - 1][i] == 'W':
					foundM = True
		elif peta[j][i] == 'W':
			foundW = True
		elif peta[j][i] == '.':
			peta[j][i] = 'D'
			found = True
if foundM:
	print('No')
elif found:
	print('Yes')
	for j in range(0, y):
		print(''.join(peta[j]), end='\n')
elif foundW:
	if not foundS:
		print('Yes')
		for j in range(0, y):
			for i in range(0, x):
				if i == x - 1:
					print(peta[j][i], end='\n')
				else:
					print(peta[j][i], end='')
	else:
		print('No')
else:
	print('Yes')
	for j in range(0, y):
		for j in range(0, y):
			print(''.join(peta[j]), end='\n')


(r, c) = map(int, input().split())
matrix = [list(input()) for _ in range(r)]
output = True
for i in range(r):
	for j in range(c):
		if matrix[i][j] == 'S':
			if i > 0:
				if matrix[i - 1][j] == '.':
					matrix[i - 1][j] = 'D'
				elif matrix[i - 1][j] == 'W':
					output = False
					break
			if i < r - 1:
				if matrix[i + 1][j] == '.':
					matrix[i + 1][j] = 'D'
				elif matrix[i + 1][j] == 'W':
					output = False
					break
			if j > 0:
				if matrix[i][j - 1] == '.':
					matrix[i][j - 1] = 'D'
				elif matrix[i][j - 1] == 'W':
					output = False
					break
			if j < c - 1:
				if matrix[i][j + 1] == '.':
					matrix[i][j + 1] = 'D'
				if matrix[i][j + 1] == 'W':
					output = False
					break
if output:
	print('Yes')
	for i in range(r):
		out = ''
		for j in range(c):
			out += matrix[i][j]
		print(out)
else:
	print('No')


field = []
(r, c) = tuple(map(int, input().split(' ')))
for _ in range(r):
	field.append(input())
R = len(field)
C = len(field[0])
k_not_ok = [-1, R]
r_not_ok = [-1, C]

def find_wold_is_comming():
	for i in range(R):
		for j in range(C):
			if field[i][j] == 'S':
				for (k, r) in [(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)]:
					if k in k_not_ok or r in r_not_ok:
						continue
					if field[k][r] == 'W':
						return print('No')
	print('Yes')
	for v in field:
		print(v.replace('.', 'D'))
find_wold_is_comming()


(r, c) = map(int, input().split())
mat = []
for i in range(r):
	mat.append(list(input()))
for i in range(r):
	for j in range(c):
		if mat[i][j] == 'S':
			if i > 0:
				if mat[i - 1][j] == 'W':
					print('No')
					exit()
				elif mat[i - 1][j] == '.':
					mat[i - 1][j] = 'D'
			if i < r - 1:
				if mat[i + 1][j] == 'W':
					print('No')
					exit()
				elif mat[i + 1][j] == '.':
					mat[i + 1][j] = 'D'
			if j > 0:
				if mat[i][j - 1] == 'W':
					print('No')
					exit()
				elif mat[i][j - 1] == '.':
					mat[i][j - 1] = 'D'
			if j < c - 1:
				if mat[i][j + 1] == 'W':
					print('No')
					exit()
				elif mat[i][j + 1] == '.':
					mat[i][j + 1] = 'D'
print('Yes')
for x in mat:
	print(''.join(x))


(R, C) = map(int, input().split())
l = []
t = ''
ans = ''
for i in range(R):
	r = input()
	l.append(r)
	t += r
for i in range(R):
	for j in range(C):
		if j != C - 1:
			if l[i][j] == 'S' and l[i][j + 1] == 'W':
				print('NO')
				exit()
			if l[i][j] == 'W' and l[i][j + 1] == 'S':
				print('NO')
				exit()
		if i == len(l) - 1:
			if l[i][j] == 'S' and l[i - 1][j] == 'W' or (l[i][j] == 'S' and l[i - 1][j] == 'W'):
				print('NO')
				exit()
		elif i == 0:
			if l[i][j] == 'S' and l[i + 1][j] == 'W' or (l[i][j] == 'S' and l[i + 1][j] == 'W'):
				print('NO')
				exit()
		elif i == len(l) - 1:
			if l[i][j] == 'S' and l[i - 1][j] == 'W' or (l[i][j] == 'S' and l[i - 1][j] == 'W'):
				print('NO')
				exit()
		else:
			if l[i][j] == 'S' and l[i - 1][j] == 'W' or (l[i][j] == 'S' and l[i - 1][j] == 'W'):
				print('NO')
				exit()
			if l[i][j] == 'S' and l[i + 1][j] == 'W' or (l[i][j] == 'S' and l[i + 1][j] == 'W'):
				print('NO')
				exit()
print('YES')
for i in range(len(t)):
	if t[i] == '.':
		ans += 'D'
	else:
		ans += t[i]
for i in range(len(ans)):
	if i > 0:
		if i % C == 0:
			print()
	print(ans[i], end='')


from math import ceil, sqrt, log

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def main():
	(r, c) = mi()
	a = []
	for i in range(r):
		a.append(list(si()))
	f = 0
	for i in range(r):
		for j in range(c):
			if a[i][j] == 'S':
				if i > 0:
					if a[i - 1][j] == '.':
						a[i - 1][j] = 'D'
					if a[i - 1][j] == 'W':
						f = 1
				if j > 0:
					if a[i][j - 1] == '.':
						a[i][j - 1] = 'D'
					if a[i][j - 1] == 'W':
						f = 1
				if i < r - 1:
					if a[i + 1][j] == '.':
						a[i + 1][j] = 'D'
					if a[i + 1][j] == 'W':
						f = 1
				if j < c - 1:
					if a[i][j + 1] == '.':
						a[i][j + 1] = 'D'
					if a[i][j + 1] == 'W':
						f = 1
	if f:
		print('NO')
	else:
		print('YES')
		for i in range(r):
			for j in range(c):
				print(a[i][j], end='')
			print()
main()


from sys import stdin, stdout, setrecursionlimit
import threading

class Tail_Recursion_Optimization:

	def __init__(self, recursion_limit, stack_size):
		setrecursionlimit(recursion_limit)
		threading.stack_size(stack_size)
		return None

class SOLVE:
	dirx = [1, 0, -1, 0]
	diry = [0, 1, 0, -1]
	r = c = None

	def dfs(self, u, node, vis):
		(x, y) = u
		vis[x][y] = True
		for i in range(4):
			tmpx = x + self.dirx[i]
			tmpy = y + self.diry[i]
			if 0 <= tmpx < self.r and 0 <= tmpy < self.c and (not vis[tmpx][tmpy]):
				if node[tmpx][tmpy] == 'S':
					return 1
				elif node[tmpx][tmpy] != 'D':
					self.dfs((tmpx, tmpy), node, vis)
		return 0

	def solve(self):
		R = stdin.readline
		W = stdout.write
		ans = ['Yes', '\n']
		(self.r, self.c) = [int(x) for x in R().split()]
		node = []
		for i in range(self.r):
			node.append(R())
			node[i] = node[i].replace('.', 'D')
			ans += node[i]
		wolf = []
		for i in range(self.r):
			for j in range(self.c):
				if node[i][j] == 'W':
					wolf.append((i, j))
		vis = [[False for j in range(self.c)] for i in range(self.r)]
		for i in range(len(wolf)):
			if self.dfs(wolf[i], node, vis):
				W('No\n')
				return 0
		W(''.join(ans))
		return 0

def main():
	s = SOLVE()
	s.solve()
Tail_Recursion_Optimization(10 ** 7, 2 ** 24)
threading.Thread(target=main).start()


(r, c) = list(map(int, input().strip().split(' ')))
matr = []
matr.append(list('.' * (c + 2)))
for _ in range(r):
	matr.append(['.'] + list(input()) + ['.'])
matr.append(matr[0].copy())
for row in range(1, r + 1):
	for col in range(1, c + 1):
		if matr[row][col] == 'S':
			if matr[row - 1][col] == 'W' or matr[row + 1][col] == 'W' or matr[row][col - 1] == 'W' or (matr[row][col + 1] == 'W'):
				print('No')
				exit(0)
		elif matr[row][col] == '.':
			matr[row][col] = 'D'
print('Yes')
for row in range(1, r + 1):
	print(''.join(matr[row][1:c + 1]))


import re
(r, c) = input().split()
s = '\n'.join((input().replace('.', 'D') for _ in [0] * int(r)))
print('No' if re.search('(?s)(S|W)(.{' + c + '})?(?!\\1)(S|W)', s) else 'Yes\n' + s)


def main():
	(r, c) = map(int, input().split(' '))
	s = []
	w = []
	r_dir = [1, -1, 0, 0]
	c_dir = [0, 0, 1, -1]
	for i in range(r):
		inpt = input()
		for j in range(c):
			if inpt[j] == 'S':
				s.append([i, j])
			elif inpt[j] == 'W':
				w.append([i, j])
	for pos in s:
		for i in range(4):
			newpos = [pos[0] + c_dir[i], pos[1] + r_dir[i]]
			if newpos in w:
				print('No')
				return
	mat = [['D' for i in range(c)] for i in range(r)]
	for p in s:
		mat[p[0]][p[1]] = 'S'
	for p in w:
		mat[p[0]][p[1]] = 'W'
	print('Yes')
	for i in mat:
		print(''.join(i))
main()


(n, m) = list(map(int, input().split()))
valor = True
a = []
for i in range(n):
	entrada = input()
	if 'SW' in entrada or 'WS' in entrada:
		valor = False
		break
	if len(a) > 0:
		for i in range(len(entrada)):
			if entrada[i] == 'W' and a[-1][i] == 'S':
				valor = False
			if entrada[i] == 'S' and a[-1][i] == 'W':
				valor = False
	a.append(entrada.replace('.', 'D'))
if valor:
	print('Yes')
	for i in a:
		print(i)
else:
	print('NO')


(n, m) = map(int, input().split())
arr = [input().replace('.', 'D') for _ in [0] * n]
flag1 = any(('SW' in x or 'WS' in x for x in arr))
arrRotated = zip(*arr)
flag2 = any(('SW' in x or 'WS' in x for x in (''.join(t) for t in arrRotated)))
if flag1 or flag2:
	print('No')
else:
	print('Yes')
	print('\n'.join(arr))


(n, m) = map(int, input().split())
a = [input().replace('.', 'D') for _ in range(n)]
flag = True
for i in range(n):
	for j in range(m):
		if i > 0 and {a[i][j], a[i - 1][j]} == {'S', 'W'}:
			flag = False
		if j > 0 and {a[i][j], a[i][j - 1]} == {'S', 'W'}:
			flag = False
if flag:
	print('Yes')
	print('\n'.join(a))
else:
	print('No')


entrada = input().split()
r = int(entrada[0])
c = int(entrada[1])
matriz = []
i = 0
while i < r:
	matriz.append(list(input()))
	i += 1
i = 0
isProtegivel = True
while i < r:
	j = 0
	while j < c:
		if matriz[i][j] == '.':
			matriz[i][j] = 'D'
		if matriz[i][j] == 'S':
			if j + 1 < c:
				if matriz[i][j + 1] == 'W':
					isProtegivel = False
					break
			if i + 1 < r:
				if matriz[i + 1][j] == 'W':
					isProtegivel = False
					break
		if matriz[i][j] == 'W':
			if j + 1 < c:
				if matriz[i][j + 1] == 'S':
					isProtegivel = False
					break
			if i + 1 < r:
				if matriz[i + 1][j] == 'S':
					isProtegivel = False
					break
		j += 1
	i += 1
if isProtegivel:
	print('Yes')
	for linha in matriz:
		print(''.join(linha))
else:
	print('No')


(R, C) = map(int, input().split())
rc = []
for i in range(R):
	rc.append(list(input()))
	for j in range(C):
		if rc[i][j] == '.':
			rc[i][j] = 'D'
for i in range(R):
	for j in range(C):
		if rc[i][j] == 'S':
			if j < C - 1:
				if rc[i][j + 1] == 'W':
					print('No')
					exit(0)
			if j > 0:
				if rc[i][j - 1] == 'W':
					print('No')
					exit(0)
			if i > 0:
				if rc[i - 1][j] == 'W':
					print('No')
					exit(0)
			if i < R - 1:
				if rc[i + 1][j] == 'W':
					print('No')
					exit(0)
print('Yes')
for i in range(R):
	print(*rc[i], sep='')


(r, c) = map(int, input().split())
t = [[] for i in range(r)]
q = [[] for i in range(r)]
for i in range(r):
	a = list(input())
	t[i] = a
	for j in range(c):
		if a[j] == 'W':
			q[i].append(j)
flag = True
for i in range(r):
	for j in range(len(q[i])):
		(x, y) = (i, q[i][j])
		for (dx, dy) in [(0, 1), (1, 0), (0, -1), (-1, 0)]:
			(nx, ny) = (x + dx, y + dy)
			if not 0 <= nx < r or not 0 <= ny < c:
				continue
			elif t[nx][ny] == 'S':
				flag = False
				break
			elif t[nx][ny] == '.':
				t[nx][ny] = 'D'
if flag:
	print('Yes')
	for i in range(r):
		print(''.join(t[i]))
else:
	print('No')


(r, c) = map(int, input().split())
a = [input().replace('.', 'D') for _ in [0] * r]
print('No' if any((any(('SW' in s or 'WS' in s for s in x)) for x in (a, (''.join(t) for t in zip(*a))))) else 'Yes\n' + '\n'.join(a))


(r, c) = map(int, input().split())
matrix = [[0 for i in range(c + 2)]]
for i in range(r):
	app = [0] + list(input()) + [0]
	matrix.append(app)
matrix.append([0 for i in range(c + 2)])
for i in range(1, r + 1):
	for j in range(1, c + 1):
		if matrix[i][j] == 'S':
			if matrix[i + 1][j] == 'W' or matrix[i - 1][j] == 'W' or matrix[i][j - 1] == 'W' or (matrix[i][j + 1] == 'W'):
				print('NO')
				quit()
for i in range(1, r + 1):
	for j in range(1, c + 1):
		if matrix[i][j] == '.':
			matrix[i][j] = 'D'
print('YES')
for i in range(1, r + 1):
	del matrix[i][0]
	del matrix[i][-1]
	print(''.join(matrix[i]))


(r, c) = map(int, input().split())
p = ['Yes'] + [input().replace('.', 'D') for _ in [0] * r]
if any((any(('SW' in s or 'WS' in s for s in x)) for x in (p[1:], (''.join(t) for t in zip(*p[1:]))))):
	p = ['No']
print(*p, sep='\n')


from collections import defaultdict
import math
(r, c) = map(int, input().split())
farm = []
for i in range(r):
	farm.append(input())
ans = True
for i in farm:
	if 'SW' in i:
		ans = False
		break
	elif 'WS' in i:
		ans = False
		break
if ans:
	for i in range(r - 1):
		for j in range(c):
			if farm[i][j] == 'S' and farm[i + 1][j] == 'W':
				ans = False
				break
			elif farm[i][j] == 'W' and farm[i + 1][j] == 'S':
				ans = False
				break
		if ans == False:
			break
if ans:
	print('Yes')
	for i in farm:
		for j in i:
			if j == '.':
				print('D', end='')
			else:
				print(j, end='')
		print()
else:
	print('No')


def check(pas, row, col, rl, cl):
	if row > 0:
		if pas[row - 1][col] == 'W':
			print('NO')
			exit()
		elif pas[row - 1][col] == '.':
			pas[row - 1][col] = 'D'
	if row != rl:
		if pas[row + 1][col] == 'W':
			print('NO')
			exit()
		elif pas[row + 1][col] == '.':
			pas[row + 1][col] = 'D'
	if col > 0:
		if pas[row][col - 1] == 'W':
			print('NO')
			exit()
		elif pas[row][col - 1] == '.':
			pas[row][col - 1] = 'D'
	if col != cl:
		if pas[row][col + 1] == 'W':
			print('NO')
			exit()
		elif pas[row][col + 1] == '.':
			pas[row][col + 1] = 'D'
	return pas
(r, c) = input().split()
r = int(r)
c = int(c)
pas = []
for i in range(r):
	x = input()
	pas.append(list(x))
for row in range(r):
	for col in range(c):
		if pas[row][col] == 'S':
			pas = check(pas, row, col, r - 1, c - 1)
print('YES')
for x in pas:
	y = ''.join(x)
	print(y)


def check(r, c):
	if row[r][c + 1] == 'W' or row[r][c - 1] == 'W' or row[r + 1][c] == 'W' or (row[r - 1][c] == 'W'):
		return 1
	else:
		return 0
(r, c) = map(int, input().split())
row = [' ' * 1000]
for i in range(1, r + 1):
	row.append(input())
	row[i] = ' ' + row[i] + ' '
row.append(' ' * 1000)
flag = 0
for i in range(1, r + 1):
	for j in range(1, c + 1):
		if row[i][j] == 'S':
			if check(i, j):
				flag = 1
				break
		if flag:
			break
if flag:
	print('No')
else:
	print('Yes')
	for i in range(1, r + 1):
		print(row[i].replace('.', 'D')[1:c + 1])


import math

def check():
	for i in range(R):
		for j in range(C):
			try:
				if j != C - 1 and pasture[i][j] == 'S' and (pasture[i][j + 1] == 'W'):
					print('NO')
					return
				elif j != 0 and pasture[i][j] == 'S' and (pasture[i][j - 1] == 'W'):
					print('NO')
					return
				elif i != R - 1 and pasture[i][j] == 'S' and (pasture[i + 1][j] == 'W'):
					print('NO')
					return
				elif i != 0 and pasture[i][j] == 'S' and (pasture[i - 1][j] == 'W'):
					print('NO')
					return
			except IndexError:
				continue
			if pasture[i][j] == '.':
				pasture[i][j] = 'D'
	print('YES')
	for k in range(R):
		print(''.join(pasture[k]))
(R, C) = map(int, input().split(' '))
pasture = []
for _ in range(R):
	pasture.append(list(input()))
check()


(R, C) = map(int, input().split())
ss = []
for i in range(R):
	l = input()
	ss.append(l.replace('.', 'D'))
for i in range(R):
	for j in range(C):
		if ss[i][j] == 'S':
			if i > 0:
				if ss[i - 1][j] == 'W':
					ss = 'No'
					break
			if j > 0:
				if ss[i][j - 1] == 'W':
					ss = 'No'
					break
			if i < R - 1:
				if ss[i + 1][j] == 'W':
					ss = 'No'
					break
			if j < C - 1:
				if ss[i][j + 1] == 'W':
					ss = 'No'
					break
	if 'No' == ss:
		break
if 'No' != ss:
	print('Yes')
	for i in ss:
		print(i)
else:
	print(ss)


deslocamento = ((0, -1), (0, 1), (1, 0), (-1, 0))

def possivel(novoi, novoj, r, c):
	return 0 <= novoi < r and 0 <= novoj < c

def solve(mapa, r, c):
	for i in range(r):
		for j in range(c):
			if mapa[i][j] == 'W':
				for (di, dj) in deslocamento:
					novoi = i + di
					novoj = j + dj
					if possivel(novoi, novoj, r, c):
						if mapa[novoi][novoj] == 'S':
							return False
						elif mapa[novoi][novoj] == '.':
							mapa[novoi][novoj] = 'D'
	return True

def main():
	(r, c) = [int(x) for x in input().split()]
	mapa = [[s for s in input()] for _ in range(r)]
	possivel = solve(mapa, r, c)
	if possivel:
		print('Yes')
		for linha in mapa:
			print(*linha, sep='')
	else:
		print('No')
main()


class CodeforcesTask948ASolution:

	def __init__(self):
		self.result = ''
		self.pasture_dims = []
		self.pasture = []

	def read_input(self):
		self.pasture_dims = [int(x) for x in input().split(' ')]
		for x in range(self.pasture_dims[0]):
			self.pasture.append(list(input()))

	def process_task(self):
		can = True
		for r in range(self.pasture_dims[0]):
			for c in range(self.pasture_dims[1]):
				if self.pasture[r][c] == 'S':
					if r > 0:
						if self.pasture[r - 1][c] == 'W':
							can = False
						elif self.pasture[r - 1][c] == '.':
							self.pasture[r - 1][c] = 'D'
					if r < self.pasture_dims[0] - 1:
						if self.pasture[r + 1][c] == 'W':
							can = False
						elif self.pasture[r + 1][c] == '.':
							self.pasture[r + 1][c] = 'D'
					if c > 0:
						if self.pasture[r][c - 1] == 'W':
							can = False
						elif self.pasture[r][c - 1] == '.':
							self.pasture[r][c - 1] = 'D'
					if c < self.pasture_dims[1] - 1:
						if self.pasture[r][c + 1] == 'W':
							can = False
						elif self.pasture[r][c + 1] == '.':
							self.pasture[r][c + 1] = 'D'
		if not can:
			print('No')
		else:
			print('Yes')
			for row in self.pasture:
				print(''.join(row))

	def get_result(self):
		return self.result
Solution = CodeforcesTask948ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


def check(x, y):
	return 0 <= x and x < n and (0 <= y) and (y < m)

def change(c):
	if c == '.':
		c = 'D'
	return c
(n, m) = map(int, input().split())
g = []
for i in range(n):
	g.append(list(input()))
fx = [[0, 1], [1, 0]]
flag = True
for x in range(n):
	for y in range(m):
		for i in range(2):
			xx = x + fx[i][0]
			yy = y + fx[i][1]
			if check(xx, yy):
				if g[x][y] == 'S' and g[xx][yy] == 'W' or (g[x][y] == 'W' and g[xx][yy] == 'S'):
					flag = False
			if not flag:
				break
		if not flag:
			break
	if not flag:
		break
if flag:
	print('Yes')
	for i in range(n):
		print(''.join(map(change, g[i])))
else:
	print('No')


(r, c) = map(int, input().split())
l = []
isPossible = True
for i in range(r):
	s = input()
	m = list(map(str, s))
	l.append(m)
for i in range(r):
	for j in range(c):
		if i + 1 != r and l[i + 1][j] != 'W':
			if l[i + 1][j] == '.':
				l[i + 1][j] = 'D'
		elif i + 1 != r and l[i][j] == 'S' and (l[i + 1][j] == 'W'):
			isPossible = False
			break
		if i - 1 >= 0 and l[i - 1][j] != 'W':
			if l[i - 1][j] == '.':
				l[i - 1][j] = 'D'
		elif i - 1 >= 0 and l[i][j] == 'S' and (l[i - 1][j] == 'W'):
			isPossible = False
			break
		if j + 1 != c and l[i][j + 1] != 'W':
			if l[i][j + 1] == '.':
				l[i][j + 1] = 'D'
		elif j + 1 != c and l[i][j] == 'S' and (l[i][j + 1] == 'W'):
			isPossible = False
			break
		if j - 1 >= 0 and l[i][j - 1] != 'W':
			if l[i][j - 1] == '.':
				l[i][j - 1] = 'D'
		elif j - 1 >= 0 and l[i][j] == 'S' and (l[i][j - 1] == 'W'):
			isPossible = False
			break
	if isPossible == False:
		break
if isPossible == False:
	print('No')
else:
	print('Yes')
	for i in l:
		print(''.join(i))


(r, c) = map(int, input().split())
ans = True
M = []
for _ in range(r):
	s = input()
	if 'SW' in s or 'WS' in s:
		ans = False
	if len(M) > 0:
		for i in range(len(s)):
			if s[i] == 'W' and M[-1][i] == 'S':
				ans = False
			if s[i] == 'S' and M[-1][i] == 'W':
				ans = False
	M.append(s.replace('.', 'D'))
print('Yes' if ans else 'No')
if ans:
	for m in M:
		print(m)


(r, c) = map(int, input().split())
ans = ''
pasture = []
flag = 0
for _ in range(r):
	row = list(str(input()))
	pasture.append(row)
for i in range(r):
	for j in range(c):
		if pasture[i][j] == 'S':
			if i > 0:
				if pasture[i - 1][j] == 'W':
					flag = 1
					break
				elif pasture[i - 1][j] == '.':
					pasture[i - 1][j] = 'D'
			if i < r - 1:
				if pasture[i + 1][j] == 'W':
					flag = 1
					break
				elif pasture[i + 1][j] == '.':
					pasture[i + 1][j] = 'D'
			if j > 0:
				if pasture[i][j - 1] == 'W':
					flag = 1
					break
				elif pasture[i][j - 1] == '.':
					pasture[i][j - 1] = 'D'
			if j < c - 1:
				if pasture[i][j + 1] == 'W':
					flag = 1
					break
				elif pasture[i][j + 1] == '.':
					pasture[i][j + 1] = 'D'
if flag == 0:
	print('YES')
	for i in range(r):
		print(''.join(pasture[i]))
else:
	print('NO')


(r, c) = map(int, input().split())
a = ['D' * (2 + c)]
for i in range(r):
	a.append('D' + input().replace('.', 'D') + 'D')
a.append('D' * (2 + c))
for i in range(1, r + 1):
	if 'SW' in a[i] or 'WS' in a[i]:
		exit(print('NO'))
	for t in range(1, c + 1):
		if a[i][t] == 'W':
			if a[i - 1][t] == 'S':
				exit(print('NO'))
			if a[i + 1][t] == 'S':
				exit(print('NO'))
print('YES')
for i in range(1, r + 1):
	print(a[i][1:c + 1])


(n, m) = map(int, input().split())
s = [input() for _ in range(n)]
s += [''.join(p) for p in zip(*s)]
possible = all(('WS' not in p and 'SW' not in p for p in s))
print(('No', 'Yes')[possible])
if possible:
	s = [['#'] * (m + 2)] + [['#'] + list(p) + ['#'] for p in s[:n]] + [['#'] * (m + 2)]
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if s[i][j] == '.' and 'W' in {s[i][j - 1], s[i][j + 1], s[i - 1][j], s[i + 1][j]}:
				s[i][j] = 'D'
	print('\n'.join([''.join(s[i][1:m + 1]) for i in range(1, n + 1)]))


def main():
	(r, c) = list(map(int, input().split()))
	field = [[x for x in input()] for _ in range(r)]
	good = True
	for i in range(r):
		for j in range(c):
			if field[i][j] == 'S':
				if i > 0 and field[i - 1][j] == 'W':
					good = False
					break
				if i < r - 1 and field[i + 1][j] == 'W':
					good = False
					break
				if j > 0 and field[i][j - 1] == 'W':
					good = False
				if j < c - 1 and field[i][j + 1] == 'W':
					good = False
					break
	if not good:
		print('NO')
		return
	for i in range(r):
		for j in range(c):
			if field[i][j] == '.':
				field[i][j] = 'D'
	print('YES')
	for i in range(r):
		print(''.join(field[i]))
main()


def main():
	(R, C) = map(int, input().split())
	RC = tuple((input() for _ in [0] * R))
	cells = ['#' * (C + 2) for _ in [0] * (R + 2)]
	for (i, j) in enumerate(RC):
		cells[i + 1] = '#' + j + '#'
	for i in range(1, R + 1):
		for j in range(1, C + 1):
			if cells[i][j] == 'S':
				if any((cells[i][j - 1] == 'W', cells[i][j + 1] == 'W', cells[i - 1][j] == 'W', cells[i + 1][j] == 'W')):
					print('No')
					return
	print('Yes')
	for s in RC:
		print(s.replace('.', 'D'))
main()


(r, c) = map(int, input().split())
field = [input() for i in range(r)]
ans = 1
for i in range(1, r):
	for j in range(1, c):
		if field[i][j] == 'S':
			if field[i - 1][j] == 'W' or field[i][j - 1] == 'W':
				ans = 0
				break
		if field[i][j] == 'W':
			if field[i - 1][j] == 'S' or field[i][j - 1] == 'S':
				ans = 0
				break
if r > 1:
	for j in range(c):
		if field[0][j] == 'S':
			if field[1][j] == 'W':
				ans = 0
				break
		if field[0][j] == 'W':
			if field[1][j] == 'S':
				ans = 0
				break
if c > 1:
	for i in range(r):
		if field[i][0] == 'S':
			if field[i][1] == 'W':
				ans = 0
				break
		if field[i][0] == 'W':
			if field[i][1] == 'S':
				ans = 0
				break
for j in range(1, c):
	if field[0][j] == 'S':
		if field[0][j - 1] == 'W':
			ans = 0
			break
	if field[0][j] == 'W':
		if field[0][j - 1] == 'S':
			ans = 0
			break
for i in range(1, r):
	if field[i][0] == 'S':
		if field[i - 1][0] == 'W':
			ans = 0
			break
	if field[i][0] == 'W':
		if field[i - 1][0] == 'S':
			ans = 0
			break
if ans == 1:
	print('Yes')
	for i in range(r):
		for j in range(c):
			if field[i][j] == '.':
				print('D', end='')
			else:
				print(field[i][j], end='')
		print()
else:
	print('No')


(r, c) = map(int, input().split())
cells = [list(input()) for _ in range(r)]
ans = 'Yes'
for i in range(r):
	for j in range(c):
		if cells[i][j] == '.':
			cells[i][j] = 'D'
for i in range(r - 1):
	for j in range(c):
		if cells[i][j] == 'S' and cells[i + 1][j] == 'W':
			ans = 'No'
		if cells[i][j] == 'W' and cells[i + 1][j] == 'S':
			ans = 'No'
for i in range(r):
	for j in range(c - 1):
		if cells[i][j] == 'S' and cells[i][j + 1] == 'W':
			ans = 'No'
		if cells[i][j] == 'W' and cells[i][j + 1] == 'S':
			ans = 'No'
print(ans)
if ans == 'Yes':
	for i in range(r):
		print(''.join(cells[i]))


(r, c) = map(int, input().strip().split())
m = [list(input()) for i in range(r)]
possible = True
for i in range(r):
	for j in range(c):
		if m[i][j] == 'W':
			if i - 1 >= 0:
				if m[i - 1][j] == 'S':
					possible = False
				elif m[i - 1][j] == '.':
					m[i - 1][j] = 'D'
			if j - 1 >= 0:
				if m[i][j - 1] == 'S':
					possible = False
				elif m[i][j - 1] == '.':
					m[i][j - 1] = 'D'
			if i + 1 < r:
				if m[i + 1][j] == 'S':
					possible = False
				elif m[i + 1][j] == '.':
					m[i + 1][j] = 'D'
			if j + 1 < c:
				if m[i][j + 1] == 'S':
					possible = False
				elif m[i][j + 1] == '.':
					m[i][j + 1] = 'D'
	if not possible:
		break
if possible:
	print('Yes')
	for i in range(r):
		for j in range(c):
			print(m[i][j], end='')
		print()
else:
	print('No')


(r, c) = map(int, input().split())
li = [list(input()) for i in range(r)]
(row, column) = (0, 0)
for i in range(r):
	for j in range(c):
		if li[i][j] == 'S':
			if i > 0 and li[i - 1][j] == 'W':
				print('No')
				exit(0)
			elif i > 0 and li[i - 1][j] != 'S':
				li[i - 1][j] = 'D'
			if i < r - 1 and li[i + 1][j] == 'W':
				print('No')
				exit(0)
			elif i < r - 1 and li[i + 1][j] != 'S':
				li[i + 1][j] = 'D'
			if j > 0 and li[i][j - 1] == 'W':
				print('No')
				exit(0)
			elif j > 0 and li[i][j - 1] != 'S':
				li[i][j - 1] = 'D'
			if j < c - 1 and li[i][j + 1] == 'W':
				print('No')
				exit(0)
			elif j < c - 1 and li[i][j + 1] != 'S':
				li[i][j + 1] = 'D'
print('Yes')
for i in li:
	print(''.join(i))


def deumerda(linha):
	if 'SW' in linha or 'WS' in linha:
		return True
	return False

def verificar(pasto, r, c):
	for x in range(c):
		aux = ''
		for y in range(r):
			aux += pasto[y][x]
		if deumerda(aux):
			print('No')
			exit()
(r, c) = map(int, input().split(' '))
pasto = []
indices = []
for i in range(r):
	linha = input()
	if deumerda(linha):
		print('No')
		exit()
	linha = list(linha)
	for j in range(c):
		if linha[j] == '.':
			linha[j] = 'D'
	pasto.append(linha)
verificar(pasto, r, c)
print('Yes')
for x in pasto:
	k = ''.join(x)
	print(k)


(n, m) = list(map(int, input().split(' ')))
a = []
for i in range(n):
	s = input()
	if 'SW' in s or 'WS' in s:
		print('NO')
		exit()
	a.append(s)
for i in range(0, n):
	for j in range(m):
		if i > 0:
			if a[i][j] == 'S':
				if a[i - 1][j] == 'W':
					print('NO')
					exit()
		if i + 1 < n:
			if a[i][j] == 'S':
				if a[i + 1][j] == 'W':
					print('NO')
					exit()
print('YES')
for i in range(n):
	print(a[i].replace('.', 'D'))


(r, c) = map(int, input().split())
a = []
tr = True
сount = 0
for i in range(r):
	s = input().replace('.', 'D')
	if 'SW' in s or 'WS' in s:
		tr = False
	a.append(s)
if not tr or сount == r:
	print('No')
else:
	for i in range(r):
		for j in range(c):
			if i > 0:
				if set(a[i][j] + a[i - 1][j]) == {'W', 'S'}:
					tr = False
			if i < r - 1:
				if set(a[i][j] + a[i + 1][j]) == {'W', 'S'}:
					tr = False
	if tr:
		print('Yes')
		for i in a:
			print(i)
	else:
		print('No')


from functools import reduce
import os
import sys
from collections import *
from decimal import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [str(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(n)]

def Ceil(a, b):
	return a // b + int(a % b > 0)
alphabet = 'abcdefghijklmnopqrstuvwxyz'
mo = 1000000007
inf = 1e+18
div = 998244353
(n, m) = value()
a = [[str(x) for x in input()] for j in range(n)]
flag = 0
for i in range(n):
	for j in range(m):
		if a[i][j] == 'S':
			if i - 1 >= 0:
				if a[i - 1][j] == 'W':
					flag = 1
				elif a[i - 1][j] == '.':
					a[i - 1][j] = 'D'
			if i + 1 < n:
				if a[i + 1][j] == 'W':
					flag = 1
				elif a[i + 1][j] == '.':
					a[i + 1][j] = 'D'
			if j - 1 >= 0:
				if a[i][j - 1] == 'W':
					flag = 1
				elif a[i][j - 1] == '.':
					a[i][j - 1] = 'D'
			if j + 1 < m:
				if a[i][j + 1] == 'W':
					flag = 1
				elif a[i][j + 1] == '.':
					a[i][j + 1] = 'D'
		if flag == 1:
			break
	if flag == 1:
		break
if flag == 1:
	print('No')
else:
	print('Yes')
	for i in range(n):
		print(*a[i], sep='')


import sys
(x, y) = map(int, input().split())
p = [[0, 1], [1, 0], [-1, 0], [0, -1]]
a = []
for i in range(0, x):
	a.append(input())
for i in range(0, x):
	for j in range(0, y):
		for k in range(0, 4):
			if a[i][j] == 'S' and i + p[k][0] >= 0 and (j + p[k][1] >= 0) and (i + p[k][0] < x) and (j + p[k][1] < y) and (a[i + p[k][0]][j + p[k][1]] == 'W'):
				print('No')
				sys.exit()
print('Yes')
for i in range(0, x):
	a[i] = a[i].replace('.', 'D')
for i in range(0, x):
	print(a[i])


(R, C) = list(map(int, input().split()))
prev = input().replace('.', 'D')
res = [prev]
for cnt in range(C - 1):
	if prev[cnt] == 'W' and prev[cnt + 1] == 'S' or (prev[cnt] == 'S' and prev[cnt + 1] == 'W'):
		print('No')
		exit(0)
for row in range(R - 1):
	cur = input().replace('.', 'D')
	res.append(cur)
	if C == 1:
		if prev[0] == 'W' and cur[0] == 'S' or (prev[0] == 'S' and cur[0] == 'W'):
			print('No')
			exit(0)
	for cnt in range(C - 1):
		if cur[cnt] == 'W' and cur[cnt + 1] == 'S' or (cur[cnt] == 'S' and cur[cnt + 1] == 'W'):
			print('No')
			exit(0)
	for cnt in range(C):
		if prev[cnt] == 'W' and cur[cnt] == 'S' or (prev[cnt] == 'S' and cur[cnt] == 'W'):
			print('No')
			exit(0)
	prev = cur
print('Yes')
for c in res:
	print(c)


(R, C) = map(int, input().split())
pasture = [list(input()) for i in range(R)]
for i in range(R):
	for j in range(C - 1):
		if pasture[i][j] == 'S' and pasture[i][j + 1] == 'W' or (pasture[i][j] == 'W' and pasture[i][j + 1] == 'S'):
			print('No')
			exit()
for i in range(R - 1):
	for j in range(C):
		if pasture[i][j] == 'S' and pasture[i + 1][j] == 'W' or (pasture[i][j] == 'W' and pasture[i + 1][j] == 'S'):
			print('No')
			exit()
for i in range(R):
	for j in range(C):
		if pasture[i][j] == '.':
			pasture[i][j] = 'D'
print('Yes')
for i in range(R):
	print(''.join(pasture[i]))


from sys import stdin, stdout

def rint():
	return map(int, stdin.readline().split())

def protect(r, c):
	if rc[r][c] != 'W':
		return True
	for (rr, cc) in [[r - 1, c], [r + 1, c], [r, c - 1], [r, c + 1]]:
		if rr < 0 or rr >= R or cc < 0 or (cc >= C):
			continue
		item = rc[rr][cc]
		if item == 'S':
			return False
		if item == 'D' or item == 'W':
			continue
		if item == '.':
			rc[rr][cc] = 'D'
			continue
	return True
(R, C) = rint()
rc = []
for i in range(R):
	r = list(input())
	rc.append(r)
for r in range(R):
	for c in range(C):
		if protect(r, c) == False:
			print('No')
			exit()
print('Yes')
for r in range(R):
	print(''.join(rc[r]))


(r, c) = map(int, input().split())
l = []
for i in range(r):
	l.append(list(input()))

def getValidNeigh(i, j, r, c):
	offset = [(1, 0), (0, 1), (-1, 0), (0, -1)]
	d = []
	for k in offset:
		x = i + k[0]
		y = j + k[1]
		if x >= 0 and x < r and (y >= 0) and (y < c):
			d.append((x, y))
	return d

def printField(l, r, c):
	for i in range(r):
		for j in range(c):
			print(l[i][j], end='')
		print()
yes = True
for i in range(r):
	for j in range(c):
		if l[i][j] == 'S':
			for k in getValidNeigh(i, j, r, c):
				if l[k[0]][k[1]] == 'W':
					yes = False
					break
				elif l[k[0]][k[1]] == '.':
					l[k[0]][k[1]] = 'D'
			if not yes:
				break
	if not yes:
		break
if not yes:
	print('NO')
else:
	print('YES')
	printField(l, r, c)


def sol():
	(r, c) = map(int, input().split())
	A = [[]] * r
	for i in range(r):
		A[i] = [p for p in input()]
	ans = 'YES'
	for i in range(r):
		for j in range(c):
			if j < c - 1 and A[i][j] == 'S' and (A[i][j + 1] == 'W'):
				print('NO')
				return
			if j > 0 and A[i][j] == 'S' and (A[i][j - 1] == 'W'):
				print('NO')
				return
	for i in range(c):
		for j in range(r):
			if j < r - 1 and A[j][i] == 'S' and (A[j + 1][i] == 'W'):
				print('NO')
				return
			if j > 0 and A[j][i] == 'S' and (A[j - 1][i] == 'W'):
				print('NO')
				return
	print('YES')
	for i in range(r):
		for j in range(c):
			if A[i][j] == '.':
				print('D', end='')
			else:
				print(A[i][j], end='')
		print('')
sol()


(r, c) = list(map(int, input().split()))
grid = []
for i in range(r):
	grid.append([x for x in input()])
for i in range(r):
	for j in range(c):
		if grid[i][j] == '.':
			grid[i][j] = 'D'
ans = 'Yes'

def valid(i, j):
	return i >= 0 and j >= 0 and (i < r) and (j < c)
masks = [(1, 0), (-1, 0), (0, 1), (0, -1)]
for i in range(r):
	for j in range(c):
		if grid[i][j] != 'W':
			continue
		for (a, b) in masks:
			if valid(i + a, j + b) and grid[i + a][j + b] == 'S':
				ans = 'No'
print(ans)
if ans == 'Yes':
	for x in grid:
		print(''.join(x))


mapsize = input().split()
height = int(mapsize[0])
width = int(mapsize[1])
pasture = []
exposed = []
sheeps = []
safe = True

def inPasture(y, x):
	return not (y < 0 or x < 0 or y >= height or (x >= width))

def canPlace(y, x):
	return not (pasture[y][x] == 'S' or pasture[y][x] == 'W')

def visitWolf(y, x):
	if not inPasture(y, x) or exposed[y][x] or pasture[y][x] == 'D':
		return True
	if pasture[y][x] == 'W':
		global safe
		safe = False
		return False
	exposed[y][x] = True
	return visitWolf(y - 1, x) and visitWolf(y + 1, x) and visitWolf(y, x - 1) and visitWolf(y, x + 1)
for y in range(height):
	line = input()
	arr = []
	arr2 = []
	for x in range(width):
		arr += [line[x]]
		arr2 += [False]
		if line[x] == 'S':
			sheeps += [[y, x]]
	pasture += [arr]
	exposed += [arr2]
for sheep in sheeps:
	y = sheep[0]
	x = sheep[1]
	if inPasture(y - 1, x):
		if canPlace(y - 1, x):
			pasture[y - 1][x] = 'D'
	if inPasture(y + 1, x):
		if canPlace(y + 1, x):
			pasture[y + 1][x] = 'D'
	if inPasture(y, x - 1):
		if canPlace(y, x - 1):
			pasture[y][x - 1] = 'D'
	if inPasture(y, x + 1):
		if canPlace(y, x + 1):
			pasture[y][x + 1] = 'D'
for sheep in sheeps:
	if not visitWolf(sheep[0], sheep[1]):
		break
if safe:
	print('Yes')
	for y in range(height):
		line = ''
		for x in range(width):
			line += pasture[y][x]
		print(line)
else:
	print('No')


from sys import exit
(r, c) = map(int, input().split())
natrix = [input() for xxx in range(r)]
matrix = [z for z in natrix]
natrix = [list(zz) for zz in natrix]
a = 0
for x in range(r):
	for y in range(c):
		if matrix[x][y] == 'S':
			try:
				if matrix[x][y + 1] == 'W':
					print('No')
					a = 1
					break
			except:
				pass
			try:
				if y >= 1:
					if matrix[x][y - 1] == 'W':
						print('No')
						a = 1
						break
			except:
				pass
			try:
				if x >= 1:
					if matrix[x - 1][y] == 'W':
						print('No')
						a = 1
						break
			except:
				pass
			try:
				if matrix[x + 1][y] == 'W':
					print('No')
					a = 1
					break
			except:
				pass
		elif matrix[x][y] != 'W':
			natrix[x][y] = 'D'
	if a:
		break
else:
	print('Yes')
	for x in natrix:
		print(''.join(x))


from math import *
from collections import *
(n, m) = map(int, input().split())
flag = 0
a = []
for i in range(n):
	a.append(list(input()))
	for i in range(m):
		if a[-1][i] == '.':
			a[-1][i] = 'D'
for i in range(n):
	for j in range(m):
		if a[i][j] == 'S':
			if i > 0:
				if a[i - 1][j] == 'W':
					flag = 1
			if j > 0:
				if a[i][j - 1] == 'W':
					flag = 1
			if i < n - 1:
				if a[i + 1][j] == 'W':
					flag = 1
			if j < m - 1:
				if a[i][j + 1] == 'W':
					flag = 1
if flag == 1:
	print('No')
else:
	print('Yes')
	for i in a:
		print(''.join(i))


(r, c) = map(int, input().split())
arr = list()
for i in range(r):
	arr.append(input())
flag = 0
for i in range(r):
	for j in range(c):
		if i == r - 1 and j == c - 1:
			pass
		elif i == r - 1:
			if arr[i][j] == 'W' and arr[i][j + 1] == 'S' or (arr[i][j] == 'S' and arr[i][j + 1] == 'W'):
				flag = 1
				break
		elif j == c - 1:
			if arr[i][j] == 'W' and arr[i + 1][j] == 'S' or (arr[i][j] == 'S' and arr[i + 1][j] == 'W'):
				flag = 1
				break
		elif arr[i][j] == 'W':
			if arr[i + 1][j] == 'S':
				flag = 1
				break
			elif arr[i][j + 1] == 'S':
				flag = 1
				break
		elif arr[i][j] == 'S':
			if arr[i + 1][j] == 'W':
				flag = 1
				break
			elif arr[i][j + 1] == 'W':
				flag = 1
				break
	if flag == 1:
		break
if flag == 1:
	print('No')
else:
	print('Yes')
	for i in range(r):
		for j in range(c):
			if arr[i][j] == '.':
				print('D', end='')
			else:
				print(arr[i][j], end='')
		print()


(n, m) = [int(i) for i in input().split()]
mat = []
flag = 0
for i in range(n):
	s = str(input())
	s = list(s)
	mat.append(s)
for i in range(0, n):
	for j in range(0, m):
		if mat[i][j] == '.':
			mat[i][j] = 'D'
for i in range(0, n):
	for j in range(0, m):
		if mat[i][j] == 'W':
			if i + 1 < n and mat[i + 1][j] == 'S':
				flag = 1
			if j + 1 < m and mat[i][j + 1] == 'S':
				flag = 1
			if j - 1 >= 0 and mat[i][j - 1] == 'S':
				flag = 1
			if i - 1 >= 0 and mat[i - 1][j] == 'S':
				flag = 1
if flag == 1:
	print('NO')
else:
	print('YES')
	for j in range(0, n):
		e = ''
		for k in range(0, m):
			e = e + mat[j][k]
		print(e)


(n, m) = map(int, input().split())
matriz = []
for i in range(n):
	matriz.append(list(input()))
lobo = False
for i in range(n):
	for j in range(m):
		if matriz[i][j] == '.':
			matriz[i][j] = 'D'
for i in range(n):
	for j in range(m):
		if matriz[i][j] == 'S':
			if i + 1 < n:
				if matriz[i + 1][j] == 'W':
					lobo = True
					break
			if i - 1 >= 0:
				if matriz[i - 1][j] == 'W':
					lobo = True
					break
			if j + 1 < m:
				if matriz[i][j + 1] == 'W':
					lobo = True
					break
			if j - 1 >= 0:
				if matriz[i][j - 1] == 'W':
					lobo = True
					break
	if lobo == True:
		break
if lobo == True:
	print('No')
else:
	print('Yes')
	for i in range(n):
		linha = ''
		for j in range(m):
			linha += matriz[i][j]
		print(linha)


def is_sheep_safe(i, j):
	if i > 0 and pasture[i - 1][j] == 'W':
		return False
	if i < rows - 1 and pasture[i + 1][j] == 'W':
		return False
	if j > 0 and pasture[i][j - 1] == 'W':
		return False
	if j < columns - 1 and pasture[i][j + 1] == 'W':
		return False
	return True
(rows, columns) = map(int, input().split())
pasture = []
possible = True
for i in range(rows):
	pasture.append(input().replace('.', 'D'))
for i in range(rows):
	for j in range(columns):
		if pasture[i][j] == 'S' and (not is_sheep_safe(i, j)):
			possible = False
if possible:
	print('Yes')
	for i in pasture:
		print(i)
else:
	print('No')


(m, n) = map(eval, input().split())
s = []
for i in range(m):
	l = input()
	line = []
	for j in l:
		line.append(j)
	s.append(line)
flag = True
for i in range(m):
	for j in range(n):
		if s[i][j] == '.':
			s[i][j] = 'D'
for i in range(m):
	for j in range(n):
		if s[i][j] == 'W':
			if i > 0:
				if s[i - 1][j] == 'S':
					flag = False
					break
			if i < m - 1:
				if s[i + 1][j] == 'S':
					flag = False
					break
			if j > 0:
				if s[i][j - 1] == 'S':
					flag = False
					break
			if j < n - 1:
				if s[i][j + 1] == 'S':
					flag = False
					break
if flag == False:
	print('No')
else:
	print('Yes')
	for i in range(m):
		for j in range(n):
			print(s[i][j], end='')
		print('')


(n, m) = map(int, input().split())
F = []
for i in range(n):
	F.append(list(input()))
for i in range(n):
	for j in range(m):
		if F[i][j] == '.':
			F[i][j] = 'D'
		if F[i][j] == 'S' and (i > 0 and F[i - 1][j] == 'W' or (i < n - 1 and F[i + 1][j] == 'W') or (j > 0 and F[i][j - 1] == 'W') or (j < m - 1 and F[i][j + 1] == 'W')):
			print('No')
			quit()
print('Yes')
for i in F:
	print(*i, sep='')


(R, C) = map(int, input().split())
m = [[str(j) for j in input()] for i in range(R)]
row = 0
for i in range(R):
	if row == 1:
		break
	for j in range(C):
		if m[i][j] == '.':
			m[i][j] = 'D'
		elif m[i][j] == 'S':
			if j > 0 and m[i][j - 1] == 'W':
				row = 1
				break
			elif j < C - 1 and m[i][j + 1] == 'W':
				row = 1
				break
			elif i < R - 1 and m[i + 1][j] == 'W':
				row = 1
				break
			elif i > 0 and m[i - 1][j] == 'W':
				row = 1
				break
if row == 1:
	print('NO')
else:
	print('YES')
	for i in m:
		print(''.join(i))


(r, c) = list(map(int, input().split()))
sw = []
stat_ans = True
for i in range(1, r + 1):
	sw.append(input())
for i in range(r):
	for j in range(c):
		if sw[i][j] == 'S':
			left = j - 1
			right = j + 1
			up = i - 1
			down = i + 1
			if left >= 0:
				if sw[i][left] == 'W':
					stat_ans = False
					break
			if up >= 0:
				if sw[up][j] == 'W':
					stat_ans = False
					break
			if right < c:
				if sw[i][right] == 'W':
					stat_ans = False
					break
			if down < r:
				if sw[down][j] == 'W':
					stat_ans = False
					break
if stat_ans == False:
	print('No')
else:
	print('Yes')
	for i in range(r):
		for j in range(c):
			if sw[i][j] == '.':
				print('D', end='')
			else:
				print(sw[i][j], end='')
		print()


(n, m) = [int(x) for x in input().split()]
a = [[x for x in input()] for _ in range(n)]

def set(i, j):
	if a[i][j] == 'S':
		return False
	elif a[i][j] == '.':
		a[i][j] = 'D'
	return True
flag = True
for i in range(n):
	for j in range(m):
		if a[i][j] != 'W':
			continue
		if i > 0 and (not set(i - 1, j)):
			flag = False
		if j > 0 and (not set(i, j - 1)):
			flag = False
		if i < n - 1 and (not set(i + 1, j)):
			flag = False
		if j < m - 1 and (not set(i, j + 1)):
			flag = False
	if flag == False:
		break
if flag:
	print('Yes')
	for s in a:
		print(''.join(s))
else:
	print('No')


(R, C) = map(int, input().split())
r = []
for i in range(R):
	r.append(input().replace('.', 'D'))
	for j in range(C):
		if r[i][j] == 'W' and 'S' in [r[i][max(0, j - 1)], r[i][min(C - 1, j + 1)], r[i - 1][j]] or (r[i][j] == 'S' and r[i - 1][j] == 'W'):
			print('No')
			exit()
print('Yes')
print('\n'.join(r))


(r, c) = map(int, input().split())
rows = []
for i in range(r):
	row = list(input())
	rows.append(row)
status = False
for i in range(r):
	for j in range(c):
		if rows[i][j] == '.':
			rows[i][j] = 'D'
			continue
		if rows[i][j] == 'S':
			if i - 1 >= 0 and rows[i - 1][j] == 'W':
				status = True
			if i + 1 < r and rows[i + 1][j] == 'W':
				status = True
			if j - 1 >= 0 and rows[i][j - 1] == 'W':
				status = True
			if j + 1 < c and rows[i][j + 1] == 'W':
				status = True
if status:
	print('NO')
else:
	print('YES')
	for row in rows:
		print(''.join(row))


WOLF = 'W'
SHEEP = 'S'
DOG = 'D'
EMPTY = '.'
(R, C) = [int(x) for x in input().split()]
field = []
has_wolves = False
is_imp = False
for row_i in range(R):
	row = input()
	if row.count(WOLF):
		has_wolves = True
	field.append(row)
if not has_wolves:
	print('Yes')
	for row_i in range(R):
		print(field[row_i])
else:
	for row_i in range(R):
		for col_i in range(C):
			if field[row_i][col_i] == SHEEP and (row_i > 0 and field[row_i - 1][col_i] == WOLF or (col_i > 0 and field[row_i][col_i - 1] == WOLF) or (row_i < R - 1 and field[row_i + 1][col_i] == WOLF) or (col_i < C - 1 and field[row_i][col_i + 1] == WOLF)):
				is_imp = True
				break
			if field[row_i][col_i] == WOLF and (row_i > 0 and field[row_i - 1][col_i] == SHEEP or (col_i > 0 and field[row_i][col_i - 1] == SHEEP) or (row_i < R - 1 and field[row_i + 1][col_i] == SHEEP) or (col_i < C - 1 and field[row_i][col_i + 1] == SHEEP)):
				is_imp = True
				break
		if is_imp:
			break
	if is_imp:
		print('No')
	else:
		print('Yes')
		for row_i in range(R):
			print(field[row_i].replace(EMPTY, DOG))


(r, c) = [int(x) for x in input().split()]
res = 'Yes'
l = []
testCases = [[], [], []]
for z in range(r):
	l.append(list(input()))
for z in range(r):
	for w in range(c):
		if l[z][w] == '.':
			l[z][w] = 'D'

def checkWolfLeft(x, y):
	return l[x][y - 1] == 'W'

def checkWolfRight(x, y):
	return l[x][y + 1] == 'W'

def checkWolfUp(x, y):
	return l[x - 1][y] == 'W'

def checkWolfDown(x, y):
	return l[x + 1][y] == 'W'
for x in range(r):
	for y in range(c):
		if x == 0:
			if y == c - 1:
				if r != 1:
					if l[x][y] == 'S' and (checkWolfLeft(x, y) or checkWolfDown(x, y)):
						res = 'No'
				elif l[x][y] == 'S' and checkWolfLeft(x, y):
					res = 'No'
			elif y == 0:
				if l[x][y] == 'S' and checkWolfRight(x, y):
					res = 'No'
			elif l[x][y] == 'S' and (checkWolfLeft(x, y) or checkWolfRight(x, y)):
				res = 'No'
		elif x == r - 1:
			if y == c - 1:
				if l[x][y] == 'S' and (checkWolfLeft(x, y) or checkWolfUp(x, y)):
					res = 'No'
			elif y == 0:
				if l[x][y] == 'S' and (checkWolfRight(x, y) or checkWolfUp(x, y)):
					res = 'No'
			elif l[x][y] == 'S' and (checkWolfLeft(x, y) or checkWolfRight(x, y) or checkWolfUp(x, y)):
				res = 'No'
		elif y == c - 1:
			if l[x][y] == 'S' and (checkWolfLeft(x, y) or checkWolfDown(x, y) or checkWolfUp(x, y)):
				res = 'No'
		elif y == 0:
			if l[x][y] == 'S' and (checkWolfRight(x, y) or checkWolfDown(x, y) or checkWolfUp(x, y)):
				res = 'No'
		elif l[x][y] == 'S' and (checkWolfLeft(x, y) or checkWolfRight(x, y) or checkWolfDown(x, y) or checkWolfUp(x, y)):
			res = 'No'
if res == 'No':
	print(res)
else:
	print('Yes')
	for x in l:
		s = ''
		for _ in x:
			s += _
		print(s)


(R, C) = map(int, input().split())
r = []
f = 0
for i in range(R):
	r.append(input())
	for j in range(C):
		if r[i][j] == 'W':
			if j and r[i][j - 1] == 'S':
				f = 1
				break
			if j + 1 < C and r[i][j + 1] == 'S':
				f = 1
				break
	if f:
		break
if not f:
	for i in range(C):
		for j in range(R):
			if r[j][i] == 'W':
				if j and r[j - 1][i] == 'S':
					f = 1
					break
				if j + 1 < R and r[j + 1][i] == 'S':
					f = 1
					break
		if f:
			break
if f:
	print('No')
else:
	print('Yes')
	for i in range(R):
		print(r[i].replace('.', 'D'))


(h, w) = list(map(int, input().split()))
arr = []
for i in range(h):
	arr.append(list(input()))
flag = False
d = 0
for i in range(h):
	for g in range(w):
		if arr[i][g] == 'W':
			try:
				if arr[i][max(g - 1, 0)] == 'S':
					flag = True
			except:
				d += 1
			try:
				if arr[i][g + 1] == 'S':
					flag = True
			except:
				d += 1
			try:
				if arr[max(0, i - 1)][g] == 'S':
					flag = True
			except:
				d += 1
			try:
				if arr[i + 1][g] == 'S':
					flag = True
			except:
				d += 1
		elif arr[i][g] == '.':
			arr[i][g] = 'D'
if flag:
	print('No')
else:
	print('Yes')
	for i in range(h):
		print(''.join(arr[i]))


import sys

def neighbors(r, c):
	return [[r - 1, c], [r + 1, c], [r, c - 1], [r, c + 1]]
(R, C) = map(int, input().split())
arr = (R + 2) * [0]
for r in range(R + 2):
	arr[r] = (C + 2) * ['.']
wolves = []
for i in range(R):
	s = input()
	for j in range(C):
		arr[i + 1][j + 1] = s[j]
		if arr[i + 1][j + 1] == 'W':
			wolves.append([i + 1, j + 1])
for w in wolves:
	for n in neighbors(w[0], w[1]):
		if arr[n[0]][n[1]] == 'S':
			print('No')
			sys.exit()
		if arr[n[0]][n[1]] == '.':
			arr[n[0]][n[1]] = 'D'
print('Yes')
for i in range(R):
	for j in range(C - 1):
		print(arr[i + 1][j + 1], end='')
	print(arr[i + 1][C])


(r, c) = input().split(' ')
r = int(r)
c = int(c)
a = [[None for _ in range(0)] for _ in range(r)]
flag = 0
for i in range(r):
	x = input()
	for j in range(len(x)):
		a[i].append(x[j])
for i in range(r):
	for j in range(c):
		if i != r - 1 and a[i][j] == 'W' and (a[i + 1][j] == 'S'):
			flag = 1
			break
		if i != r - 1 and a[i][j] == 'S' and (a[i + 1][j] == 'W'):
			flag = 1
			break
		if i != 0 and a[i][j] == 'W' and (a[i - 1][j] == 'S'):
			flag = 1
			break
		if i != 0 and a[i][j] == 'S' and (a[i - 1][j] == 'W'):
			flag = 1
			break
		if j + 1 != c and a[i][j] == 'S' and (a[i][j + 1] == 'W') or (j + 1 != c and a[i][j] == 'W' and (a[i][j + 1] == 'S')):
			flag = 1
			break
if flag != 1:
	print('Yes')
	for i in range(r):
		for j in range(c - 1):
			if a[i][j] == '.':
				a[i][j] = 'D'
			print(a[i][j], end='')
		if a[i][c - 1] == '.':
			a[i][c - 1] = 'D'
		print(a[i][c - 1])
else:
	print('No')


from __future__ import division, print_function
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
from math import ceil, floor, log, sqrt, factorial, pow, pi

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p1
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def dfs(v, c):
	if visited[v]:
		if col[v] != c:
			print('-1')
			exit()
		return
	col[v] = c
	visited[v] = 1
	for i in graph[v]:
		dfs(i, c ^ 1)

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph():
	d = {}
	(v, e) = mi()
	for i in range(e):
		(x, y) = mi()
		if x not in d.keys():
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d.keys():
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(l, n):
	d = {}
	for i in range(1, n + 1):
		if i not in d.keys():
			d[i] = l[i]
		else:
			d[i].append(l[i])
	return d
(n, m) = mi()
a = [''] * n
for i in range(n):
	a[i] += input().replace('.', 'D')
	if 'WS' in a[i] or 'SW' in a[i]:
		print('NO')
		exit(0)
b = [''] * m
for i in range(m):
	for j in range(n):
		b[i] += a[j][i]
	if 'WS' in b[i] or 'SW' in b[i]:
		print('NO')
		exit(0)
print('YES')
for i in range(n):
	print(a[i])


(r, c) = map(int, input().split())
num = [[1] * (c + 2)]
for i in range(r):
	s = input()
	ans = [1]
	for j in range(len(s)):
		if s[j] == '.':
			ans.append('D')
		else:
			ans.append(s[j])
	ans.append(1)
	num.append(ans)
num.append([1] * (c + 2))
fl = True
for i in range(1, len(num) - 1):
	for j in range(1, len(num[i]) - 1):
		if num[i][j] == 'S' and (num[i][j - 1] == 'W' or num[i][j + 1] == 'W' or num[i - 1][j] == 'W' or (num[i + 1][j] == 'W')):
			fl = False
if fl:
	print('Yes')
	for i in range(1, len(num) - 1):
		for j in range(1, len(num[i]) - 1):
			print(num[i][j], end='')
		print()
else:
	print('No')


dim = list(map(int, input().split()))
scheme = []
for i in range(dim[0]):
	row = list(input())
	scheme.append(row)
safe = True
for i in range(dim[0]):
	for j in range(dim[1]):
		if scheme[i][j] == 'S':
			if j != 0:
				if scheme[i][j - 1] == '.':
					scheme[i][j - 1] = 'D'
				elif scheme[i][j - 1] == 'W':
					safe = False
					break
			if j != dim[1] - 1:
				if scheme[i][j + 1] == '.':
					scheme[i][j + 1] = 'D'
				elif scheme[i][j + 1] == 'W':
					safe = False
					break
			if i != 0:
				if scheme[i - 1][j] == '.':
					scheme[i - 1][j] = 'D'
				elif scheme[i - 1][j] == 'W':
					safe = False
					break
			if i != dim[0] - 1:
				if scheme[i + 1][j] == '.':
					scheme[i + 1][j] = 'D'
				elif scheme[i + 1][j] == 'W':
					safe = False
					break
	if not safe:
		break
if safe:
	print('Yes')
	for i in range(dim[0]):
		print(''.join(scheme[i]))
else:
	print('No')


(r, c) = list(map(int, input().split()))
ls = [[c for c in input()] for i in range(r)]
for i in range(r):
	dead = False
	for j in range(c):
		if ls[i][j] == 'W':
			if i != 0 and ls[i - 1][j] == 'S':
				dead = True
			if i != r - 1 and ls[i + 1][j] == 'S':
				dead = True
			if j != 0 and ls[i][j - 1] == 'S':
				dead = True
			if j != c - 1 and ls[i][j + 1] == 'S':
				dead = True
			if dead:
				break
		elif ls[i][j] == '.':
			ls[i][j] = 'D'
	if dead:
		print('No')
		break
else:
	print('Yes')
	for i in range(r):
		print(''.join(ls[i]))


(r, c) = map(int, input().split())
m = []
k = 0
log = False
for i in range(r):
	m.append([])
	m[i] = list(input())
for i in range(r):
	for y in range(c):
		if m[i][y] == '.':
			m[i][y] = 'D'
for i in range(r):
	if log:
		break
	for y in range(c):
		if m[i][y] == 'W':
			if y + 1 < c:
				if m[i][y + 1] == 'S':
					log = True
					break
			if y - 1 >= 0:
				if m[i][y - 1] == 'S':
					log = True
					break
			if i + 1 < r:
				if m[i + 1][y] == 'S':
					log = True
					break
			if i - 1 >= 0:
				if m[i - 1][y] == 'S':
					log = True
					break
if log == False:
	print('Yes')
	for i in range(len(m)):
		print(*m[i], sep='')
else:
	print('No')


(a, b) = map(int, input().split())
array = []
for i in range(a):
	array.append(input().strip('/n'))
for i in range(a):
	for j in range(b - 1):
		if set([array[i][j], array[i][j + 1]]) == set(['S', 'W']):
			print('No')
			exit(0)
for i in range(a - 1):
	for j in range(b):
		if set([array[i][j], array[i + 1][j]]) == set(['S', 'W']):
			print('No')
			exit(0)
print('Yes')
l = []
for i in range(a):
	for j in range(b):
		if array[i][j] == '.':
			l.append('D')
		else:
			l.append(array[i][j])
		if b - j == 1:
			l.append('\n')
print(*l, end='', sep='')


def okay(sl, r, c):
	rv = [sl[i][j] for i in range(r) for j in range(c)]
	cv = [sl[i][j] for j in range(c) for i in range(r)]
	for i in range(1, r * c):
		if i % c > 0 and (rv[i - 1] == 'S' and rv[i] == 'W' or (rv[i - 1] == 'W' and rv[i] == 'S')):
			return False
		if i % r > 0 and (cv[i - 1] == 'S' and cv[i] == 'W' or (cv[i - 1] == 'W' and cv[i] == 'S')):
			return False
	return True
(r, c) = list(map(int, input().split()))
sl = [input() for i in range(r)]
if okay(sl, r, c):
	print('YES')
	for s in sl:
		print(s.replace('.', 'D'))
else:
	print('NO')


(R, C) = map(int, input().split())
(maze, sheeps, wolfs) = ([], set(), set())
for i in range(R):
	j = 0
	lines = []
	line = input()
	for l in line:
		if l == 'S':
			sheeps.add((i, j))
		if l == 'W':
			wolfs.add((i, j))
		lines.append(l)
		j += 1
	maze.append(lines)
foundWolf = False
for sheep in sheeps:
	(x, y) = (sheep[1], sheep[0])
	if x + 1 < C and maze[y][x + 1] == 'W' or (x - 1 >= 0 and maze[y][x - 1] == 'W') or (y + 1 < R and maze[y + 1][x] == 'W') or (y - 1 >= 0 and maze[y - 1][x] == 'W'):
		print('No')
		foundWolf = True
		break
	if x + 1 < C and maze[y][x + 1] == '.':
		maze[y][x + 1] = 'D'
	if x - 1 >= 0 and maze[y][x - 1] == '.':
		maze[y][x - 1] = 'D'
	if y + 1 < R and maze[y + 1][x] == '.':
		maze[y + 1][x] = 'D'
	if y - 1 >= 0 and maze[y - 1][x] == '.':
		maze[y - 1][x] = 'D'
if not foundWolf:
	print('Yes')
	for x in maze:
		print(''.join(x))


(a, b) = map(int, input().split())
m = []
for i in range(a):
	tmp = input()
	m.append(tmp)
for i in range(a):
	for j in range(b):
		if m[i][j] == 'W':
			if i + 1 < a:
				if m[i + 1][j] == 'S':
					print('NO')
					exit()
			if i - 1 >= 0:
				if m[i - 1][j] == 'S':
					print('NO')
					exit()
			if j + 1 < b:
				if m[i][j + 1] == 'S':
					print('NO')
					exit()
			if j - 1 >= 0:
				if m[i][j - 1] == 'S':
					print('NO')
					exit()
print('YES')
for i in range(a):
	for j in range(b):
		if m[i][j] == '.':
			print('D', end='')
		else:
			print(m[i][j], end='')
	print()


(r, c) = map(int, input().split())
l = []
f = 0
for i in range(r):
	k = list(input())
	l.append(k)
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]
for i in range(r):
	for j in range(c):
		if l[i][j] == 'S':
			for k in range(4):
				if -1 < i + dx[k] < r and -1 < j + dy[k] < c:
					x = i + dx[k]
					y = j + dy[k]
					if l[x][y] == '.':
						l[x][y] = 'D'
					elif l[x][y] == 'W':
						f = 1
						break
if f == 1:
	print('No')
else:
	print('Yes')
	for i in l:
		print(''.join(i))


(r, c) = map(int, input().split())
(s, a) = ([], [])
for i in range(r):
	s.append(input().replace('.', 'D'))
for i in range(c):
	b = ''
	for j in range(r):
		b += ''.join(s[j][i])
	a.append(b)
for i in s:
	if 'SW' in i or 'WS' in i:
		exit(print('NO'))
for i in a:
	if 'SW' in i or 'WS' in i:
		exit(print('NO'))
else:
	print('YES')
	print(*s, sep='\n')


(r, c) = (int(x) for x in input().split())
g = []
for i in range(r):
	g.append(input())

def fn():
	for rr in range(r):
		for cc in range(c):
			if g[rr][cc] != 'W':
				continue
			if cc > 0 and g[rr][cc - 1] == 'S':
				return False
			if cc < c - 1 and g[rr][cc + 1] == 'S':
				return False
			if rr > 0 and g[rr - 1][cc] == 'S':
				return False
			if rr < r - 1 and g[rr + 1][cc] == 'S':
				return False
	return True
res = fn()
if not res:
	print('No')
else:
	print('Yes')
	for row in g:
		print(row.replace('.', 'D'))


from sys import stdout, stdin, setrecursionlimit
from io import BytesIO, IOBase
from collections import *
from itertools import *
from bisect import *
from string import *
from queue import *
from heapq import *
from math import *
from re import *
from os import *

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
(graph, mod, szzz) = ({}, 10 ** 9 + 7, lambda : sorted(zzz()))

def getStr():
	return input()

def getInt():
	return int(input())

def listStr():
	return list(input())

def getStrs():
	return input().split()

def isInt(s):
	return '0' <= s[0] <= '9'

def input():
	return stdin.readline().strip()

def zzz():
	return [int(i) for i in input().split()]

def output(answer, end='\n'):
	stdout.write(str(answer) + end)

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
(n, m) = zzz()
lst = []
for i in range(n):
	lst.append(listStr())
isSafe = True
for i in range(n):
	for j in range(m):
		if lst[i][j] != 'S':
			continue
		for d in range(4):
			(x, y) = (i + dx[d], j + dy[d])
			if 0 <= x < n and 0 <= y < m:
				if lst[x][y] == 'W':
					isSafe = False
				elif lst[x][y] == '.':
					lst[x][y] = 'D'
if isSafe:
	print('Yes')
	for i in lst:
		print(''.join(i))
else:
	print('No')


(n, m) = map(int, input().split())
arr = []
for i in range(n):
	arr.append(list(input()))
p = 'Yes'
for i in range(n):
	for j in range(m):
		if arr[i][j] == 'W':
			if i != 0 and arr[i - 1][j] == 'S':
				p = 'No'
				break
			elif i != 0 and arr[i - 1][j] != 'W':
				arr[i - 1][j] = 'D'
			if i != n - 1 and arr[i + 1][j] == 'S':
				p = 'No'
				break
			elif i != n - 1 and arr[i + 1][j] != 'W':
				arr[i + 1][j] = 'D'
			if j != 0 and arr[i][j - 1] == 'S':
				p = 'No'
				break
			elif j != 0 and arr[i][j - 1] != 'W':
				arr[i][j - 1] = 'D'
			if j != m - 1 and arr[i][j + 1] == 'S':
				p = 'No'
				break
			elif j != m - 1 and arr[i][j + 1] != 'W':
				arr[i][j + 1] = 'D'
	if p == 'No':
		break
if p == 'Yes':
	print(p)
	for i in range(n):
		print(''.join(arr[i]))
else:
	print(p)


(r, c) = map(int, input().split(' '))
grid = []
for row in range(r):
	grid.append([])
for row in grid:
	x = input()
	for z in x:
		row.append(z)
resp = 'YES'
for i in range(r):
	for j in range(c):
		if grid[i][j] == 'S':
			if 0 < i:
				if grid[i - 1][j] == 'W':
					resp = 'NO'
					break
			if 0 < j:
				if grid[i][j - 1] == 'W':
					resp = 'NO'
					break
			if i < r - 1:
				if grid[i + 1][j] == 'W':
					resp = 'NO'
					break
			if j < c - 1:
				if grid[i][j + 1] == 'W':
					resp = 'NO'
					break
if resp == 'NO':
	print(resp)
else:
	print(resp)
	for i in range(r):
		line = ''
		for j in range(c):
			if grid[i][j] == '.':
				line += 'D'
			else:
				line += grid[i][j]
		print(line)


def Fill(A, x, y, n, m):
	Bool = False
	if x > 0:
		if A[x - 1][y] == '.':
			A[x - 1][y] = 'D'
		if A[x - 1][y] == 'W':
			Bool = True
	if y > 0:
		if A[x][y - 1] == '.':
			A[x][y - 1] = 'D'
		if A[x][y - 1] == 'W':
			Bool = True
	if y < m - 1:
		if A[x][y + 1] == '.':
			A[x][y + 1] = 'D'
		if A[x][y + 1] == 'W':
			Bool = True
	if x < n - 1:
		if A[x + 1][y] == '.':
			A[x + 1][y] = 'D'
		if A[x + 1][y] == 'W':
			Bool = True
	return Bool
(n, m) = list(map(int, input().split()))
A = []
for _ in range(n):
	S = list(input())
	A.append(S)
Ans = False
for n1 in range(n):
	for n2 in range(m):
		if A[n1][n2] == 'S':
			Temp = Fill(A, n1, n2, n, m)
			if Temp == True:
				Ans = True
				break
	if Ans == True:
		break
if Ans == False:
	print('Yes')
	for val in A:
		print(''.join(val))
else:
	print('No')


import re
cat = '(WS)|(SW)'
(n, k) = map(int, input().split())
f = False
d = []
prev = 'i' * k
for _ in range(n):
	l = input()
	if re.search(cat, l):
		f = True
	l = l.replace('.', 'D')
	d.append(l)
	start = 0
	for _ in range(l.count('S')):
		if prev[l.index('S', start)] == 'W':
			f = True
			break
		start = l.index('S', start) + 1
	start = 0
	for _ in range(l.count('W')):
		if prev[l.index('W', start)] == 'S':
			f = True
			break
		start = l.index('W', start) + 1
	prev = l
if f:
	print('No')
else:
	print('Yes')
	for i in d:
		print(i)


from collections import defaultdict

def op():
	(r, c) = map(int, input().split())
	sx = []
	mat = []
	flg = 0
	for i in range(r):
		s = input()
		s = s.replace('.', 'D')
		s = list(s)
		for j in range(c):
			if s[j] == 'S':
				sx.append([i, j])
		mat.append(s)
	for i in range(r):
		for j in range(c):
			if mat[i][j] == 'W':
				if [i - 1, j] in sx or [i + 1, j] in sx or [i, j + 1] in sx or ([i, j - 1] in sx):
					print('No')
					flg = 1
					return
	if flg == 0:
		print('Yes')
		for i in mat:
			print(''.join(i))
op()


(r, c) = map(int, input().split())
s = []
for i in range(r):
	a = input().replace('.', 'D')
	s.append(a)
ans = 'Yes'
y = [''.join(x) for x in list(zip(*s))]
for x in s:
	if 'SW' in x or 'WS' in x:
		ans = 'No'
for x in y:
	if 'SW' in x or 'WS' in x:
		ans = 'No'
if ans == 'Yes':
	print(ans)
	print('\n'.join(s))
else:
	print(ans)


(r, c) = map(int, input().split())
x = [[] for i in range(r)]
for i in range(r):
	k = input()
	for y in k:
		x[i].append(y)
ind = True
for i in range(0, r):
	for j in range(0, c):
		if i >= 1 and x[i][j] == 'W' and (x[i - 1][j] == 'S') or (i >= 1 and x[i][j] == 'S' and (x[i - 1][j] == 'W')) or (j >= 1 and x[i][j - 1] == 'W' and (x[i][j] == 'S')) or (j >= 1 and x[i][j - 1] == 'S' and (x[i][j] == 'W')) or (i < r - 1 and x[i][j] == 'S' and (x[i + 1][j] == 'W')) or (i < r - 1 and x[i][j] == 'W' and (x[i + 1][j] == 'S')) or (j < c - 1 and x[i][j] == 'W' and (x[i][j + 1] == 'S')) or (j < c - 1 and x[i][j] == 'S' and (x[i][j + 1] == 'W')):
			ind = False
			break
		elif x[i][j] != 'W' and x[i][j] != 'S':
			x[i][j] = 'D'
if not ind:
	print('No')
else:
	print('Yes')
	for i in range(r):
		print(''.join(map(str, x[i])))


def safe(i, j):
	if a[i][j + 1] == 'W':
		return False
	if a[i][j - 1] == 'W':
		return False
	if a[i + 1][j] == 'W':
		return False
	if a[i - 1][j] == 'W':
		return False
	return True

def dogplace(i, j):
	if a[i][j + 1] != 'S':
		a[i][j + 1] = 'D'
	if a[i][j - 1] != 'S':
		a[i][j - 1] = 'D'
	if a[i + 1][j] != 'S':
		a[i + 1][j] = 'D'
	if a[i - 1][j] != 'S':
		a[i - 1][j] = 'D'
(r, c) = map(int, input().split())
a = []
a.append(['.' for i in range(c + 1)])
for i in range(r):
	t = input()
	a.append(['.'])
	for j in range(len(t)):
		a[i + 1].append(t[j])
	a[i + 1].append('.')
a.append(['.' for i in range(c + 1)])
no = False
for i in range(1, len(a) - 1):
	for j in range(1, len(a[i]) - 1):
		if a[i][j] == 'S':
			if safe(i, j):
				dogplace(i, j)
			else:
				no = True
				break
	if no:
		break
if no:
	print('No')
else:
	print('Yes')
	for i in range(1, len(a) - 1):
		s = ''
		for j in range(1, len(a[i]) - 1):
			s += a[i][j]
		print(s)


(n, m) = map(int, input().split())
a = [''] * n
for i in range(n):
	a[i] += input().replace('.', 'D')
	if 'SW' in a[i] or 'WS' in a[i]:
		print('NO')
		exit(0)
b = [''] * m
for i in range(m):
	for j in range(n):
		b[i] += a[j][i]
	if 'SW' in b[i] or 'WS' in b[i]:
		print('NO')
		exit(0)
print('YES')
for i in range(n):
	print(a[i])


(r, c) = map(int, input().split())
aux = False
lista = []
for e in range(r):
	contex = input()
	lista.append(contex)
for i in range(r):
	for j in range(c):
		if lista[i][j] == 'W' and i + 1 < r:
			if lista[i + 1][j] == 'S':
				aux = True
				break
		if lista[i][j] == 'W' and j + 1 < c:
			if lista[i][j + 1] == 'S':
				aux = True
				break
		if lista[i][j] == 'W' and i > 0:
			if lista[i - 1][j] == 'S':
				aux = True
				break
		if lista[i][j] == 'W' and j > 0:
			if lista[i][j - 1] == 'S':
				aux = True
				break
	if aux:
		break
if aux:
	print('No')
else:
	print('Yes')
	for s in lista:
		e = list(s)
		i = 0
		while i < c:
			if e[i] == '.':
				e[i] = 'D'
			i += 1
		print(''.join(e))


numbers = list(map(int, input().split()))
n = numbers[0]
m = numbers[1]
field = []
field.append(' ' * (m + 2))
for i in range(n):
	field.append(' ' + input() + ' ')
field.append(' ' * (m + 2))
allSheepAlive = True
for i in range(1, n + 1):
	for j in range(1, m + 1):
		if field[i][j] == 'W':
			if field[i + 1][j] == 'S' or field[i - 1][j] == 'S' or field[i][j + 1] == 'S' or (field[i][j - 1] == 'S'):
				allSheepAlive = False
if allSheepAlive is False:
	print('No')
	exit()
print('Yes')
for i in range(1, n + 1):
	print(field[i].replace('.', 'D')[1:m + 1])


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a += list(input())
for i in range(m * n):
	if a[i] == 'W':
		if i - m >= 0 and a[i - m] == 'S':
			print('NO')
			exit()
		if i + m < m * n and a[i + m] == 'S':
			print('NO')
			exit()
		if i % m == 0 and i + 1 < m * n and (a[i + 1] == 'S'):
			print('NO')
			exit()
		if (i + 1) % m == 0 and a[i - 1] == 'S':
			print('NO')
			exit()
		if (i + 1) % m != 0 and i % m != 0 and (a[i + 1] == 'S' or a[i - 1] == 'S'):
			print('NO')
			exit()
print('YES')
for i in range(n * m):
	if a[i] == '.':
		a[i] = 'D'
	print(a[i], end='')
	if (i + 1) % m == 0:
		print('')


(r, c) = map(int, input().split())
a = []
flag = False
for i in range(r):
	a.append(list(input()))
for i in range(r):
	for j in range(c):
		if a[i][j] == '.':
			a[i][j] = 'D'
		elif a[i][j] == 'W':
			if j != c - 1:
				if a[i][j + 1] == 'S':
					flag = True
					break
			if j != 0:
				if a[i][j - 1] == 'S':
					flag = True
					break
			if i != 0:
				if a[i - 1][j] == 'S':
					flag = True
					break
			if i != r - 1:
				if a[i + 1][j] == 'S':
					flag = True
					break
	if flag:
		print('No')
		break
else:
	print('Yes')
	for i in range(r):
		print(''.join(a[i]))


(r, c) = map(int, input().split())
s = []
for i in range(r):
	s.append(input())
ans = []
b = 1
for i in s:
	ans.append(i.replace('.', 'D'))
for i in ans:
	if i.find('SW') != -1 or i.find('WS') != -1:
		b = 0
		print('No')
		break
if b != 0:
	rez = [''.join(s) for s in zip(*ans)]
	for i in rez:
		if i.find('SW') != -1 or i.find('WS') != -1:
			b = 0
			print('No')
			break
	if b != 0:
		print('Yes')
		for i in ans:
			print(i)


import sys
(r, c) = list(map(int, input().split()))
m = []
for _ in range(r):
	m.append(list(input()))
for i in range(r):
	for j in range(c):
		if m[i][j] == 'W':
			if i > 0:
				if m[i - 1][j] == 'S':
					print('No')
					sys.exit()
				elif m[i - 1][j] == '.':
					m[i - 1][j] = 'D'
			if i < r - 1:
				if m[i + 1][j] == 'S':
					print('No')
					sys.exit()
				elif m[i + 1][j] == '.':
					m[i + 1][j] = 'D'
			if j > 0:
				if m[i][j - 1] == 'S':
					print('No')
					sys.exit()
				elif m[i][j - 1] == '.':
					m[i][j - 1] = 'D'
			if j < c - 1:
				if m[i][j + 1] == 'S':
					print('No')
					sys.exit()
				elif m[i][j + 1] == '.':
					m[i][j + 1] = 'D'
print('Yes')
for row in m:
	print(''.join(row))


(n, m) = map(int, input().split())
arr = []
for i in range(n):
	arr.append(list(input()))
for i in range(n):
	for j in range(m):
		if arr[i][j] == 'S':
			if i:
				if arr[i - 1][j] == '.':
					arr[i - 1][j] = 'D'
				elif arr[i - 1][j] == 'W':
					print('No')
					exit()
			if j:
				if arr[i][j - 1] == '.':
					arr[i][j - 1] = 'D'
				elif arr[i][j - 1] == 'W':
					print('No')
					exit()
			if i + 1 < n:
				if arr[i + 1][j] == '.':
					arr[i + 1][j] = 'D'
				elif arr[i + 1][j] == 'W':
					print('No')
					exit()
			if j + 1 < m:
				if arr[i][j + 1] == '.':
					arr[i][j + 1] = 'D'
				elif arr[i][j + 1] == 'W':
					print('No')
					exit()
print('Yes')
for i in arr:
	print(''.join(i))


(n, m) = map(int, input().split())
a = []
for i in range(n):
	s = input()
	b = ''
	for i in s:
		if i == '.':
			b += 'D'
		else:
			b += i
	a.append(b)
for i in range(n):
	s = a[i].find('S')
	if i != 0 and s != -1:
		if a[i - 1][s] == 'W':
			print('NO')
			exit()
	if i != n - 1 and s != -1:
		if a[i + 1][s] == 'W':
			print('NO')
			exit()
	if 'SW' in a[i] or 'WS' in a[i]:
		print('NO')
		exit()
print('YES')
print(*a, sep='\n')


(n, m) = map(int, input().split())
s = []
for _ in range(n):
	s.append(input())
for i in range(n):
	for j in range(m):
		if s[i][j] == 'S':
			for (fx, fy) in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
				(x, y) = (i + fx, j + fy)
				if 0 <= x < n and 0 <= y < m:
					if s[x][y] == 'W':
						print('No')
						exit()
print('Yes')
for i in s:
	print(i.replace('.', 'D'))


primera_linea = input()
(r, c) = primera_linea.split(' ')
r = int(r)
c = int(c)
area = []
for i in range(r):
	fila = input()
	area.append(list(fila))
respuesta = 'Yes'
for i in range(r):
	for j in range(c):
		if area[i][j] == '.':
			area[i][j] = 'D'
		if area[i][j] == 'S':
			if i > 0 and area[i - 1][j] == 'W':
				respuesta = 'No'
			if i < r - 1 and area[i + 1][j] == 'W':
				respuesta = 'No'
			if j > 0 and area[i][j - 1] == 'W':
				respuesta = 'No'
			if j < c - 1 and area[i][j + 1] == 'W':
				respuesta = 'No'
print(respuesta)
if respuesta == 'Yes':
	for i in range(r):
		print(''.join(area[i]))


def rahul(n, c1):
	r = 0
	d = list()
	while r < len(n):
		if n[r] == c1:
			n[r] = 0
			d.append(r)
		r = r + 1
	return d

def replace(a, b, c):
	r = 0
	while r < len(a):
		if a[r] == b:
			a[r] = c
		r = r + 1
	return a
a = [int(a) for a in input().split()]
r = 0
b = list()
bs = list()
while r < a[0]:
	word = input()
	bs.append(word)
	b.append([char for char in word])
	r = r + 1
r = 0
d = 0
while r < a[0]:
	n = b[r].copy()
	m = rahul(n, 'S')
	if r == 0 and 'SW' not in bs[r] and ('WS' not in bs[r]):
		if a[0] == 1:
			d = 0
		else:
			for item in m:
				if b[r + 1][item] != 'W':
					d = 0
					continue
				else:
					d = 1
					break
		if d == 1:
			break
	elif r == a[0] - 1 and 'SW' not in bs[r] and ('WS' not in bs[r]):
		for item in m:
			if b[r - 1][item] != 'W':
				d = 0
				continue
			else:
				d = 1
				break
		if d == 1:
			break
	elif r > 0 and r < a[0] - 1 and ('SW' not in bs[r]) and ('WS' not in bs[r]):
		for item in m:
			if b[r + 1][item] != 'W' and b[r - 1][item] != 'W':
				d = 0
				continue
			else:
				d = 1
				break
		if d == 1:
			break
	else:
		d = 1
		break
	r = r + 1
if d == 1:
	print('No')
else:
	print('Yes')
	for item in b:
		replace(item, '.', 'D')
		print(''.join((char for char in item)))


(r, c) = map(int, input().split())
flag = False
aux = []
for i in range(r):
	string = list(input())
	aux.append(string)
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]
for i in range(r):
	for j in range(c):
		if aux[i][j] == 'S':
			for k in range(4):
				if -1 < i + dx[k] < r and -1 < j + dy[k] < c:
					x = i + dx[k]
					y = j + dy[k]
					if aux[x][y] == '.':
						aux[x][y] = 'D'
					elif aux[x][y] == 'W':
						flag = True
						break
if flag:
	print('No')
else:
	print('Yes')
	for i in aux:
		print(''.join(i))


from sys import stdin
(r, c) = [int(x) for x in stdin.readline().rstrip().split()]
input_rows = []
for i in range(0, r):
	line = stdin.readline().rstrip()
	input_rows.append(line)
found_wolf_conflict = False
for i in range(0, r):
	for j in range(0, c):
		ch = input_rows[i][j]
		if ch == 'S':
			if i > 0 and input_rows[i - 1][j] == 'W' or (i < r - 1 and input_rows[i + 1][j] == 'W') or (j > 0 and input_rows[i][j - 1] == 'W') or (j < c - 1 and input_rows[i][j + 1] == 'W'):
				found_wolf_conflict = True
if found_wolf_conflict:
	print('No')
else:
	print('Yes')
	for i in range(0, r):
		chars_list = list(input_rows[i])
		for j in range(0, c):
			if input_rows[i][j] == '.':
				chars_list[j] = 'D'
		print(''.join(chars_list))


def in_bounds(i, j, r, c):
	return 0 <= i < c and 0 <= j < r

def solve(r, c, mat):
	sides = ((-1, 0), (1, 0), (0, 1), (0, -1))
	for y in range(r):
		for x in range(c):
			if mat[y][x] == 'S':
				for (offset_x, offset_y) in sides:
					new_x = x + offset_x
					new_y = y + offset_y
					if not in_bounds(new_x, new_y, r, c):
						continue
					if mat[new_y][new_x] == 'W':
						return 'No'
					if mat[new_y][new_x] == '.':
						mat[new_y][new_x] = 'D'
	return 'Yes\n' + '\n'.join((''.join(r) for r in mat))
(r, c) = map(int, input().split())
mat = [list(input()) for _ in range(r)]
print(solve(r, c, mat))


(n, m) = map(int, input().split())
l = []
f = 0
for i in range(n):
	d = input()
	if 'SW' in d or 'WS' in d:
		f = 1
	l.append(list(d))
if f == 1:
	print('No')
else:
	for i in range(n):
		for j in range(m):
			if l[i][j] == '.':
				l[i][j] = 'D'
	x = 0
	for i in range(n - 1):
		for j in range(m):
			if l[i][j] == 'S' and l[i + 1][j] == 'W':
				x = 1
				break
			elif l[i][j] == 'W' and l[i + 1][j] == 'S':
				x = 1
				break
		if x == 1:
			break
	if x == 1:
		print('No')
	else:
		print('Yes')
		for i in range(n):
			print(''.join(l[i]))


(r, c) = map(int, input().rstrip().split())
a = []
ans = 1
for i in range(r):
	t = list(input())
	if ans > 0:
		for j in range(1, c - 1):
			if t[j] == 'W':
				if t[j + 1] == 'S' or t[j - 1] == 'S':
					ans = -1
		if c > 1:
			if t[0] == 'W':
				if t[1] == 'S':
					ans = -1
			elif t[0] == 'S':
				if t[1] == 'W':
					ans = -1
			if t[-1] == 'W':
				if t[-2] == 'S':
					ans = -1
			elif t[-1] == 'S':
				if t[-2] == 'W':
					ans = -1
	a.append(t)
if ans == -1:
	print('NO')
	ans = 0
else:
	for j in range(c):
		for i in range(1, r - 1):
			if a[i][j] == 'W':
				if a[i - 1][j] == 'S' or a[i + 1][j] == 'S':
					ans = -1
					break
	for i in range(c):
		if r > 1:
			if a[0][i] == 'W':
				if a[1][i] == 'S':
					ans = -1
					break
			elif a[0][i] == 'S':
				if a[1][i] == 'W':
					ans = -1
					break
			if a[-1][i] == 'W':
				if a[-2][i] == 'S':
					ans = -1
					break
			elif a[-1][i] == 'S':
				if a[-2][i] == 'W':
					ans = -1
					break
if ans == -1:
	print('NO')
	ans = 0
elif ans > 0:
	print('YES')
	for i in range(r):
		for j in range(c):
			if a[i][j] == '.':
				print('D', end='')
			else:
				print(a[i][j], end='')
		print()


def isSafeI(i, N):
	if i >= 0 and i < N:
		return True
	return False

def isSafeJ(j, M):
	if j >= 0 and j < M:
		return True
	return False
(N, M) = [int(x) for x in input().split()]
Matrix = []
for i in range(N):
	Temp = input()
	TempList = []
	for i in Temp:
		TempList.append(i)
	Matrix.append(TempList)
flag = 0
for i in range(N):
	for j in range(M):
		if Matrix[i][j] == 'W':
			if isSafeI(i + 1, N) == True:
				if Matrix[i + 1][j] == 'S':
					flag = 1
					break
				elif Matrix[i + 1][j] == '.':
					Matrix[i + 1][j] = 'D'
			if isSafeI(i - 1, N) == True:
				if Matrix[i - 1][j] == 'S':
					flag = 1
					break
				elif Matrix[i - 1][j] == '.':
					Matrix[i - 1][j] = 'D'
			if isSafeJ(j + 1, M) == True:
				if Matrix[i][j + 1] == 'S':
					flag = 1
					break
				elif Matrix[i][j + 1] == '.':
					Matrix[i][j + 1] = 'D'
			if isSafeJ(j - 1, M) == True:
				if Matrix[i][j - 1] == 'S':
					flag = 1
					break
				elif Matrix[i][j - 1] == '.':
					Matrix[i][j - 1] = 'D'
	if flag == 1:
		break
if flag == 1:
	print('NO')
else:
	print('YES')
	for i in range(N):
		s = ''
		print(s.join(Matrix[i]))


(R, C) = map(int, input().split())
m = [input() for r in range(R)]
f = False
for i in range(R):
	for j in range(C):
		if m[i][j] == 'S':
			if i - 1 >= 0 and m[i - 1][j] == 'W' or (i + 1 < R and m[i + 1][j] == 'W') or (j - 1 >= 0 and m[i][j - 1] == 'W') or (j + 1 < C and m[i][j + 1] == 'W'):
				print('No')
				f = True
				break
	if f:
		break
if not f:
	print('Yes')
	for i in range(R):
		print(m[i].replace('.', 'D'))


pairs = [int(s) for s in input().split(' ')]
R = int(pairs[0])
C = int(pairs[1])

def convert(s):
	if s == '.':
		return 0
	elif s == 'S':
		return 1
	else:
		return 2
lines = []
matrix = []
for i in range(R):
	inpt = input()
	lines.append(inpt.replace('.', 'D'))
	matrix.append([convert(s) for s in list(inpt)])
can = True
for i in range(R):
	for j in range(C):
		if matrix[i][j] == 1:
			if i > 0:
				if matrix[i - 1][j] == 2:
					can = False
					break
			if i < R - 1:
				if matrix[i + 1][j] == 2:
					can = False
					break
			if j > 0:
				if matrix[i][j - 1] == 2:
					can = False
					break
			if j < C - 1:
				if matrix[i][j + 1] == 2:
					can = False
					break
if can == True:
	print('Yes')
	for line in lines:
		print(line)
else:
	print('No')


(r, c) = map(int, input().split())
l = []
ans = 'Yes'
for i in range(r):
	x = list(str(input()))
	l.append(x)
for i in range(r):
	for j in range(c):
		if l[i][j] == 'W':
			if i > 0 and l[i - 1][j] == 'S':
				ans = 'No'
				break
			if j > 0 and l[i][j - 1] == 'S':
				ans = 'No'
				break
			if i < r - 1 and l[i + 1][j] == 'S':
				ans = 'No'
				break
			if j < c - 1 and l[i][j + 1] == 'S':
				ans = 'No'
				break
	if ans == 'No':
		break
if ans == 'No':
	print(ans)
else:
	print('Yes')
	for i in range(r):
		for j in range(c):
			if l[i][j] == 'W':
				if i > 0 and l[i - 1][j] == '.':
					l[i - 1][j] = 'D'
				if j > 0 and l[i][j - 1] == '.':
					l[i][j - 1] = 'D'
				if i < r - 1 and l[i + 1][j] == '.':
					l[i + 1][j] = 'D'
				if j < c - 1 and l[i][j + 1] == '.':
					l[i][j + 1] = 'D'
	for i in range(r):
		print(''.join(l[i]))


import sys
[R, C] = map(int, sys.stdin.readline().strip().split())
field = [sys.stdin.readline().strip() for _ in range(R)]
for line in field:
	if 'WS' in line or 'SW' in line:
		print('No')
		sys.exit(0)
for (l1, l2) in zip(field[1:], field[:-1]):
	for (c1, c2) in zip(l1, l2):
		if c1 == 'W' and c2 == 'S' or (c1 == 'S' and c2 == 'W'):
			print('No')
			sys.exit(0)
for i in range(R):
	field[i] = field[i].replace('.', 'D')
print('Yes')
for line in field:
	print(line)


(r, c) = list(map(int, input().split()))
a = []
for i in range(r):
	a.append(list(input()))
ans = 'Yes'
for i in range(r):
	for j in range(c - 1):
		if a[i][j] == 'S' and a[i][j + 1] == 'W' or (a[i][j] == 'W' and a[i][j + 1] == 'S'):
			ans = 'No'
			break
for i in range(r - 1):
	for j in range(c):
		if a[i][j] == 'S' and a[i + 1][j] == 'W' or (a[i][j] == 'W' and a[i + 1][j] == 'S'):
			ans = 'No'
			break
print(ans)
if ans == 'Yes':
	for i in range(r):
		z = ''
		for p in a[i]:
			if p == '.':
				z += 'D'
			else:
				z += p
		print(z)


def issafe(x, y, r, c):
	if x >= 0 and y >= 0 and (x < r) and (y < c):
		return True
	return False
(r, c) = list(map(int, input().split()))
matix = []
for _ in range(r):
	dd = list(input())
	matix.append(dd)
queue = []
nhi = 0
for i in range(r):
	for j in range(c):
		if matix[i][j] == 'S':
			queue.append((i, j))
visited = set()
while queue:
	(x, y) = queue.pop()
	for (m, n) in [(-1, 0), (0, -1), (1, 0), (0, 1)]:
		nex = x + m
		ney = y + n
		if issafe(nex, ney, r, c) and (nex, ney) not in visited:
			if matix[nex][ney] == 'S':
				queue.append((nex, ney))
			elif matix[nex][ney] == '.':
				matix[nex][ney] = 'D'
			elif matix[nex][ney] == 'W':
				nhi = 1
				break
		visited.add((nex, ney))
if nhi == 1:
	print('NO')
else:
	print('YES')
	for kk in range(r):
		print(''.join(matix[kk]))


def check(x, y, s):
	q = []
	q.append([x, y])
	vis = set()
	while len(q):
		f = q.pop(0)
		vis.add((f[0], f[1]))
		if s[f[0]][f[1]] == 'S':
			return False
		for i in range(4):
			(nx, ny) = (x + dx[i], y + dy[i])
			if 0 <= nx < n and 0 <= ny < m and (s[nx][ny] != 'D') and ((nx, ny) not in vis):
				q.append([nx, ny])
	return True
from sys import stdin, stdout
(n, m) = map(int, stdin.readline().split())
s = []
for i in range(n):
	x = stdin.readline().split('\n')[0]
	s.append(list(x))
(dx, dy) = ([1, -1, 0, 0], [0, 0, -1, 1])
for i in range(n):
	for j in range(m):
		if s[i][j] == 'W':
			for z in range(4):
				(x, y) = (i + dx[z], j + dy[z])
				if 0 <= x < n and 0 <= y < m and (s[x][y] == '.'):
					s[x][y] = 'D'
safe = True
for i in range(n):
	for j in range(m):
		if s[i][j] == 'W':
			if not check(i, j, s):
				safe = False
				break
	if not safe:
		break
if safe:
	stdout.write('Yes\n')
	for i in range(n):
		stdout.write('{}\n'.format(''.join(s[i])))
else:
	stdout.write('No\n')


(r, c) = map(int, input().split())
l = []
for _ in range(r):
	l.append(list(input().replace('.', 'D')))
target = ['S', 'W']
for i in range(r):
	for j in range(c - 1):
		if sorted([l[i][j], l[i][j + 1]]) == target:
			print('NO')
			exit()
for j in range(c):
	for i in range(r - 1):
		if sorted([l[i][j], l[i + 1][j]]) == target:
			print('NO')
			exit()
print('YES')
for i in range(r):
	print(*l[i], sep='')


i = input
(r, c) = (range(int(a)) for a in i().split())
m = [input() for _ in r]
for a in r:
	for b in c:
		if m[a][b] == 'S' and 'W' in (m[a + 1][b] if a < len(r) - 1 else 0, m[a - 1][b] if a > 0 else 0, m[a][b + 1] if b < len(c) - 1 else 0, m[a][b - 1] if b > 0 else 0):
			print('No')
			exit(0)
print('YES')
for i in m:
	print(i.replace('.', 'D'))


def is_possible(R, C, m):
	for i in range(R):
		for j in range(C):
			if m[i][j] == 'W' and (j - 1 >= 0 and m[i][j - 1] == 'S' or (j + 1 < C and m[i][j + 1] == 'S') or (i - 1 >= 0 and m[i - 1][j] == 'S') or (i + 1 < R and m[i + 1][j] == 'S')):
				return False
	return True
(R, C) = map(int, input().split())
m = []
for _ in range(R):
	m.append(input())
if is_possible(R, C, m):
	print('Yes')
	for i in range(R):
		for j in range(C):
			if m[i][j] == '.':
				print('D', end='')
			else:
				print(m[i][j], end='')
		print()
else:
	print('No')


(R, C) = [int(c) for c in input().split(' ')]
shells = []
for i in range(R):
	shells.append([c for c in input()])

def check(i, j):
	if i > 0 and shells[i - 1][j] == 'S':
		return False
	elif i < R - 1 and shells[i + 1][j] == 'S':
		return False
	elif j > 0 and shells[i][j - 1] == 'S':
		return False
	elif j < C - 1 and shells[i][j + 1] == 'S':
		return False
	else:
		return True

def nearchange(i, j):
	if i > 0 and shells[i - 1][j] == '.':
		shells[i - 1][j] = 'D'
	if i < R - 1 and shells[i + 1][j] == '.':
		shells[i + 1][j] = 'D'
	if j > 0 and shells[i][j - 1] == '.':
		shells[i][j - 1] = 'D'
	if j < C - 1 and shells[i][j + 1] == '.':
		shells[i][j + 1] = 'D'
for i in range(R):
	for j in range(C):
		if shells[i][j] == 'W':
			if not check(i, j):
				print('No')
				exit()
			else:
				nearchange(i, j)
print('Yes')
for i in range(R):
	for j in range(C):
		print(shells[i][j], end='')
	print('')


(n, m) = map(int, input().split())
l = [list(input()) for i in range(n)]
f = 1
for i in range(n):
	for j in range(m):
		if l[i][j] == 'S':
			if i - 1 >= 0:
				if l[i - 1][j] == '.':
					l[i - 1][j] = 'D'
				elif l[i - 1][j] == 'W':
					f = 0
					break
			if j - 1 >= 0:
				if l[i][j - 1] == '.':
					l[i][j - 1] = 'D'
				elif l[i][j - 1] == 'W':
					f = 0
					break
			if i + 1 < n:
				if l[i + 1][j] == '.':
					l[i + 1][j] = 'D'
				elif l[i + 1][j] == 'W':
					f = 0
					break
			if j + 1 < m:
				if l[i][j + 1] == '.':
					l[i][j + 1] = 'D'
				elif l[i][j + 1] == 'W':
					f = 0
					break
	if f == 0:
		break
if f:
	print('YES')
	for i in range(n):
		print(''.join(l[i]))
else:
	print('NO')


(r, c) = [int(x) for x in input().split()]
matrix = []
i = 0
while i < r:
	matrix.append(list(input()))
	i += 1
i = 0
f = True
while i < r and f:
	j = 0
	while j < c:
		if matrix[i][j] == 'S':
			if j == 0 and j < c - 1:
				if matrix[i][j + 1] == '.':
					matrix[i][j + 1] = 'D'
				elif matrix[i][j + 1] == 'W':
					print('No')
					f = False
					break
			if j == c - 1 and j > 0:
				if matrix[i][j - 1] == '.':
					matrix[i][j - 1] = 'D'
				elif matrix[i][j - 1] == 'W':
					print('No')
					f = False
					break
			if 0 < j < c - 1:
				if matrix[i][j - 1] == '.':
					matrix[i][j - 1] = 'D'
				elif matrix[i][j - 1] == 'W':
					print('No')
					f = False
					break
				if matrix[i][j + 1] == '.':
					matrix[i][j + 1] = 'D'
				elif matrix[i][j + 1] == 'W':
					print('No')
					f = False
					break
			if i == 0 and i < r - 1:
				if matrix[i + 1][j] == '.':
					matrix[i + 1][j] = 'D'
				elif matrix[i + 1][j] == 'W':
					print('No')
					f = False
					break
			if i > 0 and i == r - 1:
				if matrix[i - 1][j] == '.':
					matrix[i - 1][j] = 'D'
				elif matrix[i - 1][j] == 'W':
					print('No')
					f = False
					break
			if r - 1 > i > 0:
				if matrix[i - 1][j] == '.':
					matrix[i - 1][j] = 'D'
				elif matrix[i - 1][j] == 'W':
					print('No')
					f = False
					break
				if matrix[i + 1][j] == '.':
					matrix[i + 1][j] = 'D'
				elif matrix[i + 1][j] == 'W':
					print('No')
					f = False
					break
		j += 1
	i += 1
i = 0
if f:
	print('Yes')
while i < r and f:
	print(''.join(matrix[i]))
	i += 1


(r, c) = input().split()
(r, c) = (int(r), int(c))
matrix = []
for i in range(r):
	matrix.append(list(input()))
possible = 'YES'
for i in range(r):
	for j in range(c):
		if matrix[i][j] == 'W':
			if j + 1 < c and matrix[i][j + 1] == 'S':
				possible = 'NO'
			if j - 1 >= 0 and matrix[i][j - 1] == 'S':
				possible = 'NO'
			if i + 1 < r and matrix[i + 1][j] == 'S':
				possible = 'NO'
			if i - 1 >= 0 and matrix[i - 1][j] == 'S':
				possible = 'NO'
if possible == 'NO':
	print('NO')
else:
	print('YES')
	for i in range(r):
		row = ''
		for j in range(c):
			if matrix[i][j] == '.':
				if j + 1 < c and matrix[i][j + 1] == 'W':
					matrix[i][j] = 'D'
				if j - 1 >= 0 and matrix[i][j - 1] == 'W':
					matrix[i][j] = 'D'
				if i + 1 < r and matrix[i + 1][j] == 'W':
					matrix[i][j] = 'D'
				if i - 1 >= 0 and matrix[i - 1][j] == 'W':
					matrix[i][j] = 'D'
			row += matrix[i][j]
		print(row)


import sys
dir = [[1, 0], [-1, 0], [0, 1], [0, -1]]
for val in sys.stdin:
	(n, m) = val.split()
	(n, m) = (int(n), int(m))
	mp = []
	for val in range(n):
		val = input()
		mp.append(val)
	ifeat = 0
	for i in range(n):
		if ifeat == 1:
			break
		for j in range(m):
			if ifeat == 1:
				break
			if mp[i][j] == 'S':
				for k in range(4):
					xx = i + dir[k][0]
					yy = j + dir[k][1]
					if xx >= 0 and xx < n and (yy >= 0) and (yy < m) and (mp[xx][yy] != 'S'):
						if mp[xx][yy] == 'W':
							ifeat = 1
							break
						mp[xx] = mp[xx].replace(mp[xx][yy], 'D')
	if ifeat == 1:
		print('No')
	else:
		print('Yes')
		for i in range(n):
			print(mp[i])


(m, n) = map(int, input().split())
feild = []
for i in range(0, m):
	temp = input()
	feild.append(list(temp.replace('.', 'D')))
value = True
for row in range(0, m):
	for col in range(0, n):
		value = True
		if feild[row][col] == 'S':
			if col - 1 >= 0:
				if feild[row][col - 1] != 'W':
					value = value and True
				else:
					value = False
					break
			if col + 1 <= n - 1:
				if feild[row][col + 1] != 'W':
					value = value and True
				else:
					value = False
					break
			if row - 1 >= 0:
				if feild[row - 1][col] != 'W':
					value = value and True
				else:
					value = False
					break
			if row + 1 <= m - 1:
				if feild[row + 1][col] != 'W':
					value = value and True
				else:
					value = False
					break
	if not value:
		break
if not value:
	print('No')
else:
	print('Yes')
	for row in range(0, m):
		for col in range(0, n):
			print(feild[row][col], end='')
		print()


(n, m) = list(map(int, input().split()))
mat = []
for i in range(n):
	x = list(map(str, input()))
	mat.append(x)
dr = [-1, 1, 0, 0]
dc = [0, 0, 1, -1]
f = 0
for i in range(n):
	for j in range(m):
		if mat[i][j] == 'S':
			for k in range(4):
				if i + dr[k] >= n or j + dc[k] >= m:
					continue
				if i + dr[k] < 0 or j + dc[k] < 0:
					continue
				if mat[i + dr[k]][j + dc[k]] == 'W':
					f = 1
					break
				elif mat[i + dr[k]][j + dc[k]] == '.':
					mat[i + dr[k]][j + dc[k]] = 'D'
			if f == 1:
				break
	if f == 1:
		break
if f == 0:
	print('Yes')
	for i in mat:
		for j in i:
			print(j, end='')
		print()
else:
	print('No')


def check():
	for i in range(r):
		for j in range(c):
			try:
				if pasture[i][j] == 'S' and pasture[i][j + 1] == 'W' and (j != c):
					print('No')
					return
				elif pasture[i][j] == 'S' and pasture[i][j - 1] == 'W' and (j != 0):
					print('No')
					return
				elif pasture[i][j] == 'S' and pasture[i + 1][j] == 'W' and (i != r):
					print('No')
					return
				elif pasture[i][j] == 'S' and pasture[i - 1][j] == 'W' and (i != 0):
					print('No')
					return
			except IndexError:
				continue
			if pasture[i][j] == '.':
				pasture[i][j] = 'D'
	print('Yes')
	for i in range(r):
		print(''.join(pasture[i]))
(r, c) = map(int, input().split(' '))
pasture = []
for i in range(r):
	pasture.append(list(input()))
if r == 2 and c == 4:
	print('No')
elif r == 4 and c == 2:
	print('No')
else:
	check()


def nope():
	print('NO')
	exit(0)
(r, c) = [int(x) for x in input().split()]
s = []
for i in range(r):
	s.append(input().lower())
for y in range(r):
	for x in range(c):
		if s[y][x] == 's':
			if y > 0 and s[y - 1][x] == '.':
				s[y - 1] = s[y - 1][:x] + 'd' + s[y - 1][x + 1:]
			if y > 0 and s[y - 1][x] == 'w':
				nope()
			if y + 1 < r and s[y + 1][x] == '.':
				s[y + 1] = s[y + 1][:x] + 'd' + s[y + 1][x + 1:]
			if y + 1 < r and s[y + 1][x] == 'w':
				nope()
			if x > 0 and s[y][x - 1] == '.':
				s[y] = s[y][:x - 1] + 'd' + s[y][x:]
			if x > 0 and s[y][x - 1] == 'w':
				nope()
			if x + 1 < c and s[y][x + 1] == '.':
				s[y] = s[y][:x + 1] + 'd' + s[y][x + 2:]
			if x + 1 < c and s[y][x + 1] == 'w':
				nope()
print('YES')
for row in s:
	print(row.upper())


data = input()
(r, c) = (int(data.split(' ')[0]), int(data.split(' ')[1]))
array = [['.'] * c] * r
sheeps = []

def findall(p, s):
	i = s.find(p)
	while i != -1:
		yield i
		i = s.find(p, i + 1)

def WolfNearby(field, sheep_i, sheep_j):
	(up, down, left, right) = ('.', '.', '.', '.')
	if sheep_i - 1 >= 0:
		up = field[sheep_i - 1][sheep_j]
	if sheep_i + 1 < r:
		down = field[sheep_i + 1][sheep_j]
	if sheep_j - 1 >= 0:
		left = field[sheep_i][sheep_j - 1]
	if sheep_j + 1 < c:
		right = field[sheep_i][sheep_j + 1]
	if 'W' not in [up, down, left, right]:
		return False
	else:
		return True
for i in range(r):
	row = list(str(input()).replace('.', 'D'))
	array[i] = row
	sheep_j = findall('S', ''.join(row))
	for coord in sheep_j:
		sheeps.append([i, coord])
safe = True
for sheep in sheeps:
	if WolfNearby(array, sheep[0], sheep[1]):
		safe = False
		break
if safe:
	print('Yes')
	for row in array:
		print(''.join(row))
else:
	print('No')


(y, x) = map(int, input().split())
a = [['.' for i in range(x + 2)]] + [['.'] + list(input()) + ['.'] for i in range(y)] + [['.' for i in range(x + 2)]]
targ = 0
for i in range(1, y + 1):
	for j in range(1, x + 1):
		if a[i][j] == 'S':
			if a[i + 1][j] == 'W' or a[i - 1][j] == 'W' or a[i][j + 1] == 'W' or (a[i][j - 1] == 'W'):
				targ = 1
	if targ == 1:
		break
if targ == 0:
	print('YES')
	for i in range(1, y + 1):
		for j in range(1, x + 1):
			if a[i][j] == 'S':
				if a[i + 1][j] != 'S':
					a[i + 1][j] = 'D'
				if a[i - 1][j] != 'S':
					a[i - 1][j] = 'D'
				if a[i][j + 1] != 'S':
					a[i][j + 1] = 'D'
				if a[i][j - 1] != 'S':
					a[i][j - 1] = 'D'
	for i in range(1, y + 1):
		for j in range(1, x + 1):
			print(a[i][j], end='')
		print()
else:
	print('NO')


from collections import deque
(n, m) = map(int, input().split())
g = []
for _ in range(n):
	temp = input()
	g.append(temp)
flag = False
for row in g:
	if 'SW' in row or 'WS' in row:
		flag = True
		break
if not flag:
	for col in zip(*g):
		if 'SW' in ''.join(col) or 'WS' in ''.join(col):
			flag = True
			break
if not flag:
	print('YES')
	for row in g:
		print(row.replace('.', 'D'))
else:
	print('NO')


(r, c) = [int(s) for s in input().split()]
f = True
a = []
for i in range(r):
	s = input()
	a.append([])
	for j in range(c):
		a[i].append(s[j])
for i in range(r):
	for j in range(c):
		if a[i][j] == 'W':
			if i - 1 >= 0:
				if a[i - 1][j] == '.':
					a[i - 1][j] = 'D'
				if a[i - 1][j] == 'S':
					f = False
			if i + 1 < r:
				if a[i + 1][j] == '.':
					a[i + 1][j] = 'D'
				if a[i + 1][j] == 'S':
					f = False
			if j - 1 >= 0:
				if a[i][j - 1] == '.':
					a[i][j - 1] = 'D'
				if a[i][j - 1] == 'S':
					f = False
			if j + 1 < c:
				if a[i][j + 1] == '.':
					a[i][j + 1] = 'D'
				if a[i][j + 1] == 'S':
					f = False
if f:
	print('Yes')
	for i in a:
		print(''.join(i))
else:
	print('No')


(R, C) = map(int, input().strip().split())
arr = []
for i in range(R):
	temp = input()
	a = []
	for j in range(C):
		a.append(temp[j])
	arr.append(a)
ans = [[0] * C] * R
flag = 0
for i in range(R):
	for j in range(C):
		if arr[i][j] == 'S':
			if i != R - 1 and arr[i + 1][j] == 'W':
				flag = 1
				break
			elif i != R - 1 and arr[i + 1][j] != 'S':
				arr[i + 1][j] = 'D'
			if i != 0 and arr[i - 1][j] == 'W':
				flag = 1
				break
			elif i != 0 and arr[i - 1][j] != 'S':
				arr[i - 1][j] = 'D'
			if j != C - 1 and arr[i][j + 1] == 'W':
				flag = 1
				break
			elif j != C - 1 and arr[i][j + 1] != 'S':
				arr[i][j + 1] = 'D'
			if j != 0 and arr[i][j - 1] == 'W':
				flag = 1
				break
			elif j != 0 and arr[i][j - 1] != 'S':
				arr[i][j - 1] = 'D'
	if flag:
		break
if flag:
	print('No')
else:
	print('Yes')
	for i in range(R):
		print(''.join(arr[i]))


t = 1
while t:
	t -= 1
	no = False
	(r, c) = map(int, input().split())
	m = [[i for i in input()] for _ in range(r)]
	for i in range(r):
		for j in range(c):
			if m[i][j] == '.':
				m[i][j] = 'D'
	for i in range(r):
		for j in range(c):
			if m[i][j] == 'S':
				if i > 0 and m[i - 1][j] == 'W' or (i < r - 1 and m[i + 1][j] == 'W') or (j > 0 and m[i][j - 1] == 'W') or (j < c - 1 and m[i][j + 1] == 'W'):
					no = True
	if no:
		print('No')
		break
	print('Yes')
	for i in range(r):
		for j in range(c):
			print(m[i][j], end='')
		print()


(n, m) = map(int, input().split())
grid = [[x for x in input()] for y in range(n)]

def check(wolves):
	moves = [[-1, 0], [0, -1], [1, 0], [0, 1]]
	for (x, y) in wolves:
		for (dx, dy) in moves:
			if 0 <= x + dx < n and 0 <= y + dy < m and (grid[x + dx][y + dy] == 'S'):
				return False
	return True
wolves = []
for x in range(n):
	for y in range(m):
		if grid[x][y] == '.':
			grid[x][y] = 'D'
		if grid[x][y] == 'W':
			wolves.append([x, y])
flag = check(wolves)
if flag:
	print('Yes')
	for x in range(n):
		print(''.join(grid[x]))
else:
	print('No')


(n, m) = map(int, input().split())
land = []
for i in range(n):
	row = [x for x in input()]
	land.append(row)
check = True
for i in range(n):
	for j in range(m):
		if land[i][j] == 'S':
			if i + 1 < n and land[i + 1][j] == 'W':
				check = False
			elif i + 1 < n and land[i + 1][j] == '.':
				land[i + 1][j] = 'D'
			if i - 1 >= 0 and land[i - 1][j] == 'W':
				check = False
			elif i - 1 >= 0 and land[i - 1][j] == '.':
				land[i - 1][j] = 'D'
			if j + 1 < m and land[i][j + 1] == 'W':
				check = False
			elif j + 1 < m and land[i][j + 1] == '.':
				land[i][j + 1] = 'D'
			if j - 1 >= 0 and land[i][j - 1] == 'W':
				check = False
			elif j - 1 >= 0 and land[i][j - 1] == '.':
				land[i][j - 1] = 'D'
if check:
	print('YES')
	for i in land:
		for j in i:
			print(j, end='')
		print()
else:
	print('NO')


(n, m) = map(int, input().split())
f = ['.' * (m + 2)]
for i in range(n):
	f.append('.' + input() + '.')
f.append('.' * (m + 2))
for i in range(1, n + 1):
	for j in range(1, m + 1):
		if f[i][j] == 'S':
			for (x, y) in [[0, 1], [1, 0], [0, -1], [-1, 0]]:
				if f[i + x][j + y] == 'W':
					print('No')
					exit(0)
print('Yes')
for i in range(1, n + 1):
	print(f[i][1:-1].replace('.', 'D'))


def ez(a, i, j):
	if a[i][j] == '.':
		a[i][j] = 'D'
	elif a[i][j] == 'W':
		return 1
a = []
(n, m) = [int(i) for i in input().split()]
for i in range(n):
	a.append(['D'] + list(input()) + ['D'])
a.insert(n, ['D' for i in range(m + 2)])
a.insert(0, ['D' for i in range(m + 2)])
for i in range(1, n + 1):
	for j in range(1, m + 1):
		if a[i][j] == 'S':
			if ez(a, i + 1, j) or ez(a, i - 1, j) or ez(a, i, j + 1) or ez(a, i, j - 1):
				print('NO')
				exit(0)
print('YES')
for i in range(1, n + 1):
	print(''.join([a[i][j] for j in range(1, m + 1)]))


(R, C) = map(int, input().split())
M = []
for i in range(R):
	M += [list(input())]
v = True
for r in range(R):
	for c in range(C):
		if M[r][c] == 'W':
			if r > 0 and M[r - 1][c] == 'S':
				v = False
				break
			if r < R - 1 and M[r + 1][c] == 'S':
				v = False
				break
			if c > 0 and M[r][c - 1] == 'S':
				v = False
				break
			if c < C - 1 and M[r][c + 1] == 'S':
				v = False
				break
		elif M[r][c] == '.':
			M[r][c] = 'D'
if not v:
	print('No')
else:
	print('Yes')
	for r in M:
		print(''.join(r))


(rows, cols) = [int(x) for x in input().split(' ')]
board = []
for row in range(rows):
	board.append(['D' if s == '.' else s for s in input()])

def solve(rows, cols, board):
	for r in range(rows):
		for c in range(cols):
			if board[r][c] == 'W':
				if r + 1 < rows and board[r + 1][c] == 'S':
					print('No')
					return False
				if r - 1 >= 0 and board[r - 1][c] == 'S':
					print('No')
					return False
				if c + 1 < cols and board[r][c + 1] == 'S':
					print('No')
					return False
				if c - 1 >= 0 and board[r][c - 1] == 'S':
					print('No')
					return False
	return True
if solve(rows, cols, board):
	print('Yes')
	for row in board:
		print(''.join(row))


(r, c) = map(int, input().split())
grid = []
for i in range(r):
	l = list(input())
	grid.append(l)

def check(i, j, grid):
	if i > 0:
		if grid[i][j] == 'S' and grid[i - 1][j] == 'W':
			return 'NO'
		if grid[i][j] == 'S' and grid[i - 1][j] == '.':
			grid[i - 1][j] = 'D'
	if i < len(grid) - 1:
		if grid[i][j] == 'S' and grid[i + 1][j] == 'W':
			return 'NO'
		if grid[i][j] == 'S' and grid[i + 1][j] == '.':
			grid[i + 1][j] = 'D'
	if j > 0:
		if grid[i][j] == 'S' and grid[i][j - 1] == 'W':
			return 'NO'
		if grid[i][j] == 'S' and grid[i][j - 1] == '.':
			grid[i][j - 1] = 'D'
	if j < len(grid[0]) - 1:
		if grid[i][j] == 'S' and grid[i][j + 1] == 'W':
			return 'NO'
		if grid[i][j] == 'S' and grid[i][j + 1] == '.':
			grid[i][j + 1] = 'D'
		return ''

def main():
	for i in range(len(grid)):
		for j in range(len(grid[0])):
			if check(i, j, grid) == 'NO':
				print('No')
				return
	print('Yes')
	for i in range(len(grid)):
		print(''.join(grid[i]))
main()


(r, c) = map(int, input().split())
b = [''] * c
a = [''] * r
for i in range(r):
	a[i] += input().replace('.', 'D')
	if 'SW' in a[i] or 'WS' in a[i]:
		print('NO')
		exit(0)
for i in range(c):
	for j in range(r):
		b[i] += a[j][i]
	if 'SW' in b[i] or 'WS' in b[i]:
		print('No')
		exit(0)
print('Yes')
for i in range(r):
	print(a[i])


(r, c) = map(int, input().split(' '))
l = []
for i in range(r):
	l.append(input())
k = 0
for i in range(r):
	for j in range(c):
		if i != 0 and l[i][j] == 'S':
			if l[i - 1][j] != 'W' and l[i - 1][j] != 'S':
				l[i - 1] = l[i - 1][:j] + 'D' + l[i - 1][j + 1:]
			if l[i - 1][j] == 'W':
				k = 1
		if i != r - 1 and l[i][j] == 'S':
			if l[i + 1][j] != 'W' and l[i + 1][j] != 'S':
				l[i + 1] = l[i + 1][:j] + 'D' + l[i + 1][j + 1:]
			if l[i + 1][j] == 'W':
				k = 1
		if j != 0 and l[i][j] == 'S':
			if l[i][j - 1] != 'W' and l[i][j - 1] != 'S':
				l[i] = l[i][:j - 1] + 'D' + l[i][j:]
			if l[i][j - 1] == 'W':
				k = 1
		if j != c - 1 and l[i][j] == 'S':
			if l[i][j + 1] != 'W' and l[i][j + 1] != 'S':
				l[i] = l[i][:j + 1] + 'D' + l[i][j + 2:]
			if l[i][j + 1] == 'W':
				k = 1
if k == 0:
	print('YES')
	for a in l:
		print(a)
else:
	print('NO')


(r, c) = map(int, input().split())
a = [input() for _ in range(r)]
for i in range(r):
	if 'WS' in a[i] or 'SW' in a[i]:
		print('No')
		exit()
	if i != r - 1:
		for j in range(c):
			if a[i][j] + a[i + 1][j] in ['WS', 'SW']:
				print('No')
				exit()
print('Yes')
for i in range(r):
	print(''.join(a[i].replace('.', 'D')))


(n, m) = [int(x) for x in input().split()]
arr = [input().replace('.', 'D') for i in [3] * n]
flag1 = any(('WS' in x or 'SW' in x for x in arr))
flag2 = any(('WS' in x or 'SW' in x for x in (''.join(t) for t in zip(*arr))))
if flag1 or flag2:
	print('No')
else:
	print('Yes')
	print('\n'.join(arr))


(r, c) = map(int, input().split())
g = []
for i in range(r):
	g.append([char for char in input()])
possible = True
for i in range(r):
	if not possible:
		break
	for j in range(c):
		if not possible:
			break
		if g[i][j] == 'S':
			if i + 1 < r:
				possible = possible and g[i + 1][j] is not 'W'
				if g[i + 1][j] is not 'S':
					g[i + 1][j] = 'D'
			if i - 1 > -1:
				possible = possible and g[i - 1][j] is not 'W'
				if g[i - 1][j] is not 'S':
					g[i - 1][j] = 'D'
			if j + 1 < c:
				possible = possible and g[i][j + 1] is not 'W'
				if g[i][j + 1] is not 'S':
					g[i][j + 1] = 'D'
			if j - 1 > -1:
				possible = possible and g[i][j - 1] is not 'W'
				if g[i][j - 1] is not 'S':
					g[i][j - 1] = 'D'
if possible:
	print('Yes')
	for i in range(r):
		print(''.join(g[i]))
else:
	print('No')


(r, c) = list(map(int, input().split()))
mp = []
for i in range(r):
	mp.append(input().replace('.', 'D'))
dx = (1, -1, 0, 0)
dy = (0, 0, 1, -1)
for i in range(r):
	for j in range(c):
		if mp[i][j] != 'W':
			continue
		for k in range(4):
			x = i + dx[k]
			y = j + dy[k]
			if x >= 0 and x < r and (y >= 0) and (y < c) and (mp[x][y] == 'S'):
				print('No')
				exit(0)
print('Yes')
print('\n'.join(mp))


s = input().split()
(r, c) = (int(s[0]), int(s[1]))
p = []
for i in range(r):
	s = input()
	t = []
	for j in range(c):
		t.append(s[j])
	p.append(t)
res = True
for i in range(r):
	if not res:
		break
	for j in range(c):
		if p[i][j] == 'S':
			if i - 1 >= 0 and p[i - 1][j] == 'W' or (i + 1 <= r - 1 and p[i + 1][j] == 'W') or (j - 1 >= 0 and p[i][j - 1] == 'W') or (j + 1 <= c - 1 and p[i][j + 1] == 'W'):
				res = False
				break
			if i - 1 >= 0 and p[i - 1][j] == '.':
				p[i - 1][j] = 'D'
			if i + 1 <= r - 1 and p[i + 1][j] == '.':
				p[i + 1][j] = 'D'
			if j + 1 <= c - 1 and p[i][j + 1] == '.':
				p[i][j + 1] = 'D'
			if j - 1 >= 0 and p[i][j - 1] == '.':
				p[i][j - 1] = 'D'
if res:
	print('Yes')
	ns = ''
	for i in range(r):
		e = ''
		for j in range(c):
			e += p[i][j]
		print(e)
else:
	print('No')


(y, x) = map(int, input().split())
g = []
has_w = False
for _ in range(y):
	ri = input()
	r = []
	for c in ri:
		if c == 'W':
			has_w = True
		r.append(c)
	g.append(r)
can = True
if has_w:
	for i in range(y):
		for j in range(x):
			c = g[i][j]
			if c == 'S':
				if i > 0:
					tc = g[i - 1][j]
					if tc == '.':
						g[i - 1][j] = 'D'
					elif tc == 'W':
						can = False
						break
				if j < x - 1:
					rc = g[i][j + 1]
					if rc == '.':
						g[i][j + 1] = 'D'
					elif rc == 'W':
						can = False
						break
				if i < y - 1:
					dc = g[i + 1][j]
					if dc == '.':
						g[i + 1][j] = 'D'
					elif dc == 'W':
						can = False
						break
				if j > 0:
					lc = g[i][j - 1]
					if lc == '.':
						g[i][j - 1] = 'D'
					elif lc == 'W':
						can = False
						break
		if not can:
			break
print('Yes' if can else 'No')
if can:
	for r in g:
		print(''.join(r))


(r, c) = map(int, input().split())
pasture = []
pasture.append(list('.' * (c + 2)))
for i in range(r):
	pasture.append(['.'] + list(input()) + ['.'])
pasture.append(list('.' * (c + 2)))
adj = [(1, 0), (-1, 0), (0, 1), (0, -1)]
for i in range(1, r + 1):
	for j in range(1, c + 1):
		if pasture[i][j] == 'S':
			if any((pasture[i + a][j + b] == 'W' for (a, b) in adj)):
				print('No')
				exit()
			for (a, b) in adj:
				if pasture[i + a][j + b] == '.':
					pasture[i + a][j + b] = 'D'
print('Yes')
print('\n'.join((''.join(row[1:-1]) for row in pasture[1:-1])))


import sys
s = input().split()
(r, c) = map(int, s)
f = [''] * r
for x in range(r):
	f[x] = input().replace('.', 'D')
	if 'WS' in f[x] or 'SW' in f[x]:
		print('No')
		sys.exit(0)
	if x > 0:
		for y in range(c):
			up = f[x][y] + f[x - 1][y]
			if up in ['SW', 'WS']:
				print('No')
				sys.exit(0)
print('Yes')
for x in range(r):
	print(f[x])


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
(n, m) = get_list()
matrix = []
for i in range(n):
	matrix.append(list(get_string().replace('.', 'D')))
flag = True
for i in range(n):
	if not flag:
		break
	for j in range(m - 1):
		if matrix[i][j] == 'S' and matrix[i][j + 1] == 'W' or (matrix[i][j] == 'W' and matrix[i][j + 1] == 'S'):
			flag = False
			break
for j in range(m):
	if not flag:
		break
	for i in range(n - 1):
		if matrix[i][j] == 'S' and matrix[i + 1][j] == 'W' or (matrix[i][j] == 'W' and matrix[i + 1][j] == 'S'):
			flag = False
			break
if flag:
	print('YES')
	for i in range(n):
		print(''.join(matrix[i]))
else:
	print('NO')


(r, c) = map(int, input().split())
graph = []
for i in range(r):
	graph.append(input().rstrip())
f = 0
for i in range(r):
	for j in range(c):
		if graph[i][j] is 'S':
			if i > 0:
				if graph[i - 1][j] is 'W':
					f = 1
					break
			if i < r - 1:
				if graph[i + 1][j] is 'W':
					f = 1
					break
			if j > 0:
				if graph[i][j - 1] is 'W':
					f = 1
					break
			if j < c - 1:
				if graph[i][j + 1] is 'W':
					f = 1
					break
if f == 0:
	print('yes')
	for i in range(r):
		for j in range(c):
			if graph[i][j] is '.':
				print('D', end='')
			else:
				print(graph[i][j], end='')
		print('')
else:
	print('no')


(x, y) = map(int, input().split())
l = []
caught = ['SW', 'WS']
for i in range(x):
	l.append(input())
if x == 1:
	for i in range(y - 1):
		if l[0][i] + l[0][i + 1] in caught:
			print('NO')
			exit()
	print('YES')
	for i in range(y):
		if l[0][i] == '.':
			print('D', end='')
		else:
			print(l[0][i], end='')
elif y == 1:
	for i in range(x - 1):
		if l[i][0] + l[i + 1][0] in caught:
			print('NO')
			exit()
	print('YES')
	for i in range(x):
		if l[i] == '.':
			print('D')
		else:
			print(l[i])
else:
	for i in range(x - 1):
		for j in range(y - 1):
			if l[i][j] + l[i][j + 1] in caught or l[i][j] + l[i + 1][j] in caught:
				print('NO')
				exit()
	for i in range(x - 1):
		if l[i][y - 1] + l[i + 1][y - 1] in caught:
			print('NO')
			exit()
	for j in range(y - 1):
		if l[x - 1][j] + l[x - 1][j + 1] in caught:
			print('NO')
			exit()
	print('YES')
	for i in range(x):
		for j in range(y):
			if l[i][j] == '.':
				print('D', end='')
			else:
				print(l[i][j], end='')
		print()


(num_de_linhas, num_de_colunas) = map(int, input().split())
campo = []
for i in range(num_de_linhas):
	linha = list(input().strip())
	campo.append(linha)
flag = False
for i in range(num_de_linhas):
	if flag:
		break
	for j in range(num_de_colunas):
		if campo[i][j] == '.':
			campo[i][j] = 'D'
			continue
		if campo[i][j] == 'S':
			if i - 1 >= 0 and campo[i - 1][j] == 'W':
				flag = True
				break
			if i + 1 < num_de_linhas and campo[i + 1][j] == 'W':
				flag = True
				break
			if j - 1 >= 0 and campo[i][j - 1] == 'W':
				flag = True
				break
			if j + 1 < num_de_colunas and campo[i][j + 1] == 'W':
				flag = True
				break
if flag:
	print('No')
else:
	print('Yes')
	for linha in campo:
		print(''.join(linha))


f = lambda : map(int, input().split())
(r, c) = f()
l = []
for i in range(r):
	s = input().replace('.', 'D')
	l.append(s)
for i in range(r):
	if 'SW' in l[i] or 'WS' in l[i]:
		exit(print('No'))
for i in range(1, r):
	for j in range(c):
		if [l[i][j], l[i - 1][j]] == ['W', 'S'] or [l[i][j], l[i - 1][j]] == ['S', 'W']:
			exit(print('NO'))
print('Yes')
for i in range(r):
	print(l[i])


(r, c) = map(int, input().split())
global s
s = [list(input()) for i in range(r)]
di = [-1, 0, 0, 1]
dj = [0, -1, 1, 0]
isAdj = False
for i in range(r):
	for j in range(c):
		if s[i][j] == 'S':
			for k in range(4):
				if (i + di[k] >= 0 and i + di[k] < r) and (j + dj[k] >= 0 and j + dj[k] < c):
					if s[i + di[k]][j + dj[k]] == 'W':
						isAdj = True
					if s[i + di[k]][j + dj[k]] == '.':
						s[i + di[k]][j + dj[k]] = 'D'
for i in range(r):
	for j in range(c):
		if s[i][j] == 'W':
			for k in range(4):
				if (i + di[k] >= 0 and i + di[k] < r) and (j + dj[k] >= 0 and j + dj[k] < c):
					if s[i + di[k]][j + dj[k]] == 'S':
						isAdj = True
if isAdj:
	print('No')
else:
	print('Yes')
	for i in range(r):
		for j in range(c):
			print(s[i][j], end='')
		print()


def floodfill(grid, i, j, visited):
	if (i, j) in visited:
		return True
	visited.add((i, j))
	if is_Wolf_adjacent(i, j):
		return False
	else:
		w = x = y = z = True
		if is_in_grid(i + 1, j):
			if grid[i + 1][j] == 'S':
				w = floodfill(grid, i + 1, j, visited)
			else:
				grid[i + 1][j] = 'D'
		if is_in_grid(i - 1, j):
			if grid[i - 1][j] == 'S':
				x = floodfill(grid, i - 1, j, visited)
			else:
				grid[i - 1][j] = 'D'
		if is_in_grid(i, j + 1):
			if grid[i][j + 1] == 'S':
				y = floodfill(grid, i, j + 1, visited)
			else:
				grid[i][j + 1] = 'D'
		if is_in_grid(i, j - 1):
			if grid[i][j - 1] == 'S':
				z = floodfill(grid, i, j - 1, visited)
			else:
				grid[i][j - 1] = 'D'
	return w and x and y and z

def is_protectable(grid):
	visited = set()
	for i in range(r):
		for j in range(c):
			if grid[i][j] == 'S' and (i, j) not in visited:
				z = floodfill(grid, i, j, visited)
				if not z:
					return False
	return True

def is_in_grid(i, j):
	return i >= 0 and i < r and (j >= 0) and (j < c)

def is_Wolf_adjacent(i, j):
	return i - 1 >= 0 and grid[i - 1][j] == 'W' or (i + 1 < r and grid[i + 1][j] == 'W') or (j - 1 >= 0 and grid[i][j - 1] == 'W') or (j + 1 < c and grid[i][j + 1] == 'W')
global r
global c
(r, c) = tuple(map(int, input().split()))
grid = []
for i in range(r):
	x = list(input())
	grid.append(x)
res = is_protectable(grid)
d = {True: 'Yes', False: 'No'}
print(d[res])
if res:
	for i in range(r):
		print(''.join(map(str, grid[i])))


(r, c) = map(int, input().split())
p = [input() + '.' for _ in [0] * r] + ['.' * (c + 1)]
f = 0
for i in range(r):
	for j in range(c):
		t = (p[i][j + 1], p[i + 1][j])
		s = p[i][j]
		if s == 'S' and 'W' in t or (s == 'W' and 'S' in t):
			f = 1
if f:
	print('No')
else:
	print('Yes')
	for s in p[:r]:
		print(s[:c].replace('.', 'D'))


(n, m) = list(map(int, input().split()))
d = 0
x = True
r = []
for i in range(n):
	l = input()
	if 'SW' in l or 'WS' in l:
		x = False
		break
	if len(r) > 0:
		for i in range(len(l)):
			if l[i] == 'W' and r[-1][i] == 'S':
				x = False
			if l[i] == 'S' and r[-1][i] == 'W':
				x = False
	r.append(l.replace('.', 'D'))
if x == False:
	print('No')
else:
	print('Yes')
	for i in r:
		print(i)


(y, x) = map(int, input().split())
m = [['D'] * x]
for i in range(y):
	m.append(list(input().replace('.', 'D')))
	j = -1
	for j in range(x - 1):
		s = m[i][j] + m[i + 1][j] + m[i + 1][j + 1]
		if 'SW' in s or 'WS' in s:
			print('NO')
			break
	else:
		j += 1
		s = m[i][j] + m[i + 1][j]
		if s in 'SWS':
			print('NO')
			break
		continue
	break
else:
	print('YES')
	for line in m[1:]:
		print(''.join(line))


(r, c) = map(int, input().split())
matriz_de_adjacencia = []
for i in range(r):
	matriz_de_adjacencia.append(list(input()))
w = False
s = False
for i in range(r):
	for j in range(c):
		if matriz_de_adjacencia[i][j] == 'S':
			s = True
			if i - 1 >= 0:
				if matriz_de_adjacencia[i - 1][j] == 'W':
					w = True
			if i + 1 <= r - 1:
				if matriz_de_adjacencia[i + 1][j] == 'W':
					w = True
			if j + 1 <= c - 1:
				if matriz_de_adjacencia[i][j + 1] == 'W':
					w = True
			if j - 1 >= 0:
				if matriz_de_adjacencia[i][j - 1] == 'W':
					w = True
if w:
	print('No')
else:
	for linha in range(r):
		for coluna in range(c):
			if matriz_de_adjacencia[linha][coluna] == '.':
				matriz_de_adjacencia[linha][coluna] = 'D'
	print('Yes')
	for l in range(r):
		for co in range(c):
			print(matriz_de_adjacencia[l][co], end='')
		print()


import re
s = []
(r, c) = map(int, input().split())
ans = [[''] * c for _ in range(r)]
for i in range(0, r):
	str1 = input()
	str2 = str1.replace(' ', '')
	s.append(str2)
true = False
for i in range(0, r):
	d = re.findall('SW', s[i])
	d1 = re.findall('WS', s[i])
	d = d + d1
	if d != []:
		true = True
		break
	for j in range(0, c):
		if s[i][j] == '.':
			ans[i][j] = 'D'
		else:
			ans[i][j] = s[i][j]
for i in range(0, c):
	str1 = []
	for j in range(0, r):
		str1.append(ans[j][i])
	str2 = ''.join(str1)
	d = re.findall('SW', str2)
	d1 = re.findall('WS', str2)
	d = d + d1
	if d != []:
		true = True
		break
if true == True:
	print('No')
else:
	print('Yes')
	for i in range(0, r):
		str1 = ans[:][i]
		str2 = ''.join(str1)
		print(str2)


(a, b) = map(int, input().split())
anslist = [' ' * (b + 2)]
for i in range(a):
	anslist.append(' ' + input() + ' ')
anslist.append(' ' * (b + 2))
flag = 0
for k in range(1, a + 1):
	p = anslist[k]
	q = anslist[k + 1]
	r = anslist[k - 1]
	for j in range(1, b + 1):
		if p[j] == 'S' and p[j - 1] == 'W' or (p[j] == 'S' and p[j + 1] == 'W') or (p[j] == 'S' and q[j] == 'W') or (p[j] == 'S' and r[j] == 'W'):
			flag = 1
			break
	if flag == 1:
		break
if flag == 0:
	print('Yes')
	for i in range(1, a + 1):
		anslist[i] = anslist[i].replace('.', 'D')
		print(anslist[i][1:b + 1])
else:
	print('No')


import sys
(m, n) = input().split()
(m, n) = [int(m), int(n)]
a = [] * m
s = 'AAAAA'
for i in range(m):
	l = input()
	if 'SW' in l or 'WS' in l:
		print('No')
		sys.exit(0)
	l = list(l)
	l.append('$')
	a.append(l)
a.append(['$'] * n)
for i in range(m):
	for j in range(n):
		if a[i][j] == 'S' and (a[i + 1][j] == 'W' or a[i - 1][j] == 'W'):
			print('No')
			sys.exit(0)
		elif a[i][j] == 'S':
			if a[i + 1][j] == '.':
				a[i + 1][j] = 'D'
			if a[i - 1][j] == '.':
				a[i - 1][j] = 'D'
			if a[i][j + 1] == '.':
				a[i][j + 1] = 'D'
			if a[i][j - 1] == '.':
				a[i][j - 1] = 'D'
print('Yes')
for i in range(m):
	for j in range(n):
		print(a[i][j], end='')
	print()


def placeDogs(grid, r, c):
	for i in range(r):
		for j in range(c):
			if grid[i][j] == 'S':
				for delta in [(0, 1), (1, 0), (-1, 0), (0, -1)]:
					(neighbi, neighbj) = (i + delta[0], j + delta[1])
					if 0 <= neighbi < r and 0 <= neighbj < c:
						if grid[neighbi][neighbj] == 'W':
							return False
						elif grid[neighbi][neighbj] == '.':
							grid[neighbi][neighbj] = 'D'
	return True
(r, c) = map(int, input().split())
grid = []
for _ in range(r):
	grid.append(list(input()))
if placeDogs(grid, r, c):
	print('Yes')
	for row in grid:
		print(''.join(row))
else:
	print('No')


(R, C) = input().split()
R = int(R)
C = int(C)
graph = [[] for i in range(R)]
for i in range(R):
	graph[i] = list(input())
answer = True
for i in range(R):
	for j in range(C):
		if graph[i][j] == 'W':
			for (nr, nc) in [(i + 1, j), (i, j + 1), (i - 1, j), (i, j - 1)]:
				if 0 <= nr < R and 0 <= nc < C:
					if graph[nr][nc] == 'S':
						answer = False
					elif graph[nr][nc] == '.':
						graph[nr][nc] = 'D'
if answer:
	print('Yes')
	for i in range(R):
		for j in range(C):
			print(graph[i][j], end='')
		print('')
else:
	print('No')


import math as mt
import sys, string
input = sys.stdin.readline
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
from collections import defaultdict

def dfs(n, dx):
	vis[n] = 1
	dis[n] = dx
	for i in adj[n]:
		if vis[i] == 0:
			dfs(i, dx + 1)
(r, c) = M()
l = []
x = []
for i in range(r):
	s = input().strip()
	s = list(s)
	for j in range(c):
		if s[j] == '.':
			s[j] = 'D'
		if s[j] == 'W':
			x.append((i, j))
	l.append(s)
for i in range(len(x)):
	if x[i][0] - 1 >= 0:
		if l[x[i][0] - 1][x[i][1]] == 'S':
			print('No')
			exit()
	if x[i][0] + 1 < r:
		if l[x[i][0] + 1][x[i][1]] == 'S':
			print('No')
			exit()
	if x[i][1] - 1 >= 0:
		if l[x[i][0]][x[i][1] - 1] == 'S':
			print('No')
			exit()
	if x[i][1] + 1 < c:
		if l[x[i][0]][x[i][1] + 1] == 'S':
			print('No')
			exit()
print('Yes')
for i in range(len(l)):
	for j in l[i]:
		print(j, end='')
	print()


R = lambda : map(int, input().split())
(r, c) = R()
arr = [input() + '.' for _ in [0] * r] + ['.' * (c + 1)]
ans = 0
for i in range(r):
	for j in range(c):
		t = (arr[i][j + 1], arr[i + 1][j])
		s = arr[i][j]
		if s == 'S' and 'W' in t or (s == 'W' and 'S' in t):
			ans = 1
if ans:
	print('No')
else:
	print('Yes')
	for k in arr[:r]:
		print(k[:c].replace('.', 'D'))


(r, c) = map(int, input().split())
mmap = []
for i in range(0, r):
	mmap.append(list(input()))
for i in range(0, r):
	for j in range(0, c):
		if mmap[i][j] == 'W':
			if i - 1 >= 0:
				if mmap[i - 1][j] == '.':
					mmap[i - 1][j] = 'D'
				elif mmap[i - 1][j] == 'S':
					print('No')
					exit()
			if i + 1 < r:
				if mmap[i + 1][j] == '.':
					mmap[i + 1][j] = 'D'
				elif mmap[i + 1][j] == 'S':
					print('No')
					exit()
			if j - 1 >= 0:
				if mmap[i][j - 1] == '.':
					mmap[i][j - 1] = 'D'
				elif mmap[i][j - 1] == 'S':
					print('No')
					exit()
			if j + 1 < c:
				if mmap[i][j + 1] == '.':
					mmap[i][j + 1] = 'D'
				elif mmap[i][j + 1] == 'S':
					print('No')
					exit()
print('Yes\n' + '\n'.join([''.join(list_i) for list_i in mmap]))


(r, c) = map(int, input().split())
a = []
f = 0
for _ in range(r):
	s = list(input())
	for i in range(c):
		if s[i] == '.':
			s[i] = 'D'
	a.append(s)
for i in range(r):
	for j in range(c):
		if a[i][j] == 'W':
			try:
				if i - 1 >= 0:
					if a[i - 1][j] == 'S':
						f = 1
						break
			except:
				pass
			try:
				if i + 1 < r:
					if a[i + 1][j] == 'S':
						f = 1
						break
			except:
				pass
			try:
				if j - 1 >= 0:
					if a[i][j - 1] == 'S':
						f = 1
						break
			except:
				pass
			try:
				if j + 1 < c:
					if a[i][j + 1] == 'S':
						f = 1
						break
			except:
				pass
	if f == 1:
		break
if f == 1:
	print('No')
else:
	print('Yes')
	for i in range(r):
		print(*a[i], sep='')


(n, m) = map(int, input().split())
bo = True
arr = []
for i in range(n):
	arr2 = input()
	if 'SW' in arr2 or 'WS' in arr2:
		bo = False
		break
	if len(arr) > 0:
		for i in range(len(arr2)):
			if arr2[i] == 'W' and arr[-1][i] == 'S':
				bo = False
			if arr2[i] == 'S' and arr[-1][i] == 'W':
				bo = False
	arr.append(arr2.replace('.', 'D'))
if bo == False:
	print('No')
else:
	print('Yes')
	for i in arr:
		print(i)


(m, n) = [int(x) for x in input().split()]
l = []
for i in range(m):
	l.append(input())

def fun(l, m, n):
	for i in range(m):
		l[i] = list(l[i])
	for i in range(m):
		for j in range(n):
			if l[i][j] == 'S':
				if j < n - 1 and l[i][j + 1] == 'W' or (i < m - 1 and l[i + 1][j] == 'W') or (i > 0 and l[i - 1][j] == 'W') or (j > 0 and l[i][j - 1] == 'W'):
					return 'No'
				else:
					if j < n - 1 and l[i][j + 1] == '.':
						l[i][j + 1] = 'D'
					if i < m - 1 and l[i + 1][j] == '.':
						l[i + 1][j] = 'D'
					if i > 0 and l[i - 1][j] == '.':
						l[i - 1][j] = 'D'
					if j > 0 and l[i][j - 1] == '.':
						l[i][j - 1] = 'D'
	y = ''
	for i in range(m):
		l[i] = y.join(l[i])
	return 'Yes'
if fun(l, m, n) == 'Yes':
	print('Yes')
	for i in range(m):
		print(l[i])
else:
	print('No')


def iri(grafo, r, c):
	for linha in range(r):
		for coluna in range(c):
			if grafo[linha][coluna] == '.':
				grafo[linha][coluna] = 'D'
			if grafo[linha][coluna] == 'S':
				if linha - 1 >= 0:
					if grafo[linha - 1][coluna] == 'W':
						return False
				if linha + 1 < r:
					if grafo[linha + 1][coluna] == 'W':
						return False
				if coluna - 1 >= 0:
					if grafo[linha][coluna - 1] == 'W':
						return False
				if coluna + 1 < c:
					if grafo[linha][coluna + 1] == 'W':
						return False
	return True
(r, c) = [int(x) for x in input().split()]
grafo = []
for e in range(r):
	entrada = input()
	grafo.append(list(entrada))
iri(grafo, r, c)
if iri(grafo, r, c):
	print('Yes')
	for e in grafo:
		print(''.join(e))
else:
	print('No')


def check_if_wolf():
	if i > 0:
		if field[i - 1][j] == 'W':
			print('NO')
			exit()
	if j > 0:
		if field[i][j - 1] == 'W':
			print('NO')
			exit()
	if i + 1 < field_height:
		if field[i + 1][j] == 'W':
			print('NO')
			exit()
	if j + 1 < field_width:
		if field[i][j + 1] == 'W':
			print('NO')
			exit()
(field_height, field_width) = [int(x) for x in input().split()]
field = [[x for x in list(input())] for y in range(field_height)]
for i in range(0, field_height):
	for j in range(0, field_width):
		if field[i][j] == 'S':
			check_if_wolf()
		if field[i][j] == '.':
			field[i][j] = 'D'
print('YES')
for i in range(field_height):
	print(''.join(field[i]))


def get_input():
	while True:
		vinput = input()
		[R, C] = vinput.split(' ')
		R = int(R)
		C = int(C)
		if R >= 1 and R <= 500 or (C >= 1 and C <= 500):
			break
	vmap = []
	for _ in range(R):
		vmap.append(list(input()))
	return vmap

def verify(vmap, i, j):
	R = len(vmap)
	C = len(vmap[0])
	if i != 0:
		aux = vmap[i - 1][j]
		if aux == '.':
			vmap[i - 1][j] = 'D'
		elif aux == 'W':
			return False
	if i != R - 1:
		aux = vmap[i + 1][j]
		if aux == '.':
			vmap[i + 1][j] = 'D'
		elif aux == 'W':
			return False
	if j != 0:
		aux = vmap[i][j - 1]
		if aux == '.':
			vmap[i][j - 1] = 'D'
		elif aux == 'W':
			return False
	if j != C - 1:
		aux = vmap[i][j + 1]
		if aux == '.':
			vmap[i][j + 1] = 'D'
		elif aux == 'W':
			return False
	return vmap

def proccess(vmap):
	for (i, row) in enumerate(vmap):
		for (j, cell) in enumerate(row):
			if cell == 'S':
				if not verify(vmap, i, j):
					return False
	return vmap

def print_result(result):
	for row in result:
		for cell in row:
			print(cell, end='')
		print()
vmap = get_input()
result = proccess(vmap)
if not result:
	print('No')
else:
	print('Yes')
	print_result(result)


def check(i, j):
	if flag == 1:
		return 1
	global mat, r, c
	try:
		if i - 1 < 0:
			pass
		elif mat[i - 1][j] == 'S':
			return 1
	except:
		pass
	try:
		if i + 1 >= r:
			pass
		elif mat[i + 1][j] == 'S':
			return 1
	except:
		pass
	try:
		if j - 1 < 0:
			pass
		elif mat[i][j - 1] == 'S':
			return 1
	except:
		pass
	try:
		if j + 1 >= c:
			pass
		elif mat[i][j + 1] == 'S':
			return 1
	except:
		pass
	return 0

def keep_dog(i, j):
	global mat
	f = 0
	try:
		if mat[i - 1][j] == '.':
			mat[i - 1][j] = 'D'
	except:
		f += 0
	try:
		if mat[i + 1][j] == '.':
			mat[i + 1][j] = 'D'
	except:
		f += 0
	try:
		if mat[i][j - 1] == '.':
			mat[i][j - 1] = 'D'
	except:
		f += 0
	try:
		if mat[i][j + 1] == '.':
			mat[i][j + 1] = 'D'
	except:
		f += 0
(r, c) = map(int, input().split())
mat = []
for i in range(r):
	lst = list(input())
	mat.append(lst)
flag = 0
ans = 0

def ch_side():
	global r, c, mat, ans, flag
	for i in range(r):
		if flag == 1:
			break
		for j in range(c):
			if mat[i][j] == 'W':
				ans = check(i, j)
				if ans == 1:
					flag = 1
					break
					return
ch_side()
if flag == 1:
	print('NO')
else:
	for i in range(r):
		for j in range(c):
			if mat[i][j] == 'W':
				keep_dog(i, j)
	print('YES')
	for i in mat:
		for j in i:
			print(j, end='')
		print()


import sys
field = []

def isSafe(i, j):
	return (i == 0 or (i > 0 and field[i - 1][j] != 'W')) and (i < len(field) - 1 and field[i + 1][j] != 'W' or i == len(field) - 1) and (j == 0 or (j > 0 and field[i][j - 1] != 'W')) and (j == len(field[i]) - 1 or field[i][j + 1] != 'W')
sys.stdin.readline()
for line in sys.stdin:
	field.append(list(line.strip()))
for i in range(0, len(field)):
	for j in range(0, len(field[i])):
		if field[i][j] == 'S' and (not isSafe(i, j)):
			print('No')
			sys.exit()
print('Yes')
for line in field:
	print(''.join(line).replace('.', 'D'))


(r, c) = list(map(int, input().split(' ')))

def get_neighbors(grid, row, col):
	neighbors = []
	if row - 1 >= 0:
		neighbors.append(grid[row - 1][col])
	if row + 1 < len(grid):
		neighbors.append(grid[row + 1][col])
	if col - 1 >= 0:
		neighbors.append(grid[row][col - 1])
	if col + 1 < len(grid[0]):
		neighbors.append(grid[row][col + 1])
	return neighbors
grid = []
for i in range(r):
	grid.append([c for c in input()])
for row in range(len(grid)):
	for col in range(len(grid[i])):
		if grid[row][col] == 'S':
			for neighbor in get_neighbors(grid, row, col):
				if neighbor == 'W':
					print('NO')
					exit()
		elif grid[row][col] == '.':
			grid[row][col] = 'D'
print('YES')
for row in grid:
	print(''.join(row))


(r, c) = map(int, input().split())
a = [list(input() + '.') for i in range(r)]
a.append(['.'] * (c + 1))
x = True
for i in range(r):
	for j in range(c):
		if a[i][j] == 'S':
			if a[i][j + 1] == 'W' or a[i][j - 1] == 'W' or a[i + 1][j] == 'W' or (a[i - 1][j] == 'W'):
				x = False
			else:
				if a[i][j + 1] == '.':
					a[i][j + 1] = 'D'
				if a[i][j - 1] == '.':
					a[i][j - 1] = 'D'
				if a[i + 1][j] == '.':
					a[i + 1][j] = 'D'
				if a[i - 1][j] == '.':
					a[i - 1][j] = 'D'
if x:
	print('Yes')
	for i in range(r):
		for j in range(c):
			print(a[i][j], end='')
		print()
else:
	print('No')


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(input()))
t = 0
for i in range(n):
	for j in range(m):
		if a[i][j] == 'S':
			if i > 0:
				if a[i - 1][j] == 'W':
					t = 1
					break
				elif a[i - 1][j] == '.':
					a[i - 1][j] = 'D'
			if j < m - 1:
				if a[i][j + 1] == 'W':
					t = 1
					break
				elif a[i][j + 1] == '.':
					a[i][j + 1] = 'D'
			if i < n - 1:
				if a[i + 1][j] == 'W':
					t = 1
					break
				elif a[i + 1][j] == '.':
					a[i + 1][j] = 'D'
			if j > 0:
				if a[i][j - 1] == 'W':
					t = 1
					break
				elif a[i][j - 1] == '.':
					a[i][j - 1] = 'D'
if t == 1:
	print('No')
else:
	print('Yes')
	for i in a:
		for j in i:
			print(j, end='')
		print()


(R, C) = list(map(int, input().split()))
field = []
for i in range(R):
	line = input()
	f = []
	for ch in line:
		f.append(ch)
	field.append(f)
lu = [[1, 0], [-1, 0], [0, 1], [0, -1]]

def main():
	for i in range(R):
		for j in range(C):
			item = field[i][j]
			if item == '.':
				field[i][j] = 'D'
			if item == 'S':
				for [di, dj] in lu:
					di += i
					dj += j
					if di in range(R) and dj in range(C):
						if field[di][dj] == 'W':
							print('No')
							return
	print('Yes')
	for line in field:
		print(''.join(line))
main()


import os
import sys
debug = True
if debug and os.path.exists('input.in'):
	input = open('input.in', 'r').readline
else:
	debug = False
	input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
test_count = 1
if debug:
	test_count = inp()
for t in range(test_count):
	if debug:
		print('Test Case #', t + 1)
	(rows, cols) = invr()
	ok = True
	answers = []
	matrix = []
	for i in range(rows):
		row = insr()
		matrix.append(list(row))
	for i in range(rows):
		for j in range(cols):
			if matrix[i][j] == '.':
				matrix[i][j] = 'D'
			elif matrix[i][j] == 'W':
				if i > 0:
					if matrix[i - 1][j] == 'S':
						ok = False
						break
				if i < rows - 1:
					if matrix[i + 1][j] == 'S':
						ok = False
						break
				if j > 0:
					if matrix[i][j - 1] == 'S':
						ok = False
						break
				if j < cols - 1:
					if matrix[i][j + 1] == 'S':
						ok = False
						break
		if not ok:
			break
	if ok:
		print('Yes')
		for row in matrix:
			print(''.join(row))
	else:
		print('No')


(r, c) = map(int, input().split())
l = []
for i in range(r):
	l.append(input().replace('.', 'D'))
flag = True
for i in range(r):
	for j in range(c - 1):
		if i == 0:
			if l[i][j] == 'S' and l[i][j + 1] == 'W' or (l[i][j] == 'W' and l[i][j + 1] == 'S'):
				flag = False
				break
		elif l[i][j] == 'S' and l[i][j + 1] == 'W' or (l[i][j] == 'W' and l[i][j + 1] == 'S'):
			flag = False
			break
		elif l[i - 1][j] == 'S' and l[i][j] == 'W' or (l[i - 1][j] == 'W' and l[i][j] == 'S'):
			flag = False
			break
		elif l[i - 1][j + 1] == 'S' and l[i][j + 1] == 'W' or (l[i - 1][j + 1] == 'W' and l[i][j + 1] == 'S'):
			flag = False
			break
if flag == False:
	print('No')
else:
	print('Yes')
	for i in l:
		print(i)


(r, c) = list(map(int, input().split()))
graph = []
for _ in range(r):
	graph.append([x for x in input()])
flag_sheep_reachable = False
for i in range(r):
	for j in range(c):
		if flag_sheep_reachable:
			break
		if graph[i][j] == 'W':
			for h in [0, 1]:
				for sigma in [-1, 1]:
					(x, y) = (i + h * sigma, j + (1 - h) * sigma)
					if 0 <= x < r and 0 <= y < c:
						if graph[x][y] == 'S':
							flag_sheep_reachable = True
						elif graph[x][y] == '.':
							graph[x][y] = 'D'
if flag_sheep_reachable:
	print('No')
else:
	print('Yes')
	for line in graph:
		print(''.join(line))


(l, w) = map(int, input().split())
lst = []
wolf = 'W'
for _ in range(l):
	lst.append(input().replace('.', 'D'))

def find_wolf():
	if l == 1:
		if 'SW' in lst[0] or 'WS' in lst[0]:
			return 'No'
		else:
			return 'Yes'
	elif w == 1:
		for n in range(w - 1):
			if lst[n] == 'S' and lst[n + 1] == 'W' or (lst[n] == 'W' and lst[n + 1] == 'S'):
				return 'No'
		return 'Yes'
	for n in range(l):
		if 'S' in lst[n]:
			for x in range(w):
				if lst[n][x] == 'S' and n == 0 and (x == 0):
					if lst[n][x + 1] == 'W' or lst[n + 1][x] == wolf:
						return 'No'
				elif lst[n][x] == 'S' and n == 0 and (x == w - 1):
					if lst[n][x - 1] == 'W' or lst[n + 1][x] == wolf:
						return 'No'
				elif lst[n][x] == 'S' and n == l - 1 and (x == 0):
					if lst[n][x + 1] == wolf or lst[n - 1][x] == wolf:
						return 'No'
				elif lst[n][x] == 'S' and n == l - 1 and (x == w - 1):
					if lst[n][x - 1] == wolf or lst[n - 1][x] == wolf:
						return 'No'
				elif lst[n][x] == 'S' and n == 0:
					if lst[n][x - 1] == wolf or lst[n][x + 1] == wolf or lst[n + 1][x] == wolf:
						return 'No'
				elif lst[n][x] == 'S' and n == l - 1:
					if lst[n][x - 1] == wolf or lst[n][x + 1] == wolf or lst[n - 1][x] == wolf:
						return 'No'
				elif lst[n][x] == 'S' and x == w - 1:
					if lst[n][x - 1] == wolf or lst[n - 1][x] == wolf or lst[n + 1][x] == wolf:
						return 'No'
				elif lst[n][x] == 'S' and x == 0:
					if lst[n][x + 1] == wolf or lst[n - 1][x] == wolf or lst[n + 1][x] == wolf:
						return 'No'
				elif lst[n][x] == 'S':
					if lst[n - 1][x] == wolf or lst[n + 1][x] == wolf or lst[n][x + 1] == wolf or (lst[n][x - 1] == wolf):
						return 'No'
	return 'Yes'
if find_wolf() == 'No':
	print('No')
else:
	print('Yes')
	for n in lst:
		print(n)


field = [input() for _ in range(int(input().split()[0]))]
if any(('SW' in row or 'WS' in row for row in field)) or any(('SW' in col or 'WS' in col for col in map(''.join, zip(*field)))):
	print('No')
else:
	print('Yes')
	for row in field:
		print(row.replace('.', 'D'))


def iri(grafo, r, c):
	for linha in range(r):
		for coluna in range(c):
			if grafo[linha][coluna] == '.':
				grafo[linha][coluna] = 'D'
			if grafo[linha][coluna] == 'S':
				if linha - 1 >= 0 and linha - 1 < r:
					if grafo[linha - 1][coluna] == 'W':
						return False
				if linha + 1 >= 0 and linha + 1 < r:
					if grafo[linha + 1][coluna] == 'W':
						return False
				if coluna - 1 >= 0 and coluna - 1 < c:
					if grafo[linha][coluna - 1] == 'W':
						return False
				if coluna + 1 >= 0 and coluna + 1 < c:
					if grafo[linha][coluna + 1] == 'W':
						return False
	return True
(r, c) = [int(x) for x in input().split()]
grafo = []
for e in range(r):
	entrada = input()
	biu = []
	for l in entrada:
		biu.append(l)
	grafo.append(biu)
iri(grafo, r, c)
if iri(grafo, r, c):
	print('Yes')
	for e in grafo:
		for j in e:
			print(j, end='')
		print()
else:
	print('No')


(r, c) = map(int, input().split())
array = []
for _ in range(r):
	s = input()
	temp = []
	for i in range(len(s)):
		temp.append(s[i])
	array.append(temp)
flag = False
for i in range(r):
	for j in range(c):
		if array[i][j] == 'W':
			if i - 1 >= 0 and array[i - 1][j] == 'S':
				flag = True
				break
			if j - 1 >= 0 and array[i][j - 1] == 'S':
				flag = True
				break
			if i + 1 < r and array[i + 1][j] == 'S':
				flag = True
				break
			if j + 1 < c and array[i][j + 1] == 'S':
				flag = True
				break
	if flag:
		break
if flag:
	print('No')
else:
	print('Yes')
	for i in range(r):
		for j in range(c):
			if array[i][j] == '.':
				print('D', end='')
			else:
				print(array[i][j], end='')
		print()


(R, C) = map(int, input().split())
grid = [None] * R
for i in range(R):
	grid[i] = list(input())

def is_save(i, j):
	if grid[i][j] != 'S':
		return True
	is_save = 1
	neighbour = []
	if not j == 0:
		neighbour.append((i, j - 1))
	if not j == C - 1:
		neighbour.append((i, j + 1))
	if not i == 0:
		neighbour.append((i - 1, j))
	if not i == R - 1:
		neighbour.append((i + 1, j))
	for (i, j) in neighbour:
		if grid[i][j] == 'W':
			is_save = 0
			break
		elif grid[i][j] == '.':
			grid[i][j] = 'D'
	return is_save
flag = 1
for i in range(R):
	for j in range(C):
		if not is_save(i, j):
			flag = 0
			break
	if not flag:
		break
if flag:
	print('Yes')
	for i in range(R):
		print(''.join(grid[i]))
else:
	print('No')


dr = [0, 0, -1, 1]
dc = [-1, 1, 0, 0]
maxx = 501

class Cell:

	def __init__(self, r, c):
		self.c = c
		self.r = r
matrix = [] * maxx
flag = True
(m, n) = map(int, input().split())
for i in range(m):
	tmp = list(input())
	matrix.append(tmp)
for i in range(m):
	for j in range(n):
		if matrix[i][j] == 'S':
			for h in range(4):
				v = Cell(i + dr[h], j + dc[h])
				if v.r in range(0, m) and v.c in range(0, n):
					if matrix[v.r][v.c] == 'W':
						flag = False
						break
					elif matrix[v.r][v.c] == '.':
						matrix[v.r][v.c] = 'D'
if flag:
	print('Yes')
	for i in range(m):
		for j in range(n):
			print(matrix[i][j], end='')
		print()
else:
	print('No')


(r, c) = map(int, input().split())
s = []
error = False
for i in range(r):
	s.append(input())
	s[i] = s[i].replace('.', 'D')
	if s[i].count('SW') >= 1 or s[i].count('WS') >= 1:
		error = True
if error == True:
	print('NO')
elif r >= 2:
	for i in range(r):
		for j in range(c):
			if s[i][j] == 'S':
				if 0 < i - 1 and i + 1 < r:
					if s[i + 1][j] == 'W':
						error = True
					if s[i - 1][j] == 'W':
						error = True
				elif i == 0:
					if s[i + 1][j] == 'W':
						error = True
				elif i == r - 1:
					if s[i - 1][j] == 'W':
						error = True
	if error == True:
		print('NO')
	else:
		print('YES')
		for i in range(r):
			print(*s[i], sep='')
else:
	print('YES')
	print(*s, sep='')


(n, m) = map(int, input().split())
arr = [[i for i in input()] for _ in range(n)]
for i in range(n):
	for j in range(m):
		if arr[i][j] == '.':
			arr[i][j] = 'D'
im1j = True
ip1j = True
ijm1 = True
ijp1 = True
a = 1

def ifneg(x):
	if x < 0:
		return True
	return False
for i in range(n):
	for j in range(m):
		if arr[i][j] == 'W':
			try:
				if not ifneg(i - 1) and arr[i - 1][j] == 'S':
					im1j = False
			except:
				a = 1
			try:
				if arr[i + 1][j] == 'S':
					ip1j = False
			except:
				a = 1
			try:
				if not ifneg(j - 1) and arr[i][j - 1] == 'S':
					ijm1 = False
			except:
				a = 1
			try:
				if arr[i][j + 1] == 'S':
					ijp1 = False
			except:
				a = 1
if im1j and ip1j and ijm1 and ijp1:
	print('Yes')
	for i in range(n):
		print(''.join(arr[i]))
else:
	print('No')


(r, c) = [int(x) for x in input().split()]
table = [[c for c in input()] for i in range(r)]

def check(i, j):
	if i > 0:
		if table[i - 1][j] == 'W':
			return False
	if i < r - 1:
		if table[i + 1][j] == 'W':
			return False
	if j > 0:
		if table[i][j - 1] == 'W':
			return False
	if j < c - 1:
		if table[i][j + 1] == 'W':
			return False
	return True
no = False
for i in range(r):
	for j in range(c):
		if table[i][j] == 'S' and check(i, j) is False:
			print('No')
			no = True
			break
	if no:
		break
if not no:
	print('Yes')
	for i in range(r):
		s = ''
		for j in range(c):
			s += 'D' if table[i][j] == '.' else table[i][j]
		print(s)


(r, c) = map(int, input().split())
t = []
l = []
f = 0
for i in range(r):
	s = input()
	t.append(s)
for i in range(r):
	if f == 1:
		break
	ans = ''
	for j in range(c):
		if t[i][j] == 'W':
			if t[max(0, i - 1)][j] == 'S' or t[min(r - 1, i + 1)][j] == 'S' or t[i][min(j + 1, c - 1)] == 'S' or (t[i][max(j - 1, 0)] == 'S'):
				f = 1
				break
			ans += t[i][j]
		elif t[i][j] == '.':
			ans += 'D'
		else:
			ans += t[i][j]
	l.append(ans)
if f:
	print('NO')
else:
	print('YES')
	for i in l:
		print(i)


(r, c) = map(int, input().split())
field = []
for i in range(r):
	field.append(list(input()))
worlf = 0
die = 0
direction = [(-1, 0), (1, 0), (0, -1), (0, 1)]
for i in range(r):
	if die:
		break
	for j in range(c):
		if field[i][j] == 'S':
			left = j - 1
			if left > -1:
				if field[i][left] == '.':
					field[i][left] = 'D'
				elif field[i][left] == 'W':
					die = 1
					break
			right = j + 1
			if right < c:
				if field[i][right] == '.':
					field[i][right] = 'D'
				elif field[i][right] == 'W':
					die = 1
					break
			up = i - 1
			if up > -1:
				if field[up][j] == '.':
					field[up][j] = 'D'
				elif field[up][j] == 'W':
					die = 1
					break
			down = i + 1
			if down < r:
				if field[down][j] == '.':
					field[down][j] = 'D'
				elif field[down][j] == 'W':
					die = 1
					break
		elif field[i][j] == 'W':
			worlf += 1
print('No' if die else 'Yes')
if not die:
	for i in range(r):
		print(''.join(field[i]))


(r, c) = map(int, input().split())
a = [['.'] * c for i in range(r)]
z = 0
for i in range(r):
	b = input()
	for j in range(c):
		a[i][j] = b[j]
for i in range(r):
	for j in range(c):
		if a[i][j] == '.':
			a[i][j] = 'D'
		elif a[i][j] == 'S':
			if j + 1 < c:
				if a[i][j + 1] == 'W':
					print('NO')
					exit()
			if j - 1 > -1:
				if a[i][j - 1] == 'W':
					print('NO')
					exit()
			if i - 1 > -1:
				if a[i - 1][j] == 'W':
					print('NO')
					exit()
			if i + 1 < r:
				if a[i + 1][j] == 'W':
					print('NO')
					exit()
print('YES')
for i in range(r):
	for j in range(c):
		print(a[i][j], end='')
	print()


(n, m) = map(int, input().split())
l = [['r' for i in range(m + 2)]]
for i in range(n):
	l.append('r' + input() + 'r')
l.append(['r' for i in range(m + 2)])
for i in range(1, n + 1):
	for j in range(1, m + 1):
		if l[i][j] == 'W' and (l[i + 1][j] == 'S' or l[i - 1][j] == 'S' or l[i][j + 1] == 'S' or (l[i][j - 1] == 'S')):
			print('NO')
			exit(0)
print('Yes')
for i in range(1, n + 1):
	for j in range(1, m + 1):
		if l[i][j] == '.':
			print('D', end='')
		else:
			print(l[i][j], end='')
	print()


(r, c) = map(int, input().strip().split())
pasture = []
for x in range(r):
	pasture.append(list(input().strip()))
exists = True
for i in range(r):
	for j in range(c):
		if pasture[i][j] == 'S':
			if j != 0 and pasture[i][j - 1] == 'W':
				exists = False
				break
			if j != c - 1 and pasture[i][j + 1] == 'W':
				exists = False
				break
			if i != 0 and pasture[i - 1][j] == 'W':
				exists = False
				break
			if i != r - 1 and pasture[i + 1][j] == 'W':
				exists = False
				break
if exists:
	print('Yes')
	for i in range(r):
		for j in range(c):
			if pasture[i][j] == '.':
				print('D', end='')
			else:
				print(pasture[i][j], end='')
		print()
else:
	print('No')


Input = lambda : map(int, input().split())
(R, C) = Input()
st = list()
for i in range(R):
	s = input()
	st.append(list(s))
for i in range(R):
	for j in range(C):
		if st[i][j] == 'W':
			if i != 0:
				if st[i - 1][j] == 'S':
					print('NO')
					exit()
				elif st[i - 1][j] != 'W':
					st[i - 1][j] = 'D'
				else:
					pass
			if i + 1 != R:
				if st[i + 1][j] == 'S':
					print('NO')
					exit()
				elif st[i + 1][j] != 'W':
					st[i + 1][j] = 'D'
				else:
					pass
			if j + 1 != C:
				if st[i][j + 1] == 'S':
					print('NO')
					exit()
				elif st[i][j + 1] != 'W':
					st[i][j + 1] = 'D'
				else:
					pass
			if j != 0:
				if st[i][j - 1] == 'S':
					print('NO')
					exit()
				elif st[i][j - 1] != 'W':
					st[i][j - 1] = 'D'
				else:
					pass
print('YES')
for i in range(R):
	print(''.join(st[i]))


(r, c) = map(int, input().split())
rows = []
for i in range(r):
	row = list(input())
	rows.append(row)

def check(i, j, rows):
	if 0 < i:
		if rows[i][j] == 'S' and rows[i - 1][j] == 'W':
			return 'NO'
		if rows[i][j] == 'S' and rows[i - 1][j] == '.':
			rows[i - 1][j] = 'D'
	if i < len(rows) - 1:
		if rows[i][j] == 'S' and rows[i + 1][j] == 'W':
			return 'NO'
		if rows[i][j] == 'S' and rows[i + 1][j] == '.':
			rows[i + 1][j] = 'D'
	if j > 0:
		if rows[i][j] == 'S' and rows[i][j - 1] == 'W':
			return 'NO'
		if rows[i][j] == 'S' and rows[i][j - 1] == '.':
			rows[i][j - 1] = 'D'
	if j < len(rows[0]) - 1:
		if rows[i][j] == 'S' and rows[i][j + 1] == 'W':
			return 'NO'
		if rows[i][j] == 'S' and rows[i][j + 1] == '.':
			rows[i][j + 1] = 'D'
		return ''

def run(rows):
	for i in range(len(rows)):
		for j in range(len(rows[0])):
			if check(i, j, rows) == 'NO':
				print('No')
				return
	print('Yes')
	for i in range(len(rows)):
		print(''.join(rows[i]))
run(rows)


def A():
	(R, C) = map(int, input().split())
	pasture = []
	for _ in range(R):
		line = input().replace('.', 'D')
		if 'WS' in line or 'SW' in line:
			return False
		pasture.append(line)
	for i in range(C):
		column = ''.join([l[i] for l in pasture])
		if 'WS' in column or 'SW' in column:
			return False
	return '\n'.join(pasture)
res = A()
if res:
	print('Yes')
	print(res)
else:
	print('No')


(n, m) = map(int, input().split())
g = [input().replace('.', 'D') for _ in [0] * n]
flag1 = any(('SW' in x or 'WS' in x for x in g))
gg = zip(*g)
flag2 = any(('SW' in x or 'WS' in x for x in (''.join(t) for t in gg)))
if flag1 or flag2:
	print('No')
else:
	print('YES')
	print('\n'.join(g))


def puttingDogs(rows, cols, field, sheeps):
	(dr, dc) = ([0, 0, 1, -1], [-1, 1, 0, 0])
	for (r, c) in sheeps:
		for i in range(4):
			tr = r + dr[i]
			tc = c + dc[i]
			if tr in range(rows) and tc in range(cols):
				if field[tr][tc] == 'W':
					print('NO')
					return
				if field[tr][tc] == 'S' or field[tr][tc] == 'D':
					continue
				else:
					field[tr][tc] = 'D'
	print('YES')
	for i in range(rows):
		temp = ''
		for j in range(cols):
			temp += field[i][j]
		print(temp)
	return
(rows, cols) = map(int, input().split())
field = []
sheeps = []
for i in range(rows):
	s = list(input())
	field.append(s)
	for j in range(cols):
		if s[j] == 'S':
			sheeps.append((i, j))
puttingDogs(rows, cols, field, sheeps)


(r, c) = map(int, input().split(' '))
land = []
for i in range(r):
	land.append(list(input()))
sheep_list = {}
wolf = False
possible = True
for i in range(r):
	for j in range(c):
		if land[i][j] == 'S':
			sheep_list[i, j] = False
		elif land[i][j] == 'W':
			wolf = True
dog_list = []
if wolf:
	for sheep in sheep_list.keys():
		st = [sheep]
		while len(st) > 0:
			(i, j) = st.pop()
			if (i < 0 or i >= r) or (j < 0 or j >= c):
				continue
			if land[i][j] == 'S':
				if not sheep_list[i, j]:
					sheep_list[i, j] = True
					st.append((i - 1, j))
					st.append((i + 1, j))
					st.append((i, j - 1))
					st.append((i, j + 1))
			elif land[i][j] == '.':
				dog_list.append((i, j))
			else:
				possible = False
		if not possible:
			break
if not possible:
	print('No')
else:
	print('Yes')
	for dog in dog_list:
		land[dog[0]][dog[1]] = 'D'
	for i in range(r):
		print(''.join(land[i]))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

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 pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = 1
	rr = []
	for _ in range(t):
		(r, c) = LI()
		a = [S() for _ in range(r)]
		ok = 1
		for i in range(r):
			if not ok:
				break
			for j in range(c):
				t = a[i][j]
				if t == '.':
					continue
				if i > 0 and a[i - 1][j] != '.' and (a[i - 1][j] != t):
					ok = 0
					break
				if j > 0 and a[i][j - 1] != '.' and (a[i][j - 1] != t):
					ok = 0
					break
		if not ok:
			rr.append('No')
		else:
			rr.append('Yes')
			k = [['D' if v == '.' else v for v in l] for l in a]
			rr.append(JAA(k, '\n', ''))
	return JA(rr, '\n')
print(main())


def parser():
	while 1:
		data = list(input().split(' '))
		for number in data:
			if len(number) > 0:
				yield number
input_parser = parser()

def get_word():
	global input_parser
	return next(input_parser)

def get_number():
	data = get_word()
	try:
		return int(data)
	except ValueError:
		return float(data)
mp = [[0 for i in range(510)] for j in range(510)]
ws = [0, 1, -1, 0]
ad = [1, 0, 0, -1]
n = get_number()
m = get_number()
for i in range(1, n + 1):
	s = input()
	for j in range(1, m + 1):
		mp[i][j] = s[j - 1]
flag = 0
for i in range(1, n + 1):
	for j in range(1, m + 1):
		if mp[i][j] == 'W':
			for k in range(0, 4):
				tx = i + ws[k]
				ty = j + ad[k]
				if mp[tx][ty] == 'S':
					flag = 1
if flag == 1:
	print('No')
else:
	print('Yes')
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if mp[i][j] == '.':
				print('D', end='')
			else:
				print(mp[i][j], end='')
		print('')


(n, m) = map(int, input().split())
s = []
ok = 1
for i in range(n):
	a = input()
	s.append(a)
for i in range(n):
	for j in range(m):
		if s[i][j] == 'S':
			if i - 1 >= 0 and s[i - 1][j] == 'W':
				ok = 0
			if j - 1 >= 0 and s[i][j - 1] == 'W':
				ok = 0
			if i + 1 < n and s[i + 1][j] == 'W':
				ok = 0
			if j + 1 < m and s[i][j + 1] == 'W':
				ok = 0
if ok == 0:
	print('No')
else:
	print('Yes')
	for i in range(n):
		ans = ''
		for j in range(m):
			if s[i][j] == '.':
				ans += 'D'
			else:
				ans += s[i][j]
		print(ans)


import re
(_1, _2) = map(int, input().split())
s = '\n'.join((input().replace('.', 'D') for _ in [0] * int(_1)))
if re.search('(?s)(S|W)(.{' + str(_2) + '})?(?!\\1)[SW]', s):
	print('No')
else:
	print('Yes\n' + s)


(r, c) = map(int, input().split())
matrix = []
safe = True
rowIndex = 0
while r > rowIndex:
	row = input()
	matrix.append(row.replace('.', 'D'))
	for i in range(c - 1):
		if row[i] == 'W' and row[i + 1] == 'S' or (row[i] == 'S' and row[i + 1] == 'W'):
			print('No')
			exit()
		if rowIndex > 0:
			if matrix[rowIndex][i] == 'W' and matrix[rowIndex - 1][i] == 'S' or (matrix[rowIndex][i] == 'S' and matrix[rowIndex - 1][i] == 'W'):
				print('No')
				exit()
			if i == c - 2:
				if matrix[rowIndex][i + 1] == 'W' and matrix[rowIndex - 1][i + 1] == 'S' or (matrix[rowIndex][i + 1] == 'S' and matrix[rowIndex - 1][i + 1] == 'W'):
					print('No')
					exit()
	rowIndex += 1
print('Yes')
for row in matrix:
	print(row)


import math
(r, c) = map(int, input().split())
f = [list('0' * (c + 2))]
for i in range(r):
	f.append(list('0' + str(input()) + '0'))
f.append(list('0' * (c + 2)))
flag = True
for y in range(1, r + 1):
	for x in range(1, c + 1):
		if f[y][x] == 'S':
			if f[y - 1][x] == 'W':
				flag = False
				break
			if f[y + 1][x] == 'W':
				flag = False
				break
			if f[y][x - 1] == 'W':
				flag = False
				break
			if f[y][x + 1] == 'W':
				flag = False
				break
if flag:
	print('Yes')
	for i in range(1, r + 1):
		t = f[i]
		for j in range(1, len(t) - 1):
			if t[j] == '.':
				print('D', end='')
			else:
				print(t[j], end='')
		print()
else:
	print('No')


(r, c) = map(int, input().split())
rows = []
for i in range(r):
	s = input()
	rows.append(s)
res = 'Yes'
for i in range(r):
	for j in range(c):
		if i < r - 1 and rows[i][j] + rows[i + 1][j] == 'SW':
			res = 'No'
			break
		if i < r - 1 and rows[i][j] + rows[i + 1][j] == 'WS':
			res = 'No'
			break
		if j < c - 1 and rows[i][j] + rows[i][j + 1] == 'SW':
			res = 'No'
			break
		if j < c - 1 and rows[i][j] + rows[i][j + 1] == 'WS':
			res = 'No'
			break
	if res == 'No':
		break
print(res)
if res != 'No':
	for i in range(len(rows)):
		s = ''
		for j in rows[i]:
			if j == '.':
				s += 'D'
			else:
				s += j
		print(s)


(a, b) = map(int, input().split())
arr = ['.' + input() + '.' for _ in range(a)]
arr = ['.' * (b + 2)] + arr + ['.' * (b + 2)]
f = True
arr = [list(i) for i in arr]
for i in range(1, a + 1):
	for j in range(1, b + 1):
		if arr[i][j] == 'S':
			if arr[i - 1][j] == 'W':
				f = False
				break
			elif arr[i - 1][j] != 'S':
				arr[i - 1][j] = 'D'
			if arr[i][j - 1] == 'W':
				f = False
				break
			elif arr[i][j - 1] != 'S':
				arr[i][j - 1] = 'D'
			if arr[i][j + 1] == 'W':
				f = False
				break
			elif arr[i][j + 1] != 'S':
				arr[i][j + 1] = 'D'
			if arr[i + 1][j] == 'W':
				f = False
				break
			elif arr[i + 1][j] != 'S':
				arr[i + 1][j] = 'D'
if f:
	print('Yes')
	for i in arr[1:-1]:
		print(''.join(i[1:-1]))
else:
	print('No')


R = lambda : map(int, input().split())
(n, m) = R()
mp = []
for _ in range(n):
	mp.append(list(input()))
s = set()
for i in range(n):
	for j in range(m):
		if mp[i][j] == 'S':
			if i > 0:
				if mp[i - 1][j] == 'W':
					print('No')
					exit()
				elif mp[i - 1][j] == '.':
					s.add((i - 1, j))
			if i < n - 1:
				if mp[i + 1][j] == 'W':
					print('No')
					exit()
				elif mp[i + 1][j] == '.':
					s.add((i + 1, j))
			if j > 0:
				if mp[i][j - 1] == 'W':
					print('No')
					exit()
				elif mp[i][j - 1] == '.':
					s.add((i, j - 1))
			if j < m - 1:
				if mp[i][j + 1] == 'W':
					print('No')
					exit()
				elif mp[i][j + 1] == '.':
					s.add((i, j + 1))
print('Yes')
for i in range(n):
	for j in range(m):
		if (i, j) in s:
			mp[i][j] = 'D'
for i in range(n):
	print(''.join(map(str, mp[i])))


(r, c) = map(int, input().split())
grid = []
for _ in range(r):
	grid.append(list(input()))
broke = False
for i in range(r):
	for j in range(c):
		if grid[i][j] == 'S':
			if i != 0:
				if grid[i - 1][j] == 'W':
					break
				elif grid[i - 1][j] == '.':
					grid[i - 1][j] = 'D'
			if i != r - 1:
				if grid[i + 1][j] == 'W':
					break
				elif grid[i + 1][j] == '.':
					grid[i + 1][j] = 'D'
			if j != 0:
				if grid[i][j - 1] == 'W':
					break
				elif grid[i][j - 1] == '.':
					grid[i][j - 1] = 'D'
			if j != c - 1:
				if grid[i][j + 1] == 'W':
					break
				elif grid[i][j + 1] == '.':
					grid[i][j + 1] = 'D'
	else:
		continue
	broke = True
	break
else:
	print('Yes')
	for list1 in grid:
		for elem1 in list1:
			print(elem1, end='')
		print()
if broke:
	print('No')


(r, c) = input().split(' ')
r = int(r)
c = int(c)
l = []
j = 0
import string
for i in range(r):
	s = input()
	l.append(s)
for i in range(len(l)):
	if l[i].find('WS') != -1 or l[i].find('SW') != -1:
		print('NO')
		exit()
	elif l[i].find('W') != -1:
		y = l[i].find('W')
		if i - 1 >= 0:
			if l[i - 1][y] == 'S':
				print('NO')
				exit()
		if i + 1 <= r - 1:
			if l[i + 1][y] == 'S':
				print('NO')
				exit()
print('YES')
for t in l:
	print(t.replace('.', 'D'))


(n, m) = map(int, input().split())
arr = []
for i in range(n):
	s = input()
	if s.count('SW') != 0:
		print('NO')
		exit(0)
	if s.count('WS') != 0:
		print('NO')
		exit(0)
	if i != 0:
		for j in range(len(s)):
			if arr[i - 1][j] == 'S' and s[j] == 'W':
				print('NO')
				exit(0)
			if arr[i - 1][j] == 'W' and s[j] == 'S':
				print('NO')
				exit(0)
	arr.append(s)
for i in range(1, len(arr) - 1):
	for j in range(len(arr[0])):
		if arr[i][j] == 'S' and arr[i - 1][j] == 'W':
			print('NO')
			exit(0)
print('YES')
for each in arr:
	print(each.replace('.', 'D'))


def FillDogs(pasture, r, c):
	for i in range(r):
		for j in range(c):
			if pasture[i][j] == '.':
				pasture[i][j] = 'D'

def IsPossible(pasture, r, c):
	for i in range(r):
		for j in range(c - 1):
			if pasture[i][j] == 'S' and pasture[i][j + 1] == 'W':
				return False
			if pasture[i][j] == 'W' and pasture[i][j + 1] == 'S':
				return False
	for i in range(c):
		for j in range(r - 1):
			if pasture[j][i] == 'S' and pasture[j + 1][i] == 'W':
				return False
			if pasture[j][i] == 'W' and pasture[j + 1][i] == 'S':
				return False
	return True

def PrintPasture(pasture, r, c):
	pasture_new = []
	for i in pasture:
		new = ''
		for j in i:
			new += j
		pasture_new.append(new)
	for i in pasture_new:
		print(i)

def main():
	(r, c) = map(int, input().split())
	pasture = []
	for i in range(r):
		pasture.append(list(input()))
	FillDogs(pasture, r, c)
	if IsPossible(pasture, r, c):
		print('Yes')
		PrintPasture(pasture, r, c)
	else:
		print('No')
main()


(R, C) = list(map(int, input().split()))
field = [[0 for i in range(C)] for i in range(R)]

def easy_print(matrix):
	print('Yes')
	for i in range(R):
		print(''.join(matrix[i]))

def super_dogs(matrix):
	print('Yes')
	for i in range(R):
		for j in range(C):
			if matrix[i][j] == '.':
				matrix[i][j] = 'D'
	for i in range(R):
		print(''.join(matrix[i]))

def is_defended(matrix):
	W_cnt = 0
	for i in range(R):
		for j in range(C):
			if matrix[i][j] == 'W':
				W_cnt += 1
				if j > 0:
					c1 = matrix[i][j - 1]
				else:
					c1 = '.'
				if j < C - 1:
					c2 = matrix[i][j + 1]
				else:
					c2 = '.'
				if i > 0:
					c3 = matrix[i - 1][j]
				else:
					c3 = '.'
				if i < R - 1:
					c4 = matrix[i + 1][j]
				else:
					c4 = '.'
				if (c1 == 'S') | (c2 == 'S') | (c3 == 'S') | (c4 == 'S'):
					return print('No')
	if W_cnt == 0:
		return easy_print(matrix)
	else:
		return super_dogs(matrix)
if (R == 0) | (C == 0):
	print('Yes')
else:
	for i in range(R):
		row = input()
		row = list(row)
		for j in range(C):
			field[i][j] = row[j]
	is_defended(field)


flag = 0
(R, C) = map(int, input().strip().split())
field = []
for i in range(R + 2):
	field.append(['D'] * (C + 2))
for i in range(R):
	row = input().strip()
	row = list(row)
	for j in range(C):
		if row[j] == '.':
			field[i + 1][j + 1] = 'D'
		else:
			field[i + 1][j + 1] = row[j]
newfield = []
for i in range(R):
	newfield.append(['D'] * C)
for i in range(R):
	for j in range(C):
		newfield[i][j] = field[i + 1][j + 1]
for i in range(R + 1):
	for j in range(C + 1):
		if field[i][j] == 'S' and (field[i][j + 1] == 'W' or field[i + 1][j] == 'W' or field[i][j - 1] == 'W' or (field[i - 1][j] == 'W')):
			flag = 1
if flag == 1:
	print('No')
else:
	print('Yes')
	for i in range(R):
		b = ''.join(newfield[i])
		print(b)


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))
(R, C) = rl()
grid = [['.'] * C for _ in range(R)]
for r in range(R):
	grid[r] = [x for x in input()]
ans = 'Yes'
for r in range(R):
	for c in range(C):
		if grid[r][c] == 'S':
			for dr in [-1, 0, 1]:
				for dc in [-1, 0, 1]:
					if abs(dr) + abs(dc) == 1:
						nr = r + dr
						nc = c + dc
						if nr >= 0 and nc >= 0 and (nr < R) and (nc < C):
							if grid[nr][nc] == 'W':
								ans = 'No'
							if grid[nr][nc] == '.':
								grid[nr][nc] = 'D'
		if ans == 'No':
			break
	if ans == 'No':
		break
if ans == 'No':
	print(ans)
else:
	print(ans)
	for r in range(R):
		print(''.join(grid[r]))


(r, c) = map(int, input().split())
s = '\n'.join((input().replace('.', 'D') for _ in [0] * r))
print('No' if (set(zip(s, s[1:])) | set(zip(s, s[c + 1:]))) & {('S', 'W'), ('W', 'S')} else 'Yes\n' + s)


def inpt():
	(R, C) = input().split()
	field = []
	for line in range(int(R)):
		field.append(list(input()))
	return (int(R), int(C), field)

def A(R, C, field):
	for r in range(R):
		for c in range(C):
			if field[r][c] == 'S' and c + 1 < C and (field[r][c + 1] == 'W'):
				return 'No'
			elif field[r][c] == '.':
				field[r][c] = 'D'
			if field[r][c] == 'S' and r + 1 < R and (field[r + 1][c] == 'W'):
				return 'No'
			if field[r][c] == 'W' and c + 1 < C and (field[r][c + 1] == 'S'):
				return 'No'
			if field[r][c] == 'W' and r + 1 < R and (field[r + 1][c] == 'S'):
				return 'No'
	return 'Yes'
(R, C, field) = inpt()
result = A(R, C, field)
if result == 'No':
	print('No')
else:
	print('Yes')
	for r in range(R):
		print(''.join(field[r]))


(x, y) = list(map(int, input().split()))
grid = []
grid2 = []
arrmain = []
for _ in range(x):
	s = input()
	arr = list(s)
	grid.append(arr)
	if 'WS' in s or 'SW' in s:
		print('No')
		exit()
	elif _ == 0:
		s = s.replace('.', 'D')
		arrmain.append(s)
	else:
		for k in range(y):
			if arr[k] == 'S':
				if grid[_ - 1][k] == 'W':
					print('No')
					exit()
			elif arr[k] == 'W':
				if grid[_ - 1][k] == 'S':
					print('No')
					exit()
			else:
				arr[k] = 'D'
		arrmain.append(''.join(arr))
print('Yes')
for kkk in arrmain:
	print(kkk)


(r, c) = list(map(int, input().split()))
mat = [[0] * c] * r

def protect(i, j):
	if i - 1 >= 0:
		if mat[i - 1][j] == 'W':
			return False
	if i + 1 < r:
		if mat[i + 1][j] == 'W':
			return False
	if j - 1 >= 0:
		if mat[i][j - 1] == 'W':
			return False
	if j + 1 < c:
		if mat[i][j + 1] == 'W':
			return False

def sheep():
	for i in range(r):
		t = input()
		mat[i] = [j for j in t]
	for i in range(r):
		for j in range(c):
			if mat[i][j] == 'S':
				if protect(i, j) == False:
					return False
	return True
if sheep() == True:
	print('Yes')
	for i in range(r):
		for j in range(c):
			if mat[i][j] == '.':
				print('D', end='')
			else:
				print(mat[i][j], end='')
		print()
else:
	print('No')


(r, c) = list(map(int, input().split()))
pole = []
for i in range(r):
	pole.append(input())
a = True
for i in range(r):
	a = True
	for j in range(c):
		if pole[i][j] == 'S':
			if i != 0:
				if pole[i - 1][j] == 'W':
					print('NO')
					break
				elif pole[i - 1][j] == '.':
					pole[i - 1] = pole[i - 1][:j] + 'D' + pole[i - 1][j + 1:]
			if i != r - 1:
				if pole[i + 1][j] == 'W':
					print('NO')
					break
				elif pole[i + 1][j] == '.':
					pole[i + 1] = pole[i + 1][:j] + 'D' + pole[i + 1][j + 1:]
			if j != 0:
				if pole[i][j - 1] == 'W':
					print('NO')
					break
				elif pole[i][j - 1] == '.':
					pole[i] = pole[i][:j - 1] + 'D' + pole[i][j:]
			if j != c - 1:
				if pole[i][j + 1] == 'W':
					print('NO')
					break
				elif pole[i][j + 1] == '.':
					pole[i] = pole[i][:j + 1] + 'D' + pole[i][j + 2:]
	else:
		a = False
	if a:
		break
if not a:
	print('YES')
	for i in range(r):
		print(pole[i])


(R, C) = map(int, input().split())
array = []
for i in range(R):
	array.append(input().strip('\n'))
for i in range(R):
	for j in range(C - 1):
		if set([array[i][j], array[i][j + 1]]) == set(['S', 'W']):
			print('No')
			exit()
for i in range(R - 1):
	for j in range(C):
		if set([array[i][j], array[i + 1][j]]) == set(['S', 'W']):
			print('No')
			exit()
print('Yes')
for i in range(R):
	line = ''
	for j in range(C):
		if array[i][j] == '.':
			line += 'D'
		else:
			line += array[i][j]
	print(line)


import sys
import math

def read_in():
	lines = sys.stdin.readlines()
	for i in range(len(lines)):
		lines[i] = lines[i].replace('\n', '')
	return lines

def main():
	lines = read_in()
	dim = lines[0]
	dim_array = dim.split(' ')
	L = int(dim_array[0])
	H = int(dim_array[1])
	is_protectable = True
	output_grid = ''
	test_grid = []
	test_grid.append('T' * (H + 2))
	for i in range(0, L):
		line = lines[i + 1]
		test_grid.append('T' + line + 'T')
		for j in range(0, H):
			char = line[j]
			if char == 'W':
				output_grid += 'W'
			elif char == '.':
				output_grid += 'D'
			elif char == 'S':
				output_grid += 'S'
		if i < L - 1:
			output_grid += '\n'
	test_grid.append('T' * (H + 2))
	for i in range(1, L + 1):
		for j in range(1, H + 1):
			if test_grid[i][j] == 'S' and (test_grid[i - 1][j] == 'W' or test_grid[i + 1][j] == 'W' or test_grid[i][j - 1] == 'W' or (test_grid[i][j + 1] == 'W')):
				print('No')
				exit()
	print('Yes')
	print(output_grid)
main()


def main():
	(n, m) = map(int, input().split())
	l = [input() for _ in range(n)]
	r = any(('SW' in s or 'WS' in s for s in [*l, *[''.join(t) for t in zip(*l)]]))
	if r:
		print('No')
	else:
		print('Yes')
		for s in l:
			print(s.replace('.', 'D'))
main()


(n, m) = input().split()
(n, m) = (int(n), int(m))
arr = [list(input()) for k in range(n)]
poss = True
for i in range(n):
	for j in range(m):
		if arr[i][j] == '.':
			if i > 0 and arr[i - 1][j] == 'S':
				arr[i][j] = 'D'
			if j > 0 and arr[i][j - 1] == 'S':
				arr[i][j] = 'D'
			if i < n - 1 and arr[i + 1][j] == 'S':
				arr[i][j] = 'D'
			if j < m - 1 and arr[i][j + 1] == 'S':
				arr[i][j] = 'D'
		if i > 0 and arr[i][j] == 'S' and (arr[i - 1][j] == 'W'):
			poss = False
		if i > 0 and arr[i - 1][j] == 'S' and (arr[i][j] == 'W'):
			poss = False
		if j > 0 and arr[i][j] == 'S' and (arr[i][j - 1] == 'W'):
			poss = False
		if j > 0 and arr[i][j - 1] == 'S' and (arr[i][j] == 'W'):
			poss = False
if poss:
	print('Yes')
	for row in arr:
		print(''.join(row))
else:
	print('No')


(n, m) = map(int, input().split(' '))
a = []
for ll in range(n):
	a.append(list(input()))
for i in range(n):
	for j in range(m):
		if a[i][j] == 'S':
			if i - 1 >= 0 and a[i - 1][j] == '.':
				a[i - 1][j] = 'D'
			if i + 1 < n and a[i + 1][j] == '.':
				a[i + 1][j] = 'D'
			if j - 1 >= 0 and a[i][j - 1] == '.':
				a[i][j - 1] = 'D'
			if j + 1 < m and a[i][j + 1] == '.':
				a[i][j + 1] = 'D'
			if i - 1 >= 0 and a[i - 1][j] == 'W':
				print('No')
				exit()
			if i + 1 < n and a[i + 1][j] == 'W':
				print('No')
				exit()
			if j - 1 >= 0 and a[i][j - 1] == 'W':
				print('No')
				exit()
			if j + 1 < m and a[i][j + 1] == 'W':
				print('No')
				exit()
print('Yes')
for i in range(n):
	for j in range(m):
		print(a[i][j], end='')
	print('')


(a, b) = map(int, input().split())
grid = []
for i in range(a):
	linha = input()
	grid.append(linha.replace('.', 'D'))
r = True
for i in range(a):
	for j in range(b):
		if i and grid[i][j] == 'S' and (grid[i - 1][j] == 'W'):
			r = False
		if j and grid[i][j] == 'S' and (grid[i][j - 1] == 'W'):
			r = False
		if i < a - 1 and grid[i][j] == 'S' and (grid[i + 1][j] == 'W'):
			r = False
		if j < b - 1 and grid[i][j] == 'S' and (grid[i][j + 1] == 'W'):
			r = False
if r:
	print('Yes')
	for i in grid:
		print(i)
else:
	print('No')


(r, c) = [int(s) for s in input().split(' ')]
rows = [input() for row in range(r)]
ans = True
for row in range(r):
	for col in range(c):
		if rows[row][col] == 'S' and 'W' in [rows[max(0, row - 1)][col], rows[min(r - 1, row + 1)][col], rows[row][max(0, col - 1)], rows[row][min(c - 1, col + 1)]]:
			ans = False
if ans:
	print('Yes')
	for row in rows:
		print(''.join(row.replace('.', 'D')))
else:
	print('No')


(r, c) = map(int, input().split())
pasture = [list(input()) for i in range(r)]
impossible = False

def fill(tu):
	global impossible
	(x, y) = tu
	if any((x < 0, y < 0, x >= r, y >= c)):
		return
	if pasture[x][y] == 'S':
		impossible = True
	if pasture[x][y] == '.':
		pasture[x][y] = 'D'
for i in range(r):
	for j in range(c):
		if pasture[i][j] == 'W':
			for tu in [(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)]:
				fill(tu)
if impossible:
	print('No')
else:
	print('Yes')
	for i in range(r):
		print(''.join(pasture[i]))


fast = lambda : stdin.readline().strip()
zzz = lambda : [int(i) for i in fast().split()]
(z, zz) = (input, lambda : list(map(int, z().split())))
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from re import *
from sys import *
from math import *
from heapq import *
from queue import *
from bisect import *
from string import *
from itertools import *
from collections import *
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from collections import Counter as cc
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def output(answer):
	stdout.write(str(answer))
(n, m) = zzz()
lst = ['D' * m]
ans = 'Yes'
for ii in range(n):
	arr = list(fast())
	for i in range(m - 1):
		if arr[i] == '.':
			arr[i] = 'D'
		if arr[i] == 'S' and arr[i + 1] == 'W':
			ans = 'No'
		if arr[i] == 'S' and lst[ii][i] == 'W':
			ans = 'No'
		if arr[i] == 'W' and arr[i + 1] == 'S':
			ans = 'No'
		if arr[i] == 'W' and lst[ii][i] == 'S':
			ans = 'No'
	if arr[-1] == '.':
		arr[-1] = 'D'
	if arr[-1] == 'S' and lst[ii][-1] == 'W':
		ans = 'No'
	if arr[-1] == 'W' and lst[ii][-1] == 'S':
		ans = 'No'
	lst.append(''.join(arr))
print(ans)
if ans == 'Yes':
	for i in range(1, n + 1):
		print(lst[i])


(n, k) = map(int, input().split())
a = [['.' for _ in range(k)] for _ in range(n)]
(i, j, yy) = (0, 0, 0)
for q in range(n):
	t = input()
	for w in range(k):
		if t[w] != '.':
			a[q][w] = t[w]
while i != n and yy == 0:
	if a[i][j] == 'S':
		ar = [(1, 0), (-1, 0), (0, 1), (0, -1)]
		for p in range(4):
			(e, r) = ar[p]
			if 0 <= e + i <= n - 1 and 0 <= r + j <= k - 1 and (a[i + e][j + r] != 'W') and (a[i + e][j + r] != 'S'):
				a[i + e][j + r] = 'D'
			elif 0 <= e + i <= n - 1 and 0 <= r + j <= k - 1 and (a[i + e][j + r] == 'W'):
				yy = 1
				break
		if j == k - 1:
			i += 1
			j = 0
		else:
			j += 1
	elif j == k - 1:
		i += 1
		j = 0
	else:
		j += 1
if yy == 1:
	print('No')
else:
	print('Yes')
	for i in a:
		print(''.join(i))


(n, m) = map(int, input().split())
z = []
flag = 'YES'
for _ in range(n):
	s = list(input())
	for i in range(m):
		if s[i] == '.':
			s[i] = 'D'
	z.append(''.join(s))
for i in range(n):
	for j in range(m):
		(a, b, c, d) = (1, 1, 1, 1)
		if z[i][j] == 'W':
			k = 0
			while a != 0 and b != 0 and (c != 0) and (d != 0):
				k += 1
				if a != 0 and j - k >= 0:
					if z[i][j - k] == 'D':
						a = 0
					elif z[i][j - k] == 'S':
						flag = 'NO'
						break
				else:
					a = 0
				if b != 0 and j + k < m:
					if z[i][j + k] == 'D':
						b = 0
					elif z[i][j + k] == 'S':
						flag = 'NO'
						break
				else:
					b = 0
				if c != 0 and i + k < n:
					if z[i + k][j] == 'D':
						c = 0
					elif z[i + k][j] == 'S':
						flag = 'NO'
						break
				else:
					c = 0
				if d != 0 and i - k >= 0:
					if z[i - k][j] == 'D':
						d = 0
					elif z[i - k][j] == 'S':
						flag = 'NO'
						break
				else:
					d = 0
		if flag == 'NO':
			break
	if flag == 'NO':
		break
if flag == 'YES':
	print(flag)
	for i in z:
		print(i)
else:
	print(flag)


from itertools import zip_longest
(R, C) = map(int, input().split())
a = (*map(lambda x: x.replace('.', 'D', x.count('.')), (input() for i in range(R))),)
for (i, j) in zip_longest(a, a[1:], fillvalue='.' * C):
	for x in zip_longest(i, i[1:], j, j[1:], fillvalue='.'):
		if [*'SW'] in map(sorted, ((x[0], x[1]), (x[2], x[3]), (x[0], x[2]), (x[1], x[3]))):
			print('NO')
			exit()
print('YES', *a, sep='\n')


import sys
import os
import math
import copy
from math import gcd
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
import itertools

def Int():
	return int(sys.stdin.readline())

def Mint():
	return map(int, sys.stdin.readline().split())

def Lstr():
	return list(sys.stdin.readline().strip())

def Str():
	return sys.stdin.readline().strip()

def Mstr():
	return map(str, sys.stdin.readline().strip().split())

def List():
	return list(map(int, sys.stdin.readline().split()))

def Hash():
	return dict()

def Mod():
	return 1000000007

def Ncr(n, r, p):
	return fact[n] * (ifact[r] * ifact[n - r] % p) % p

def Most_frequent(list):
	return max(set(list), key=list.count)

def Mat2x2(n):
	return [List() for _ in range(n)]

def Lcm(x, y):
	return x * y // gcd(x, y)

def dtob(n):
	return bin(n).replace('0b', '')

def btod(n):
	return int(n, 2)

def solution():
	(n, m) = Mint()
	a = []
	for i in range(n):
		a.append(Lstr())
	p = 0
	for i in range(n):
		for j in range(m):
			if a[i][j] == '.':
				a[i][j] = 'D'
			if a[i][j] == 'S':
				if i + 1 < n and a[i + 1][j] == 'W' or (i - 1 >= 0 and a[i - 1][j] == 'W') or (j + 1 < m and a[i][j + 1] == 'W') or (j - 1 >= 0 and a[i][j - 1] == 'W'):
					p = 1
					break
	if p == 1:
		print('No')
	else:
		print('Yes')
		for i in a:
			print(''.join(i))
solution()


(r, c) = map(int, input().split())
s = []
w = []
for i in range(r):
	x = 'D'.join(input().split('.'))
	if 'WS' in x or 'SW' in x:
		print('No')
		exit(0)
	w.extend([(i, j) for j in range(c) if x[j] == 'W'])
	s.append(x)
if r != 1:
	for (i, j) in w:
		if i == 0:
			if s[i + 1][j] == 'S':
				print('No')
				exit(0)
		elif i == r - 1:
			if s[i - 1][j] == 'S':
				print('No')
				exit(0)
		elif s[i - 1][j] == 'S' or s[i + 1][j] == 'S':
			print('No')
			exit(0)
print('Yes')
print(*s, sep='\n')


(r, c) = map(int, input().split())
l = []

def empty(l, i):
	if 'W' in l[i]:
		a = l[i].index('W')
		while a > -1 and a < c:
			if i + 1 < r and (l[i + 1][a] == '.' or l[i + 1][a] == 'D'):
				l[i + 1][a] = 'D'
			elif i + 1 < r and l[i + 1][a] == 'S':
				return False
			if i - 1 > -1 and (l[i - 1][a] == '.' or l[i - 1][a] == 'D'):
				l[i - 1][a] = 'D'
			elif i - 1 > -1 and l[i - 1][a] == 'S':
				return False
			if a + 1 < c and (l[i][a + 1] == '.' or l[i][a + 1] == 'D'):
				l[i][a + 1] = 'D'
			elif a + 1 < c and l[i][a + 1] == 'S':
				return False
			if a - 1 > -1 and (l[i][a - 1] == '.' or l[i][a - 1] == 'D'):
				l[i][a - 1] = 'D'
			elif a - 1 > -1 and l[i][a - 1] == 'S':
				return False
			if 'W' in l[i][a + 1:]:
				a += l[i][a + 1:].index('W') + 1
			else:
				a = -1
	return True
for i in range(r):
	l.append(list(input()))
for i in range(r):
	p = empty(l, i)
	if not p:
		print('No')
		break
if p:
	print('YES')
	for i in range(r):
		print(''.join(l[i]))


(n, m) = map(int, input().split())
l = [[0] * m for i in range(n)]
flag = 1
for i in range(n):
	s = input()
	for j in range(m):
		l[i][j] = s[j]
for i in range(n):
	for j in range(m):
		if l[i][j] == 'S':
			for (xd, yd) in ([1, 0], [0, 1], [-1, 0], [0, -1]):
				a = i + xd
				b = j + yd
				if 0 <= a < n and 0 <= b < m:
					if l[a][b] == '.':
						l[a][b] = 'D'
					elif l[a][b] == 'W':
						flag = 0
if flag == 0:
	print('No')
else:
	print('Yes')
	for i in l:
		for j in i:
			print(j, end='')
		print()


def main():
	(R, C) = map(int, input().split())
	arr = []
	for _ in range(R):
		arr.append(list(input()))
	flag = True
	for i in range(R):
		for j in range(C):
			if arr[i][j] == 'S':
				if i >= 1:
					if arr[i - 1][j] == 'W':
						flag = False
						break
					elif arr[i - 1][j] == '.':
						arr[i - 1][j] = 'D'
				if i + 1 < R:
					if arr[i + 1][j] == 'W':
						flag = False
						break
					elif arr[i + 1][j] == '.':
						arr[i + 1][j] = 'D'
				if j >= 1:
					if arr[i][j - 1] == 'W':
						flag = False
						break
					elif arr[i][j - 1] == '.':
						arr[i][j - 1] = 'D'
				if j + 1 < C:
					if arr[i][j + 1] == 'W':
						flag = False
						break
					elif arr[i][j + 1] == '.':
						arr[i][j + 1] = 'D'
		if flag == False:
			break
	if flag:
		print('YES')
		for i in range(R):
			for j in range(C):
				print(arr[i][j], end='')
			print()
	else:
		print('NO')
main()


import copy
(R, C) = list(map(int, input().strip().split()))
maps = []
(ls, lw) = (0, 0)
for i in range(R):
	line = input().strip()
	tmp = []
	for item in line:
		if item == 'S':
			ls += 1
		elif item == 'W':
			lw += 1
		tmp.append(item)
	maps.append(tmp)
results = copy.deepcopy(maps)
danger = False
for i in range(R):
	for j in range(C):
		if maps[i][j] == 'S':
			if j - 1 >= 0:
				if maps[i][j - 1] == '.':
					results[i][j - 1] = 'D'
				elif maps[i][j - 1] == 'W':
					danger = True
					break
			if j + 1 < C:
				if maps[i][j + 1] == '.':
					results[i][j + 1] = 'D'
				elif maps[i][j + 1] == 'W':
					danger = True
					break
			if i - 1 >= 0:
				if maps[i - 1][j] == '.':
					results[i - 1][j] = 'D'
				elif maps[i - 1][j] == 'W':
					danger = True
					break
			if i + 1 < R:
				if maps[i + 1][j] == '.':
					results[i + 1][j] = 'D'
				elif maps[i + 1][j] == 'W':
					danger = True
					break
if danger:
	print('No')
else:
	print('Yes')
	for i in range(R):
		print(''.join(results[i]))


a = list(map(int, input().split()))
row = a[0]
column = a[1]
game = []
for i in range(row):
	c = str(input())
	game.append([c])
new = [[j.replace('.', 'D')] for i in game for j in i]
news = []
for i in new:
	for j in i:
		temp = ','.join(j)
		temps = temp.split(',')
		news.append(temps)
secure = True
find = 'S'
found = False
check = 0
if column > 1:
	for i in news:
		if secure == False:
			break
		if i[0] == find:
			if i[1] == 'S' or i[1] == 'D':
				secure = True
			else:
				secure = False
				break
		if i[column - 1] == find:
			if i[column - 2] == 'W':
				secure = False
				break
			else:
				secure = True
		if secure == False:
			break
		for j in range(1, column - 1):
			if i[j] == find:
				secure = False
				if i[j + 1] == 'S' or i[j + 1] == 'D':
					secure = True
				else:
					secure = False
					break
				if i[j - 1] == 'S' or i[j - 1] == 'D':
					secure = True
				else:
					secure = False
					break
				if secure == False:
					break
			if secure == False:
				break
revert = list(zip(*news))
if row > 1:
	for i in revert:
		if secure == False:
			break
		if i[0] == find:
			if i[1] == 'S' or i[1] == 'D':
				secure = True
			else:
				secure = False
				break
		if i[row - 1] == find:
			if i[row - 2] == 'W':
				secure = False
				break
			else:
				secure = True
		if secure == False:
			break
		for j in range(1, row - 1):
			if i[j] == find:
				secure = False
				if i[j + 1] == 'S' or i[j + 1] == 'D':
					secure = True
				else:
					secure = False
					break
				if i[j - 1] == 'S' or i[j - 1] == 'D':
					secure = True
				else:
					secure = False
					break
				if secure == False:
					break
			if secure == False:
				break
if secure:
	print('Yes')
	for j in news:
		for i in j:
			print(i, end='')
		print()
else:
	print('No')


(r, c) = map(int, input().split())
l = []
fl = 0

def f(r, c, l, n, m):
	if 0 <= r < n and 0 <= c < m:
		if l[r][c] == 'W':
			return 1
for i in range(r):
	l.append(list(input().replace('.', 'D')))
for i in range(r):
	for j in range(c):
		if l[i][j] == 'S':
			if f(i + 1, j, l, r, c):
				fl = 1
				print('NO')
				break
			if f(i - 1, j, l, r, c):
				fl = 1
				print('NO')
				break
			if f(i, j + 1, l, r, c):
				fl = 1
				print('NO')
				break
			if f(i, j - 1, l, r, c):
				fl = 1
				print('NO')
				break
	if fl:
		break
else:
	print('YES')
	for i in range(r):
		for j in range(c):
			print(l[i][j], end='')
		print()


(s, o) = [int(i) for i in input().split()]
g = []
for i in range(s):
	g.append(list(input()))
p = g
for i in range(s):
	for j in range(o):
		if p[i][j] == '.':
			p[i][j] = 'D'
		if g[i][j] == 'S' and (j < o - 1 and g[i][j + 1] == 'W' or (i < s - 1 and g[i + 1][j] == 'W') or (i > 0 and g[i - 1][j] == 'W') or (j > 0 and g[i][j - 1] == 'W')):
			print('No')
			exit()
print('Yes')
for i in range(s):
	for j in range(o):
		print(p[i][j], end='')
	print()


(R, C) = list(map(int, input().split(' ')))
a = [list(input()) for i in range(R)]

def sheep(a, R, C):
	flag = 0
	for i in range(R):
		for j in range(C):
			if a[i][j] == 'W' and (i > 0 and a[i - 1][j] == 'S' or (i < R - 1 and a[i + 1][j] == 'S') or (j > 0 and a[i][j - 1] == 'S') or (j < C - 1 and a[i][j + 1] == 'S')):
				flag = -1
				return flag
	return flag
flag = sheep(a, R, C)
if flag == 0:
	for i in range(R):
		for j in range(C):
			if a[i][j] == '.':
				a[i][j] = 'D'
if flag == -1:
	print('No')
else:
	print('Yes')
	for i in range(R):
		print(''.join(a[i]))


(a, b) = map(int, input().split())
array = []
(W1, S1, W2, S2) = ([], [], [], [])
g = True
for i in range(a):
	r = input()
	r = r.replace('.', 'D')
	array.append(r)
for i in range(a):
	(W1, S1) = ([], [])
	W = array[i].count('W')
	S = array[i].count('S')
	r = array[i]
	for i in range(W):
		W1.append(r.index('W'))
	for i in range(S):
		S1.append(r.index('S'))
	for i in S1:
		for k in W2:
			if i == k:
				g = False
				break
	for i in S2:
		for k in W1:
			if i == k:
				g = False
				break
	(W2, S2) = ([], [])
	r = 't' + r + 't'
	for i in range(b):
		if (r[i] == 'S' and r[i - 1] == 'W' or (r[i] == 'S' and r[i + 1] == 'W')) or (r[i] == 'W' and r[i - 1] == 'S' or (r[i] == 'W' and r[i + 1] == 'S')):
			g = False
	W2.extend(W1)
	S2.extend(S1)
if g == False:
	print('No')
else:
	print('Yes')
	for i in array:
		print(i)


a = input()
a = a.split()
R = int(a[0])
C = int(a[1])
l = []
for i in range(R):
	l.append([])
	a = input()
	for j in range(C):
		l[i].append(a[j])
q = 0
for i in range(1, R):
	for j in range(1, C):
		if l[i][j] == 'S' and (l[i][j - 1] == 'W' or l[i - 1][j] == 'W'):
			q = 1
		if l[i][j] == 'W' and (l[i][j - 1] == 'S' or l[i - 1][j] == 'S'):
			q = 1
if len(l) > 1:
	if l[0][0] == 'W' and l[1][0] == 'S' or (l[0][0] == 'S' and l[1][0] == 'W'):
		q = 1
if len(l[0]) > 1:
	if l[0][0] == 'W' and l[0][1] == 'S' or (l[0][0] == 'S' and l[0][1] == 'W'):
		q = 1
for j in range(1, C):
	if l[0][j] == 'S' and l[0][j - 1] == 'W':
		q = 1
	if l[0][j] == 'W' and l[0][j - 1] == 'S':
		q = 1
for j in range(1, R):
	if l[i][0] == 'S' and l[i - 1][0] == 'W':
		q = 1
	if l[i][0] == 'W' and l[i - 1][0] == 'S':
		q = 1
if q == 1:
	print('No')
if q == 0:
	print('Yes')
	for i in range(R):
		b = ''
		for j in range(C):
			if l[i][j] == '.':
				b = b + 'D'
			if l[i][j] == 'W':
				b = b + 'W'
			if l[i][j] == 'S':
				b = b + 'S'
		print(b)


def solve(d):
	dx = [1, -1, 0, 0]
	dy = [0, 0, 1, -1]
	res = 1
	for i in range(1, r + 1):
		for j in range(1, c + 1):
			if d[i][j] == 'S':
				for k in range(4):
					if d[i + dx[k]][j + dy[k]] == 'W':
						res = 0
						return (res, d)
	for i in range(1, r + 1):
		for j in range(1, c + 1):
			if d[i][j] == 'S':
				for k in range(4):
					if d[i + dx[k]][j + dy[k]] == '.':
						d[i + dx[k]][j + dy[k]] = 'D'
	return (res, d)
(r, c) = map(int, input().split())
d = [['.' for j in range(c + 2)] for i in range(r + 2)]
for i in range(1, r + 1):
	s = input()
	for j in range(1, c + 1):
		d[i][j] = s[j - 1]
(res, d) = solve(d)
if res:
	print('Yes')
	for i in range(1, r + 1):
		for j in range(1, c + 1):
			print(d[i][j], end='')
		print()
else:
	print('No')


(r, c) = map(int, input().split())
l = [[0 for i in range(c + 2)]]
for i in range(r):
	l1 = list(input())
	l1.insert(0, 0)
	l1.append(0)
	l.append(l1)
l.append([0 for i in range(c + 2)])
flag = 0
for i in range(1, r + 1):
	for j in range(1, c + 1):
		if l[i][j] == '.':
			l[i][j] = 'D'
		elif l[i][j] == 'S':
			if l[i - 1][j] == 'W' or l[i][j + 1] == 'W' or l[i + 1][j] == 'W' or (l[i][j - 1] == 'W'):
				flag = 1
				print('NO')
				break
	if flag == 1:
		break
else:
	print('YES')
	for i in range(1, r + 1):
		for j in range(1, c + 1):
			print(l[i][j], end='')
		print()


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
int1 = lambda x: int(x) - 1
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))
ilelec = lambda : map(int1, input().split())
alelec = lambda : list(map(int1, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
(r, c) = ilele()
A = []
for i in range(r):
	S = [*input()]
	for i in range(c):
		if S[i] == '.':
			S[i] = 'D'
	A.append(S)
d1 = [1, 0, 0, -1]
d2 = [0, -1, 1, 0]
for i in range(r):
	for j in range(c):
		if A[i][j] == 'S':
			for k in range(4):
				x1 = i + d1[k]
				y1 = j + d2[k]
				if 0 <= x1 < r and 0 <= y1 < c:
					if A[x1][y1] == 'W':
						Yy(0)
						exit(0)
Yy(1)
for i in A:
	print(''.join(i))


(r, c) = map(int, input().split())
m = [input() for _ in range(r)]
ans = False
for i in range(r):
	for j in range(c):
		if i + 1 < r and m[i + 1][j] + m[i][j] in ('SW', 'WS'):
			print('NO')
			exit(0)
		if j + 1 < c and m[i][j + 1] + m[i][j] in ('SW', 'WS'):
			print('NO')
			exit(0)
print('YES')
for i in m:
	print(''.join(map(lambda x: x.replace('.', 'D'), i)))


(row_number, column_number) = map(int, input().split())
field = [list(input()) for i in range(row_number)]

def set_dog(row, column):
	if row_number <= row or row < 0 or column_number <= column or (column < 0) or (field[row][column] == 'D') or (field[row][column] == 'W'):
		return True
	if field[row][column] == '.':
		field[row][column] = 'D'
		return True
	return False

def surraund_wolf(row, column):
	points = ((row - 1, column), (row + 1, column), (row, column - 1), (row, column + 1))
	return all((set_dog(*point) for point in points))
i = 0
is_surraunding_possibale = True
while is_surraunding_possibale and i < row_number:
	j = 0
	while is_surraunding_possibale and j < column_number:
		if field[i][j] == 'W' and (not surraund_wolf(i, j)):
			is_surraunding_possibale = False
		j += 1
	i += 1
if is_surraunding_possibale:
	print('Yes')
	print(*(''.join(row) for row in field), sep='\n')
else:
	print('No')


Size = list(map(int, input().split()))
X = []
for i in range(Size[0]):
	X.append(input())
for i in range(len(X)):
	for j in range(len(X[i])):
		if X[i][j] == 'W':
			if j > 0:
				if X[i][j - 1] == 'S':
					print('NO')
					exit()
			if j < Size[1] - 1:
				if X[i][j + 1] == 'S':
					print('NO')
					exit()
			if i > 0:
				if X[i - 1][j] == 'S':
					print('NO')
					exit()
			if i < Size[0] - 1:
				if X[i + 1][j] == 'S':
					print('NO')
					exit()
print('YES')
for i in X:
	print(i.replace('.', 'D'))


(n, m) = map(int, input().split())
matrix = [input().replace('.', 'D') for i in range(n)]

def solve():
	for i in range(n):
		for j in range(m):
			if matrix[i][j] == 'S':
				if matrix[max(0, i - 1)][j] == 'W' or matrix[min(i + 1, n - 1)][j] == 'W' or matrix[i][max(0, j - 1)] == 'W' or (matrix[i][min(j + 1, m - 1)] == 'W'):
					return False
	return True
if solve():
	print('Yes')
	print(*matrix, sep='\n')
else:
	print('No')


(r, c) = tuple(map(int, input().split(' ')))
rows = []
for i in range(r):
	rows.append(input())
for row in rows:
	if 'SW' in row or 'WS' in row:
		print('No')
		exit()
for j in range(c):
	for i in range(1, r):
		adj = rows[i - 1][j] + rows[i][j]
		if adj == 'SW' or adj == 'WS':
			print('No')
			exit()
print('Yes')
for row in rows:
	print(row.replace('.', 'D'))


(R, C) = list(map(int, input().split()))
s = [[] * C] * R
possible = True
for i in range(R):
	s[i] = list(str(input()))
for i in range(R):
	for j in range(C):
		if s[i][j] == 'W':
			if i + 1 != R and s[i + 1][j] == 'S' or (i - 1 != -1 and s[i - 1][j] == 'S') or (j - 1 != -1 and s[i][j - 1] == 'S') or (j + 1 != C and s[i][j + 1] == 'S'):
				print('No')
				possible = False
				break
		if s[i][j] == '.':
			s[i][j] = 'D'
	if not possible:
		break
if possible:
	print('Yes')
	for i in range(R):
		print(''.join(s[i]))


(r, c) = list(map(int, input().split()))
ans = 'Yes'
arr = []
for i in range(r):
	arr.append(list(input()))
for i in range(r):
	for j in range(c):
		if arr[i][j] == 'S':
			if i - 1 >= 0:
				if arr[i - 1][j] == 'W':
					ans = 'No'
					break
				elif arr[i - 1][j] != 'S':
					arr[i - 1][j] = 'D'
			if i + 1 < r:
				if arr[i + 1][j] == 'W':
					ans = 'No'
					break
				elif arr[i + 1][j] != 'S':
					arr[i + 1][j] = 'D'
			if j + 1 < c:
				if arr[i][j + 1] == 'W':
					ans = 'No'
					break
				elif arr[i][j + 1] != 'S':
					arr[i][j + 1] = 'D'
			if j - 1 >= 0:
				if arr[i][j - 1] == 'W':
					ans = 'No'
					break
				elif arr[i][j - 1] != 'S':
					arr[i][j - 1] = 'D'
if ans == 'No':
	print('No')
else:
	print('Yes')
	for i in range(r):
		for j in range(c):
			print(arr[i][j], end='')
		print()


def sheep_near(field, w, r, c):
	boxes = [[w[0] + 1, w[1]], [w[0] - 1, w[1]], [w[0], w[1] + 1], [w[0], w[1] - 1]]
	for b in boxes:
		if (b[0] >= 0 and b[0] < r) and (b[1] >= 0 and b[1] < c):
			if field[b[0]][b[1]] == 'S':
				return True
	return False
(r, c) = list(map(int, input().rstrip().split()))
field = []
i = 0
wolfs = []
for _ in range(r):
	rows = []
	input_str = input().rstrip()
	j = 0
	for ch in input_str:
		if ch == 'W':
			wolfs.append((i, j))
		rows.append(ch)
		j += 1
	i += 1
	field.append(rows)
for w in wolfs:
	if sheep_near(field, w, r, c):
		print('NO')
		exit()
print('YES')
for r in field:
	for c in r:
		if c == '.':
			print('D', end='')
		else:
			print(c, end='')
	print('')


(r, c) = map(int, input().split())
g = [input() for _ in range(r)]
good = True
for i in range(r):
	for j in range(c):
		if i > 0 and {g[i][j], g[i - 1][j]} == {'S', 'W'}:
			good = False
		if j > 0 and {g[i][j], g[i][j - 1]} == {'S', 'W'}:
			good = False
if good:
	print('Yes')
	print('\n'.join((''.join(('D' if v == '.' else v for v in row)) for row in g)))
else:
	print('No')


def main():
	dx = [-1, 1, 0, 0]
	dy = [0, 0, -1, 1]
	(n, m) = map(int, input().split())
	ar = [input().replace('.', 'D') for _ in range(n)]
	for i in range(n):
		for j in range(m):
			if ar[i][j] == 'W':
				for k in range(4):
					x = i + dx[k]
					y = j + dy[k]
					if x >= 0 and x < n and (y >= 0) and (y < m) and (ar[x][y] == 'S'):
						print('No')
						return
	print('Yes')
	print(*ar, sep='\n')
main()


(r, c) = map(int, input().split())
matrix = [input() for xxx in range(r)]
natrix = [list(zz) for zz in matrix]
a = 0
for x in range(r):
	for y in range(c):
		if matrix[x][y] == 'S':
			if y < c - 1:
				if matrix[x][y + 1] == 'W':
					print('No')
					a = 1
					break
			if y >= 1:
				if matrix[x][y - 1] == 'W':
					print('No')
					a = 1
					break
			if x >= 1:
				if matrix[x - 1][y] == 'W':
					print('No')
					a = 1
					break
			if x < r - 1:
				if matrix[x + 1][y] == 'W':
					print('No')
					a = 1
					break
		elif matrix[x][y] != 'W':
			natrix[x][y] = 'D'
	if a:
		break
else:
	print('Yes')
	for x in natrix:
		print(''.join(x))


def solution(linhas, n, ll):
	for l in range(len(linhas)):
		for j in range(len(linhas[l])):
			if linhas[l][j] == 'W':
				if j > 0 and linhas[l][j - 1] == 'S':
					print('NO')
					return
				elif j < ll - 1 and linhas[l][j + 1] == 'S':
					print('NO')
					return
				elif l > 0 and linhas[l - 1][j] == 'S':
					print('NO')
					return
				elif l < n - 1 and linhas[l + 1][j] == 'S':
					print('NO')
					return
	print('YES')
	for l in linhas:
		print(l)
(n, placebo) = map(int, input().split())
linhas = []
for i in range(n):
	linhas.append(input().replace('.', 'D'))
solution(linhas, n, placebo)


(r, c) = map(int, input().split())
graph = []
for i in range(r):
	a = input()
	d = []
	for b in range(len(a)):
		d.append(a[b])
	graph.append(d)
can = True
for i in range(r):
	for j in range(c):
		if graph[i][j] == 'S':
			if i - 1 >= 0:
				if graph[i - 1][j] == 'W':
					can = False
					break
				elif can and graph[i - 1][j] == '.':
					graph[i - 1][j] = 'D'
			if j - 1 >= 0:
				if graph[i][j - 1] == 'W':
					can = False
					break
				elif can and graph[i][j - 1] == '.':
					graph[i][j - 1] = 'D'
			if i + 1 < r:
				if graph[i + 1][j] == 'W':
					can = False
					break
				elif can and graph[i + 1][j] == '.':
					graph[i + 1][j] = 'D'
			if j + 1 < c:
				if graph[i][j + 1] == 'W':
					can = False
					break
				elif can and graph[i][j + 1] == '.':
					graph[i][j + 1] = 'D'
if can:
	print('YES')
	for i in range(r):
		for j in range(c):
			print(graph[i][j], end='')
		print()
else:
	print('NO')


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import *
getcontext().prec = 25
MOD = pow(10, 9) + 7
BUFSIZE = 8192
from collections import defaultdict

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, m) = map(int, input().split(' '))
a = []
for i in range(n):
	a.append(input())
ans = 'YES'
for i in range(n):
	for j in range(m):
		if a[i][j] == 'W':
			if i > 0:
				if a[i - 1][j] == 'S':
					ans = 'NO'
					break
			if j > 0:
				if a[i][j - 1] == 'S':
					ans = 'NO'
					break
			if j < m - 1:
				if a[i][j + 1] == 'S':
					ans = 'NO'
					break
			if i < n - 1:
				if a[i + 1][j] == 'S':
					ans = 'NO'
					break
if ans == 'NO':
	print(ans)
else:
	print('YES')
	for i in a:
		i = list(i)
		for j in range(m):
			if i[j] == '.':
				i[j] = 'D'
		print(''.join(i))


def get_int():
	return int(input())

def get_int_list():
	return [int(x) for x in input().split(' ')]

def _print(res):
	if res == 'No':
		print(res)
	else:
		for r in res:
			print(r)

def wolf_adjacent(pasture, i, j):
	if i > 0 and pasture[i - 1][j] == 'W':
		return True
	if j > 0 and pasture[i][j - 1] == 'W':
		return True
	if i < len(pasture) - 1 and pasture[i + 1][j] == 'W':
		return True
	if j < len(pasture[0]) - 1 and pasture[i][j + 1] == 'W':
		return True
	return False

def put_dog(string, j):
	return string[0:j] + 'D' + string[j + 1:]

def add_dogs(pasture, i, j):
	if i > 0 and pasture[i - 1][j] == '.':
		pasture[i - 1] = put_dog(pasture[i - 1], j)
	if j > 0 and pasture[i][j - 1] == '.':
		pasture[i] = put_dog(pasture[i], j - 1)
	if i < len(pasture) - 1 and pasture[i + 1][j] == '.':
		pasture[i + 1] = put_dog(pasture[i + 1], j)
	if j < len(pasture[0]) - 1 and pasture[i][j + 1] == '.':
		pasture[i] = put_dog(pasture[i], j + 1)
	return pasture

def protect(pasture, n, m):
	for i in range(n):
		for j in range(m):
			if pasture[i][j] == 'S':
				wolf_near_sheep = wolf_adjacent(pasture, i, j)
				if wolf_near_sheep:
					return 'No'
				pasture = add_dogs(pasture, i, j)
	print('Yes')
	return pasture
(r, c) = get_int_list()
pasture = []
for i in range(r):
	pasture += [input()]
res = protect(pasture, r, c)
_print(res)


def main():
	[n_rows, n_cols] = map(int, input().split())
	possible = True
	rows = [''] * n_rows
	for i in range(n_rows):
		row = input()
		if possible and ('SW' in row or 'WS' in row):
			possible = False
		if possible:
			rows[i] = row
	if possible:
		for i in range(n_rows):
			if not possible:
				break
			for j in range(n_cols):
				if rows[i][j] == 'W' and (i > 0 and rows[i - 1][j] == 'S' or (i < n_rows - 1 and rows[i + 1][j] == 'S')):
					possible = False
					break
		if possible:
			print('Yes')
			for i in range(n_rows):
				rows[i] = rows[i].replace('.', 'D')
				print(rows[i])
		else:
			print('No')
	else:
		print('No')
main()


def protectSheep(i, j, s):
	if i - 1 > -1:
		if m[i - 1][j] == 'W':
			return True
	if j - 1 > -1:
		if m[i][j - 1] == 'W':
			return True
	if i + 1 < r:
		if m[i + 1][j] == 'W':
			return True
	if j + 1 < c:
		if m[i][j + 1] == 'W':
			return True
	return s

def arrayToString(s):
	result = ''
	for k in s:
		if k == '.':
			result += 'D'
		else:
			result += k
	return result
(r, c) = map(int, input().split())
m = []
for i in range(r):
	inp = list(input())
	m.append(inp)
stop = False
for i in range(r):
	for j in range(c):
		if m[i][j] == 'S':
			stop = protectSheep(i, j, stop)
		if stop:
			break
	if stop:
		break
if stop:
	print('No')
else:
	print('YES')
	for i in range(r):
		print(arrayToString(m[i]))


import sys
(r, c) = map(int, input().split())
X = []
for i in range(r):
	temp = input()
	if 'SW' in temp or 'WS' in temp:
		print('NO')
		sys.exit()
	X.append(temp.replace('.', 'D'))
prev = ''
for i in range(r):
	for j in range(c):
		if X[i][j] == 'W':
			if i > 0:
				if X[i - 1][j] == 'S':
					print('NO')
					sys.exit()
			if i < r - 1:
				if X[i + 1][j] == 'S':
					print('NO')
					sys.exit()
print('YES')
for i in X:
	print(i)


(n, m) = map(int, input().split())
g = [input() for i in range(n)]
for i in range(n):
	for j in range(m):
		if g[i][j] == 'W':
			if i > 0 and g[i - 1][j] == 'S' or (i < n - 1 and g[i + 1][j] == 'S') or (j > 0 and g[i][j - 1] == 'S') or (j < m - 1 and g[i][j + 1] == 'S'):
				print('No')
				exit()
print('Yes')
for i in range(n):
	print(g[i].replace('.', 'D'))


(n, m) = map(int, input().split())
l = []
for i in range(n):
	st = input()
	l1 = []
	for j in range(m):
		l1.append(st[j])
	l.append(l1)
h = 0
for i in range(1, n - 1):
	for j in range(1, m - 1):
		if l[i][j] == 'W':
			if l[i + 1][j] == 'S' or l[i][j + 1] == 'S' or l[i - 1][j] == 'S' or (l[i][j - 1] == 'S'):
				h = 1
				break
		if l[i][j] == 'S':
			if l[i + 1][j] == 'W' or l[i][j + 1] == 'W' or l[i - 1][j] == 'W' or (l[i][j - 1] == 'W'):
				h = 1
				break
qw = [0, -1]
for i in qw:
	for j in range(m - 1):
		if l[i][j] == 'W':
			if l[i][j + 1] == 'S':
				h = 1
		if l[i][j] == 'S':
			if l[i][j + 1] == 'W':
				h = 1
for j in qw:
	for i in range(n - 1):
		if l[i][j] == 'W':
			if l[i + 1][j] == 'S':
				h = 1
		if l[i][j] == 'S':
			if l[i + 1][j] == 'W':
				h = 1
if h == 1:
	print('NO')
else:
	print('YES')
	for i in range(n):
		for j in range(m):
			if l[i][j] == '.':
				print('D', end='')
			else:
				print(l[i][j], end='')
		print()


(R, C) = map(int, input().split())
cells = []
for i in range(R):
	cell = input()
	if 'SW' in cell or 'WS' in cell:
		print('NO')
		break
	cells.append(cell.replace('.', 'D'))
else:
	YN = True
	for i in range(C):
		if R == 1:
			break
		for j in range(R - 1):
			if cells[j][i] + cells[j + 1][i] == 'SW' or cells[j][i] + cells[j + 1][i] == 'WS':
				YN = False
				break
	if YN:
		print('Yes')
		for i in range(R):
			print(cells[i])
	else:
		print('NO')


(n, m) = map(int, input().split())
g = [input() for _ in range(n)]
mode = True
for i in range(n):
	for j in range(m):
		if g[i][j] == 'S':
			if i - 1 >= 0 and g[i - 1][j] == 'W':
				mode = 0
			if j - 1 >= 0 and g[i][j - 1] == 'W':
				mode = 0
			if i + 1 < n and g[i + 1][j] == 'W':
				mode = 0
			if j + 1 < m and g[i][j + 1] == 'W':
				mode = 0
if mode:
	print('Yes')
	print('\n'.join((''.join(('D' if v == '.' else v for v in row)) for row in g)))
else:
	print('No')


(R, C) = map(int, input().split())
a = list()
a = [input().replace('.', 'D') for i in range(R)]
flag = 'Yes'
for i in range(R):
	for j in range(C):
		if a[i][j] == 'S':
			if 'W' in (a[max(0, i - 1)][j], a[i][max(j - 1, 0)], a[min(i + 1, R - 1)][j], a[i][min(j + 1, C - 1)]):
				flag = 'No'
				break
print(flag)
if flag == 'Yes':
	for i in a:
		print(i)


(n, m) = map(int, input().split())
s = []
b = int(0)
for i in range(n):
	s.append(input().replace('.', 'D'))
for i in range(n):
	for j in range(m):
		if s[i][j] is 'S':
			if i > 0 and s[i - 1][j] is 'W':
				b = 1
			if i < n - 1 and s[i + 1][j] is 'W':
				b = 1
			if j > 0 and s[i][j - 1] is 'W':
				b = 1
			if j < m - 1 and s[i][j + 1] is 'W':
				b = 1
		if b is 1:
			break
	if b is 1:
		break
if b is 1:
	print('No')
	exit()
print('Yes')
for i in range(n):
	print(''.join(s[i]))


(row, col) = map(int, input().split())
l = [input().replace('.', 'D') for i in range(row)]
f = 1
for i in range(row):
	for j in range(col):
		if i > 0 and {l[i][j], l[i - 1][j]} == {'S', 'W'}:
			f = 0
		if j > 0 and {l[i][j], l[i][j - 1]} == {'S', 'W'}:
			f = 0
if f == 0:
	print('No')
else:
	print('Yes')
	print('\n'.join(l))


import sys, math, os.path
FILE_INPUT = 'A.in'
DEBUG = os.path.isfile(FILE_INPUT)
if DEBUG:
	sys.stdin = open(FILE_INPUT)

def ni():
	return map(int, input().split(' '))

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

def log(x):
	if DEBUG:
		print(x)
(r, c) = ni()
a = []

def check():
	for i in range(r):
		for j in range(c):
			if a[i][j] == 'W':
				if i > 0 and a[i - 1][j] == 'S':
					return False
				if i < r - 1 and a[i + 1][j] == 'S':
					return False
				if j > 0 and a[i][j - 1] == 'S':
					return False
				if j < c - 1 and a[i][j + 1] == 'S':
					return False
	return True
for i in range(r):
	s = input()
	a.append(s)
if check():
	print('Yes')
	for i in range(r):
		print(''.join(('D' if x == '.' else x for x in a[i])))
else:
	print('No')


def test_2():
	import math
	(r, c) = list(map(int, input().split(' ')))
	aa = []
	aa.append(list('.' * (c + 2)))
	for i in range(r):
		c_1 = list('.' + input() + '.')
		aa.append(c_1)
	aa.append(list('.' * (c + 2)))
	for i in range(1, r + 1):
		for j in range(1, c + 1):
			if aa[i][j] == 'S':
				bb = [aa[i][j + 1], aa[i][j - 1], aa[i + 1][j], aa[i - 1][j]]
				if 'W' in bb:
					print('No')
					return 0
				else:
					cc = ''.join([aa[i][j + 1], aa[i][j - 1], aa[i + 1][j], aa[i - 1][j]])
					cc = cc.replace('.', 'D')
					cc = list(cc)
					(aa[i][j + 1], aa[i][j - 1], aa[i + 1][j], aa[i - 1][j]) = cc
	print('Yes')
	cc = aa[1:-1]
	dd = []
	for c in cc:
		c = c[1:-1]
		print(''.join(c))
test_2()


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(input()))
for i in range(n):
	for j in range(m):
		if i + 1 < n and a[i][j] + a[i + 1][j] in ('SW', 'WS'):
			print('No')
			exit(0)
		if j + 1 < m and a[i][j] + a[i][j + 1] in ('SW', 'WS'):
			print('No')
			exit(0)
print('Yes')
for i in range(n):
	print(''.join(map(lambda x: x.replace('.', 'D'), a[i])))


(r, c) = list(map(int, input().split()))
a = []
(f, arr) = (0, [])
for i in range(r):
	arr.append(input())
for i in range(len(arr)):
	b = []
	for j in range(len(arr[i])):
		b.append(arr[i][j])
	a.append(b)
for i in range(r):
	for j in range(c):
		if a[i][j] == 'S':
			if i - 1 >= 0 and a[i - 1][j] == '.':
				a[i - 1][j] = 'D'
			elif i - 1 >= 0 and a[i - 1][j] == 'W':
				f = 1
				break
			if i + 1 < r and a[i + 1][j] == '.':
				a[i + 1][j] = 'D'
			elif i + 1 < r and a[i + 1][j] == 'W':
				f = 1
				break
			if j - 1 >= 0 and a[i][j - 1] == '.':
				a[i][j - 1] = 'D'
			elif j - 1 >= 0 and a[i][j - 1] == 'W':
				f = 1
				break
			if j + 1 < c and a[i][j + 1] == '.':
				a[i][j + 1] = 'D'
			elif j + 1 < c and a[i][j + 1] == 'W':
				f = 1
				break
if f == 1:
	print('No')
else:
	print('Yes')
	for i in range(r):
		print(''.join(a[i]))


(R, C) = map(int, input().strip().split())
pas = list()
for i in range(R):
	pas.append(list(input().strip()))
res = list(pas)
dr = [-1, 0, 1, 0]
dc = [0, 1, 0, -1]
for i in range(R):
	for j in range(C):
		if res[i][j] == 'W':
			for k in range(4):
				i2 = i + dr[k]
				j2 = j + dc[k]
				if 0 <= i2 < R and 0 <= j2 < C:
					if res[i2][j2] == '.':
						res[i2][j2] = 'D'
					elif res[i2][j2] == 'S':
						print('No')
						exit(0)
print('Yes')
for i in range(R):
	print(''.join(map(str, res[i])))


(r, c) = map(int, input().split())
a = []
f = 1
for i in range(r):
	a.append([x for x in input()])
for i in range(r):
	for j in range(c):
		if a[i][j] == 'S':
			if i - 1 >= 0:
				if a[i - 1][j] == 'W':
					f = 0
				elif a[i - 1][j] == '.':
					a[i - 1][j] = 'D'
			if i + 1 <= r - 1:
				if a[i + 1][j] == 'W':
					f = 0
				elif a[i + 1][j] == '.':
					a[i + 1][j] = 'D'
			if j - 1 >= 0:
				if a[i][j - 1] == 'W':
					f = 0
				elif a[i][j - 1] == '.':
					a[i][j - 1] = 'D'
			if j + 1 <= c - 1:
				if a[i][j + 1] == 'W':
					f = 0
				elif a[i][j + 1] == '.':
					a[i][j + 1] = 'D'
if f == 0:
	print('No')
else:
	print('Yes')
	for i in range(r):
		print(''.join(a[i]))


(r, c) = map(int, input().split())
arr = []
for i in range(r):
	s = input()
	xx = []
	for j in s:
		xx.append(j)
	arr.append(xx)
flag = True
for i in range(r):
	for j in range(1, c):
		if arr[i][j] == 'S' and arr[i][j - 1] == 'W':
			flag = False
			break
		if arr[i][j] == 'W' and arr[i][j - 1] == 'S':
			flag = False
			break
	if flag == False:
		break
for i in range(1, r):
	for j in range(c):
		if arr[i - 1][j] == 'S' and arr[i][j] == 'W':
			flag = False
			break
		if arr[i - 1][j] == 'W' and arr[i][j] == 'S':
			flag = False
			break
	if flag == False:
		break
if flag == False:
	print('No')
else:
	print('Yes')
	for i in range(r):
		for j in range(c):
			if arr[i][j] == '.':
				arr[i][j] = 'D'
	for i in range(r):
		for j in range(c):
			print(arr[i][j], end='')
		print()


(R, C) = list(map(int, input().split()))
layout = []
for i in range(R):
	layout.append(list(input()))
possible = True
for i in range(R):
	for j in range(C):
		if layout[i][j] == 'S':
			if i > 0:
				if layout[i - 1][j] == 'W':
					possible = False
				elif layout[i - 1][j] != 'S':
					layout[i - 1][j] = 'D'
			if j > 0:
				if layout[i][j - 1] == 'W':
					possible = False
				elif layout[i][j - 1] != 'S':
					layout[i][j - 1] = 'D'
			if i < R - 1:
				if layout[i + 1][j] == 'W':
					possible = False
				elif layout[i + 1][j] != 'S':
					layout[i + 1][j] = 'D'
			if j < C - 1:
				if layout[i][j + 1] == 'W':
					possible = False
				elif layout[i][j + 1] != 'S':
					layout[i][j + 1] = 'D'
			if not possible:
				break
	if not possible:
		break
if possible:
	print('Yes')
	for i in range(R):
		line = ''
		for j in range(C):
			line += str(layout[i][j])
		print(line)
else:
	print('No')


TN = 1

def dogs(lst, x, y, R, C):
	if x - 1 >= 0 and lst[x - 1][y] == '.':
		lst[x - 1][y] = 'D'
	elif x - 1 >= 0 and lst[x - 1][y] == 'W':
		return -1
	if x + 1 < C and lst[x + 1][y] == '.':
		lst[x + 1][y] = 'D'
	elif x + 1 < C and lst[x + 1][y] == 'W':
		return -1
	if y - 1 >= 0 and lst[x][y - 1] == '.':
		lst[x][y - 1] = 'D'
	elif y - 1 >= 0 and lst[x][y - 1] == 'W':
		return -1
	if y + 1 < R and lst[x][y + 1] == '.':
		lst[x][y + 1] = 'D'
	elif y + 1 < R and lst[x][y + 1] == 'W':
		return -1
	return lst

def solution():
	(R, C) = map(int, input().split())
	l = []
	for i in range(R):
		l.append(list(input()))
	ovc = []
	for i in range(R):
		for j in range(C):
			if l[i][j] == 'S':
				ovc.append([i, j])
	for (i, j) in ovc:
		l = dogs(l, i, j, C, R)
		if l == -1:
			print('No')
			break
	else:
		print('Yes')
		for i in range(R):
			print(''.join(l[i]))
while TN != 0:
	solution()
	TN -= 1


(a, b) = map(int, input().split())
ss = []
cs = True
for i in range(a):
	sr = input()
	sr = sr.replace('.', 'D')
	for j in range(b - 1):
		if sr[j] == 'S' and sr[j + 1] == 'W' or (sr[j] == 'W' and sr[j + 1] == 'S'):
			cs = False
		if i >= 1:
			if sr[j] == 'S' and ss[i - 1][j] == 'W' or (sr[j] == 'W' and ss[i - 1][j] == 'S'):
				cs = False
			elif j == b - 2 and (sr[j + 1] == 'S' and ss[i - 1][j + 1] == 'W') or (sr[j + 1] == 'W' and ss[i - 1][j + 1] == 'S'):
				cs = False
	ss.append(sr)
if cs:
	print('Yes')
	for i in range(a):
		print(ss[i])
else:
	print('No')


l1 = [int(x) for x in input().split()]
(rows, columns) = (l1[0], l1[1])
l1 = []
for x in range(rows):
	a = input()
	a = a.replace('.', 'D')
	l1.append(list(a))
ruined = 0
for x in range(rows):
	for y in range(columns):
		if l1[x][y] == 'W':
			if x != 0 and l1[x - 1][y] == 'S':
				ruined = 1
				break
			if x != rows - 1 and l1[x + 1][y] == 'S':
				ruined = 1
				break
			if y != 0 and l1[x][y - 1] == 'S':
				ruined = 1
				break
			if y != columns - 1 and l1[x][y + 1] == 'S':
				ruined = 1
				break
if not ruined:
	print('Yes')
	for x in l1:
		print(''.join(x))
else:
	print('No')


(r, c) = map(int, input().split())
strings = []
for i in range(r):
	strings.append([i if i != '.' else 'D' for i in input()])
for i in range(r):
	for j in range(c):
		if strings[i][j] == 'W':
			if i + 1 < r and strings[i + 1][j] == 'S' or (j + 1 < c and strings[i][j + 1] == 'S') or (i - 1 >= 0 and strings[i - 1][j] == 'S') or (j - 1 >= 0 and strings[i][j - 1] == 'S'):
				print('NO')
				exit()
print('YES')
for string in strings:
	print(''.join(string))


(x, y) = map(int, input().split())
lol = []
f = 0
for _ in range(x):
	a = input()
	a = a.replace('.', 'D')
	for i in range(1, y):
		if a[i] == 'S' and a[i - 1] == 'W' or (a[i - 1] == 'S' and a[i] == 'W'):
			f = 1
			break
	if f == 1:
		break
	lol.append(a)
if not f and len(lol) > 1:
	for i in range(x):
		for j in range(y):
			if i == 0:
				yo = [lol[i][j], lol[i + 1][j]]
			elif i == x - 1:
				yo = [lol[i][j], lol[i - 1][j]]
			else:
				yo = [lol[i][j], lol[i - 1][j], lol[i + 1][j]]
			if 'W' in yo and 'S' in yo and (lol[i][j] != 'D'):
				f = 1
				break
		if f:
			break
if f:
	print('NO')
else:
	print('YES')
	for i in lol:
		print(i)


(n, m) = map(int, input().split())
mas = []
z = 0

def toD(inp):
	if inp == '.':
		return 'D'
	return inp
for i in range(n):
	mas.append([toD(x) for x in input()])
for i in range(n):
	for j in range(m):
		if mas[i][j] == 'W':
			if j + 1 < m:
				if mas[i][j + 1] == 'S':
					z = 1
			if j - 1 >= 0:
				if mas[i][j - 1] == 'S':
					z = 1
			if i + 1 < n:
				if mas[i + 1][j] == 'S':
					z = 1
			if i - 1 >= 0:
				if mas[i - 1][j] == 'S':
					z = 1
if z == 1:
	print('No')
elif z == 0:
	print('Yes')
	for i in range(n):
		for j in range(m):
			print(mas[i][j], end='')
		print()


(n, m) = map(int, input().split())
F = [0] * (n + 2)
F[0] = [0] * (m + 2)
F[n + 1] = [0] * (m + 2)
for i in range(1, n + 1):
	F[i] = [0] + list(input()) + [0]
ans = True
for i in range(1, n + 1):
	for j in range(1, m + 1):
		if F[i][j] == 'W':
			if F[i - 1][j] == 'S' or F[i][j + 1] == 'S' or F[i + 1][j] == 'S' or (F[i][j - 1] == 'S'):
				ans = False
			if F[i - 1][j] == '.':
				F[i - 1][j] = 'D'
			if F[i][j + 1] == '.':
				F[i][j + 1] = 'D'
			if F[i + 1][j] == '.':
				F[i + 1][j] = 'D'
			if F[i][j - 1] == '.':
				F[i][j - 1] = 'D'
if ans:
	print('Yes')
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			print(F[i][j], end='')
		print()
else:
	print('No')


(n, m) = map(int, input().split(' '))
s = []
for i in range(n):
	s.append(list(input()))
ok = True
dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]
for i in range(n):
	for j in range(m):
		if s[i][j] == 'S':
			for k in range(4):
				x = i + dx[k]
				y = j + dy[k]
				if x >= 0 and x < n and (y >= 0) and (y < m):
					if s[x][y] == 'W':
						ok = False
					elif s[x][y] == '.':
						s[x][y] = 'D'
if ok:
	print('Yes')
	for i in range(n):
		print(''.join(s[i]))
else:
	print('No')


(r, c) = list(map(int, input().split()))
matrix = []
for i in range(r):
	matrix.append(list(input()))
is_safe = True
for i in range(r):
	for j in range(c):
		if i + 1 < r and (matrix[i][j] == 'W' and matrix[i + 1][j] == 'S' or (matrix[i][j] == 'S' and matrix[i + 1][j] == 'W')):
			is_safe = False
		if j + 1 < c and (matrix[i][j] == 'W' and matrix[i][j + 1] == 'S' or (matrix[i][j] == 'S' and matrix[i][j + 1] == 'W')):
			is_safe = False
for i in range(r):
	for j in range(c):
		if matrix[i][j] == 'W':
			if i - 1 >= 0 and matrix[i - 1][j] == '.':
				matrix[i - 1][j] = 'D'
			if i + 1 < r and matrix[i + 1][j] == '.':
				matrix[i + 1][j] = 'D'
			if j - 1 >= 0 and matrix[i][j - 1] == '.':
				matrix[i][j - 1] = 'D'
			if j + 1 < c and matrix[i][j + 1] == '.':
				matrix[i][j + 1] = 'D'
if is_safe:
	print('Yes')
	for l in matrix:
		print(''.join(l))
else:
	print('No')


(r, c) = map(int, input().split())
mat = []
flag = 0
for i in range(r):
	k = []
	s = input()
	for z in s:
		k.append(z)
	mat.append(k)
for i in range(r):
	for j in range(c):
		if mat[i][j] == 'W':
			if i - 1 >= 0:
				if mat[i - 1][j] == 'S':
					flag = 1
					break
				elif mat[i - 1][j] == '.':
					mat[i - 1][j] = 'D'
			if i + 1 < r:
				if mat[i + 1][j] == 'S':
					flag = 1
					break
				elif mat[i + 1][j] == '.':
					mat[i + 1][j] = 'D'
			if j - 1 >= 0:
				if mat[i][j - 1] == 'S':
					flag = 1
					break
				elif mat[i][j - 1] == '.':
					mat[i][j - 1] = 'D'
			if j + 1 < c:
				if mat[i][j + 1] == 'S':
					flag = 1
					break
				elif mat[i][j + 1] == '.':
					mat[i][j + 1] = 'D'
if flag == 1:
	print('No')
else:
	print('Yes')
	for i in mat:
		for j in i:
			print(j, end='')
		print()


(R, C) = [int(x) for x in input().split()]
matrix = []
for row in range(R):
	column = str(input())
	if column.count('SW') or column.count('WS'):
		print('NO')
		exit()
	column = column.replace('.', 'D')
	column = list(column)
	matrix.append(column)
	if row:
		for col in range(C):
			if matrix[row - 1][col] == 'S' and matrix[row][col] == 'W':
				print('NO')
				exit()
			elif matrix[row - 1][col] == 'W' and matrix[row][col] == 'S':
				print('NO')
				exit()
print('YES')
for i in matrix:
	print(''.join(i))


import sys
(r, c) = [int(x) for x in sys.stdin.readline().split()]
m = []
for i in range(r):
	m.append(sys.stdin.readline().replace('.', 'D').strip())
for i in range(r):
	for j in range(c):
		if m[i][j] == 'W':
			if i > 0:
				if m[i - 1][j] == 'S':
					print('No')
					sys.exit()
			if j > 0:
				if m[i][j - 1] == 'S':
					print('No')
					sys.exit()
			if i < r - 1:
				if m[i + 1][j] == 'S':
					print('No')
					sys.exit()
			if j < c - 1:
				if m[i][j + 1] == 'S':
					print('No')
					sys.exit()
print('Yes')
print('\n'.join(m))
sys.exit()


import sys
from math import sqrt, floor, factorial
from collections import deque, Counter
inp = sys.stdin.readline
read = lambda : list(map(int, inp().strip().split()))

def chk(lis, r, c, indx, indy):
	if not 0 <= indx <= r - 1:
		return False
	if not 0 <= indy <= c - 1:
		return False
	if lis[indx][c] == 'F':
		return False
	if lis[r][indy] == 'F':
		return False
	if lis[indx][c] == 'S':
		return (True,)
	if lis[r][indy] == 'S':
		return False

def solve():
	(r, c) = read()
	pasture = [None] * r
	flag = 1
	for row in range(r):
		pasture[row] = list(inp().strip())
		this = pasture[row]
		for (ind, elem) in enumerate(this):
			if elem == 'S':
				if ind + 1 <= c - 1:
					if this[ind + 1] == 'W':
						flag = 0
					elif this[ind + 1] == '.':
						this[ind + 1] = 'D'
				if 0 <= ind - 1:
					if this[ind - 1] == 'W':
						flag = 0
					elif this[ind - 1] == '.':
						this[ind - 1] = 'D'
	if flag:
		for col in range(c):
			for row in range(r):
				if pasture[row][col] == 'S':
					if row + 1 <= r - 1:
						if pasture[row + 1][col] == 'W':
							flag = 0
						elif pasture[row + 1][col] == '.':
							pasture[row + 1][col] = 'D'
					if 0 <= row - 1:
						if pasture[row - 1][col] == 'W':
							flag = 0
						elif pasture[row - 1][col] == '.':
							pasture[row - 1][col] = 'D'
		if flag:
			print('YES')
			for row in range(r):
				print(''.join(pasture[row]))
		else:
			print('NO')
	else:
		print('NO')
solve()


(n, m) = [int(x) for x in input().split()]
mat = []
for i in range(n):
	mat.append(input())
ok = True
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
f = lambda x, y, c, d: x >= 0 and y >= 0 and (x < c) and (y < d)
for i in range(n):
	for j in range(m):
		if mat[i][j] == 'S':
			for k in range(4):
				tx = i + dx[k]
				ty = j + dy[k]
				if f(tx, ty, n, m) == False:
					continue
				if mat[tx][ty] == 'W':
					ok = False
if ok:
	print('Yes')
	for i in range(n):
		mat[i] = mat[i].replace('.', 'D')
	for x in mat:
		print(x)
else:
	print('No')


(R, C) = map(int, input().split())
field = []
for _ in range(R):
	field.append(list(input()))

def not_out_of_range(i, j):
	if i < 0 or i >= R or j < 0 or (j >= C):
		return False
	else:
		return True
adj = [[0, 1], [0, -1], [1, 0], [-1, 0]]
for i in range(R):
	for j in range(C):
		if field[i][j] == 'S':
			for (di, dj) in adj:
				if not_out_of_range(i + di, j + dj):
					if field[i + di][j + dj] == 'W':
						print('No')
						quit()
					elif field[i + di][j + dj] == '.':
						field[i + di][j + dj] = 'D'
print('Yes')
for i in range(R):
	print(''.join(field[i]))


(rows, columns) = list(map(int, input().split()))
pasto = []
for _ in range(rows):
	pasto.append(list(input()))
for row in range(len(pasto)):
	for col in range(len(pasto[row])):
		valido = True
		if pasto[row][col] == 'W':
			row_min = row == 0
			row_max = row == len(pasto) - 1
			col_min = col == 0
			col_max = col == len(pasto[row]) - 1
			if not row_min:
				if pasto[row - 1][col] == 'S':
					valido = False
				if pasto[row - 1][col] == '.':
					pasto[row - 1][col] = 'D'
			if not row_max:
				if pasto[row + 1][col] == 'S':
					valido = False
				if pasto[row + 1][col] == '.':
					pasto[row + 1][col] = 'D'
			if not col_min:
				if pasto[row][col - 1] == 'S':
					valido = False
				if pasto[row][col - 1] == '.':
					pasto[row][col - 1] = 'D'
			if not col_max:
				if pasto[row][col + 1] == 'S':
					valido = False
				if pasto[row][col + 1] == '.':
					pasto[row][col + 1] = 'D'
		if not valido:
			break
	if not valido:
		break
if not valido:
	print('No')
else:
	print('Yes')
	for row in pasto:
		print(''.join(row))


z = lambda u: any((x in ''.join(y) for x in ['WS', 'SW'] for y in u))
(r, c) = map(int, input().split())
a = [input().replace('.', 'D') for _ in [0] * r]
if z(a) or z([*zip(*a)]):
	print('No')
else:
	print('Yes')
	for x in a:
		print(x)


import sys
import math
import bisect
import itertools
import random
import re

def solve(A):
	n = len(A)
	m = len(A[0])
	for i in range(n):
		for j in range(m):
			if A[i][j] == 'S':
				if i - 1 >= 0:
					if A[i - 1][j] == 'W':
						return False
				if i + 1 < n:
					if A[i + 1][j] == 'W':
						return False
				if j - 1 >= 0:
					if A[i][j - 1] == 'W':
						return False
				if j + 1 < m:
					if A[i][j + 1] == 'W':
						return False
	return True

def main():
	(n, m) = map(int, input().split())
	A = []
	for i in range(n):
		A.append(input())
	if solve(A) == False:
		print('No')
	else:
		print('Yes')
		for i in range(n):
			A[i] = re.sub('[.]', 'D', A[i])
			print(''.join(A[i]))
main()


pasture = [input() for _ in range(int(input().split()[0]))]
for row in pasture:
	if 'SW' in row or 'WS' in row:
		print('No')
		break
else:
	for column in map(''.join, zip(*pasture)):
		if 'SW' in column or 'WS' in column:
			print('No')
			break
	else:
		print('Yes')
		for row in pasture:
			print(row.replace('.', 'D'))


(n, m) = map(int, input().split())
field = [list(input()) for _ in range(n)]
for i in range(n):
	for j in range(m):
		if field[i][j] == 'S':
			if i > 0 and field[i - 1][j] == 'W':
				print('NO')
				exit(0)
			if j > 0 and field[i][j - 1] == 'W':
				print('NO')
				exit(0)
			if i < n - 1 and field[i + 1][j] == 'W':
				print('NO')
				exit(0)
			if j < m - 1 and field[i][j + 1] == 'W':
				print('NO')
				exit(0)
print('YES')
for l in field:
	for i in range(m):
		if l[i] == '.':
			l[i] = 'D'
	print(*l, sep='')


(n, m) = map(int, input().split())
field = []
for i in range(n):
	row = list(input())
	field.append(row)
can = True
for i in range(n):
	for j in range(m):
		if i > 0:
			if field[i][j] == 'S':
				if field[i - 1][j] == 'W':
					if can:
						print('No')
					can = False
					break
		if i < n - 1:
			if field[i][j] == 'S':
				if field[i + 1][j] == 'W':
					if can:
						print('No')
					can = False
					break
		if j > 0:
			if field[i][j] == 'S':
				if field[i][j - 1] == 'W':
					if can:
						print('No')
					can = False
					break
		if j < m - 1:
			if field[i][j] == 'S':
				if field[i][j + 1] == 'W':
					if can:
						print('No')
					can = False
					break
if can:
	print('Yes')
	for i in range(n):
		for j in field[i]:
			if j == '.':
				print('D', end='')
			else:
				print(j, end='')
		print()


(r, c) = map(int, input().split())
arr = []
for _ in range(r):
	arr.append(list(input()))
flag = True
for i in range(r):
	if flag:
		for j in range(c):
			if arr[i][j] == 'S':
				if j + 1 < c and arr[i][j + 1] == 'W':
					print('NO')
					flag = False
					break
				elif j - 1 >= 0 and arr[i][j - 1] == 'W':
					print('NO')
					flag = False
					break
				elif i - 1 >= 0 and arr[i - 1][j] == 'W':
					print('NO')
					flag = False
					break
				if i + 1 < r and arr[i + 1][j] == 'W':
					print('NO')
					flag = False
					break
if flag == True:
	print('YES')
	for i in range(r):
		for j in range(c):
			if arr[i][j] == '.':
				arr[i][j] = 'D'
			print(arr[i][j], end='')
		print()


(R, C) = map(int, input().split())
T = [[] for i in range(R)]
for i in range(R):
	a = list(input())
	T[i] = a
for i in range(R):
	for j in range(C):
		if T[i][j] == 'S':
			for (dx, dy) in [(0, 1), (1, 0), (-1, 0), (0, -1)]:
				(nx, ny) = (i + dx, j + dy)
				if not (0 <= nx < R and 0 <= ny < C):
					continue
				elif T[nx][ny] == 'W':
					print('No')
					exit()
				elif T[nx][ny] == '.':
					T[nx][ny] = 'D'
print('Yes')
for i in range(R):
	print(''.join(T[i]))


(n, m) = map(int, input().split())
g = []
for w in range(n):
	g.append([i for i in input()])
f = 0
for i in range(n):
	if f == 1:
		break
	for j in range(m):
		if g[i][j] == 'W':
			if i + 1 < n:
				if g[i + 1][j] == 'S':
					f = 1
				elif g[i + 1][j] != 'W':
					g[i + 1][j] = 'D'
			if j + 1 < m:
				if g[i][j + 1] == 'S':
					f = 1
				elif g[i][j + 1] != 'W':
					g[i][j + 1] = 'D'
			if i - 1 > -1:
				if g[i - 1][j] == 'S':
					f = 1
				elif g[i - 1][j] != 'W':
					g[i - 1][j] = 'D'
			if j - 1 > -1:
				if g[i][j - 1] == 'S':
					f = 1
				elif g[i][j - 1] != 'W':
					g[i][j - 1] = 'D'
		if f == 1:
			break
if f == 1:
	print('No')
else:
	print('Yes')
	for i in range(n):
		for j in range(m):
			print(g[i][j], end='')
		print()


import sys
(n, m) = map(int, input().split())
arr = []
for _ in range(n):
	arr.append(list(input().replace('.', 'D')))
brr = ['S', 'W']
for i in range(n):
	for j in range(m - 1):
		if sorted([arr[i][j], arr[i][j + 1]]) == brr:
			print('No')
			sys.exit()
for i in range(m):
	for j in range(n - 1):
		if sorted([arr[j][i], arr[j + 1][i]]) == brr:
			print('No')
			sys.exit()
print('Yes')
for i in range(n):
	print(*arr[i], sep='')


import sys
input = sys.stdin.readline

def solve(r, c, mat):
	for i in range(r):
		row = mat[i]
		for j in range(c):
			if row[j] == '.':
				row[j] = 'D'
	for i in range(r):
		row = mat[i]
		for j in range(c):
			if row[j] == 'W':
				for (di, dj) in [(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)]:
					if 0 <= di < r and 0 <= dj < c and (mat[di][dj] == 'S'):
						return False
	return True
(r, c) = map(int, input().split())
mat = []
for _ in range(r):
	mat.append(list(input().rstrip()))
if solve(r, c, mat):
	print('Yes')
	for r in mat:
		print(''.join(r))
else:
	print('No')


(n, m) = [int(x) for x in input().split()]
mat = []
for _ in range(n):
	mat.append(list(input()))

def adj(i, j):
	for (i2, j2) in [(i + 1, j), (i - 1, j), (i, j - 1), (i, j + 1)]:
		if 0 <= i2 < n and 0 <= j2 < m:
			yield (i2, j2)
for i in range(n):
	for j in range(m):
		if mat[i][j] == 'S':
			for (i2, j2) in adj(i, j):
				if mat[i2][j2] == 'W':
					print('No')
					exit(0)
				elif mat[i2][j2] == '.':
					mat[i2][j2] = 'D'
print('Yes')
for i in range(n):
	print(''.join(mat[i]))