Student Andrey has been skipping physical education lessons for the whole term, and now he must somehow get a passing grade on this subject. Obviously, it is impossible to do this by legal means, but Andrey doesn't give up. Having obtained an empty certificate from a local hospital, he is going to use his knowledge of local doctor's handwriting to make a counterfeit certificate of illness. However, after writing most of the certificate, Andrey suddenly discovered that doctor's signature is impossible to forge. Or is it?

For simplicity, the signature is represented as an $n\times m$ grid, where every cell is either filled with ink or empty. Andrey's pen can fill a $3\times3$ square without its central cell if it is completely contained inside the grid, as shown below. 

xxx

x.x

xxx

 

Determine whether is it possible to forge the signature on an empty $n\times m$ grid.


-----Input-----

The first line of input contains two integers $n$ and $m$ ($3 \le n, m \le 1000$).

Then $n$ lines follow, each contains $m$ characters. Each of the characters is either '.', representing an empty cell, or '#', representing an ink filled cell.


-----Output-----

If Andrey can forge the signature, output "YES". Otherwise output "NO".

You can print each letter in any case (upper or lower).


-----Examples-----
Input
3 3
###
#.#
###

Output
YES
Input
3 3
###
###
###

Output
NO
Input
4 3
###
###
###
###

Output
YES
Input
5 7
.......
.#####.
.#.#.#.
.#####.
.......

Output
YES


-----Note-----

In the first sample Andrey can paint the border of the square with the center in $(2, 2)$.

In the second sample the signature is impossible to forge.

In the third sample Andrey can paint the borders of the squares with the centers in $(2, 2)$ and $(3, 2)$:   we have a clear paper: 

...

...

...

...

  use the pen with center at $(2, 2)$. 

###

#.#

###

...

  use the pen with center at $(3, 2)$. 

###

###

###

###

 

In the fourth sample Andrey can paint the borders of the squares with the centers in $(3, 3)$ and $(3, 5)$.

Difficulty: EASY
Tags: Implementation
Expected Time Complexity: O(N^2)

Starter code:

Solutions:
(n, m) = map(int, input().split())
a = [0] * n
for i in range(n):
	a[i] = input()
ans = ['.'] * n
for i in range(n):
	ans[i] = ['.'] * m
for i in range(1, n - 1):
	for j in range(1, m - 1):
		if a[i - 1][j - 1] == '#' and a[i - 1][j] == '#' and (a[i - 1][j + 1] == '#') and (a[i][j - 1] == '#') and (a[i][j + 1] == '#'):
			if a[i + 1][j - 1] == '#' and a[i + 1][j] == '#' and (a[i + 1][j + 1] == '#'):
				ans[i - 1][j - 1] = '#'
				ans[i + 1][j - 1] = '#'
				ans[i + 1][j] = '#'
				ans[i + 1][j + 1] = '#'
				ans[i - 1][j] = '#'
				ans[i - 1][j + 1] = '#'
				ans[i][j - 1] = '#'
				ans[i][j + 1] = '#'
for i in range(n):
	for j in range(m):
		if a[i][j] != ans[i][j]:
			print('NO')
			exit()
print('YES')


(n, m) = map(int, input().split())
s = []
st = set()
cst = set()
for i in range(n):
	s.append(input())
	for j in range(len(s[i])):
		if s[i][j] == '#':
			st.add((i, j))
for i in range(1, n - 1):
	for j in range(1, m - 1):
		if s[i - 1][j - 1] != '#':
			continue
		if s[i - 1][j] != '#':
			continue
		if s[i - 1][j + 1] != '#':
			continue
		if s[i][j - 1] != '#':
			continue
		if s[i][j + 1] != '#':
			continue
		if s[i + 1][j - 1] != '#':
			continue
		if s[i + 1][j] != '#':
			continue
		if s[i + 1][j + 1] != '#':
			continue
		cst.add((i - 1, j))
		cst.add((i - 1, j - 1))
		cst.add((i - 1, j + 1))
		cst.add((i + 1, j))
		cst.add((i + 1, j - 1))
		cst.add((i + 1, j + 1))
		cst.add((i, j + 1))
		cst.add((i, j - 1))
if len(cst) == len(st):
	print('YES')
else:
	print('NO')


s = input().split()
n = int(s[0])
m = int(s[1])
mat = []
vis = [[0 for i in range(1005)] for j in range(1005)]

def check(x, y):
	if x < 0 or x >= n or y < 0 or (y >= m):
		return False
	return mat[x][y] == '#'
dx = (0, 0, 1, 1, -1, -1, -1, 1)
dy = (1, -1, 1, -1, 1, -1, 0, 0)

def judge(x, y):
	for i in range(8):
		if not check(x + dx[i], y + dy[i]):
			return False
	for i in range(8):
		vis[x + dx[i]][y + dy[i]] = 1
	return True

def solve():
	for i in range(n):
		for j in range(m):
			judge(i, j)
	for i in range(n):
		for j in range(m):
			if mat[i][j] == '#' and (not vis[i][j]):
				return False
	return True
for i in range(n):
	s = input()
	mat.append(s)
if solve():
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
a = []
b = []
for i in range(n):
	a.append(list(input()))
	b.append(list('.' * m))
for i in range(1, n - 1):
	for j in range(1, m - 1):
		if a[i - 1][j - 1] != '.' and a[i - 1][j] != '.' and (a[i - 1][j + 1] != '.') and (a[i][j - 1] != '.') and (a[i][j + 1] != '.') and (a[i + 1][j - 1] != '.') and (a[i + 1][j] != '.') and (a[i + 1][j + 1] != '.'):
			b[i - 1][j - 1] = '#'
			b[i - 1][j] = '#'
			b[i - 1][j + 1] = '#'
			b[i][j - 1] = '#'
			b[i][j + 1] = '#'
			b[i + 1][j - 1] = '#'
			b[i + 1][j] = '#'
			b[i + 1][j + 1] = '#'
for i in range(n):
	for j in range(m):
		if a[i][j] != b[i][j]:
			print('NO')
			exit()
print('YES')


def isValid(field, y, x):
	for i in range(3):
		for j in range(3):
			if i == 1 and j == 1:
				continue
			if field[y + i][x + j] == '.':
				return False
	return True

def fill(field, y, x):
	for i in range(3):
		for j in range(3):
			if i == 1 and j == 1:
				continue
			cur[y + i][x + j] = '#'
(n, m) = list(map(int, input().split()))
sig = []
cur = []
for i in range(n):
	sig += [list(input())]
	cur += [['.'] * m]
for i in range(n - 2):
	for j in range(m - 2):
		if isValid(sig, i, j):
			fill(cur, i, j)
if sig == cur:
	print('YES')
else:
	print('NO')


(n, m) = [int(i) for i in input().split()]
a = []
b = []
a.append('.' * (m + 4))
a.append('.' * (m + 4))
b.append([0 for i in range(m + 4)])
b.append([0 for i in range(m + 4)])
t = False
for i in range(n):
	s = input()
	a.append('..' + s + '..')
	b.append([0 for i in range(m + 4)])
a.append('.' * (m + 4))
a.append('.' * (m + 4))
b.append([0 for i in range(m + 4)])
b.append([0 for i in range(m + 4)])
for i in range(2, n + 2):
	if t:
		break
	for j in range(2, m + 2):
		if a[i][j] == '#':
			if a[i][j + 1] == '#' and a[i][j + 2] == '#' and (a[i + 1][j + 2] == '#') and (a[i + 2][j + 2] == '#') and (a[i + 2][j + 1] == '#') and (a[i + 2][j] == '#') and (a[i + 1][j] == '#'):
				b[i][j] += 1
				b[i][j + 1] += 1
				b[i][j + 2] += 1
				b[i + 1][j + 2] += 1
				b[i + 2][j + 2] += 1
				b[i + 2][j + 1] += 1
				b[i + 2][j] += 1
				b[i + 1][j] += 1
			elif b[i][j] == 0:
				t = True
				break
if t:
	print('NO')
else:
	print('YES')


def goodsurroound(row, col):
	for i in range(-1, 2):
		for j in range(-1, 2):
			if i == j == 0:
				continue
			if podp[row + i][col + j] != '#':
				return False
	return True

def wrong(row, col, podp):
	for i in range(max(-1, 1 - row), min(2, n - row - 1)):
		for j in range(max(-1, 1 - col), min(2, m - col - 1)):
			if i == j == 0:
				continue
			if goodsurroound(row + i, col + j):
				return False
	return True
(n, m) = list(map(int, input().split()))
podp = [''] * n
for a in range(n):
	podp[a] = input().strip()
for row in range(n):
	for col in range(m):
		if podp[row][col] == '#':
			if wrong(row, col, podp):
				print('NO')
				exit()
print('YES')


(n, m) = [int(x) for x in input().split()]
mat = []
v = []
for i in range(n):
	mat.append([x == '#' for x in input()])
	v.append([False] * m)

def check(m, v, x, y):
	for i in (-1, 0, 1):
		for j in (-1, 0, 1):
			if (i, j) == (0, 0):
				continue
			if not m[x + i][y + j]:
				return
	for i in (-1, 0, 1):
		for j in (-1, 0, 1):
			if (i, j) != (0, 0):
				v[x + i][y + j] = True
for x in range(1, n - 1):
	for y in range(1, m - 1):
		check(mat, v, x, y)
flag = True
for i in range(0, n):
	for j in range(0, m):
		if mat[i][j] and (not v[i][j]):
			flag = False
if flag:
	print('YES')
else:
	print('NO')


global n, m, matrix

def check_avail(y, x):
	for i in [-1, 1, 0]:
		for z in [-1, 1, 0]:
			if not (-1 < y + i < n and -1 < x + z < m) or (matrix[y + i][x + z] == 0 and (i != 0 or z != 0)):
				return False
	return True

def fill_matrix(y, x):
	for i in [-1, 1, 0]:
		for z in [-1, 1, 0]:
			if i != 0 or z != 0:
				matrix[y + i][x + z] = 2
(n, m) = list(map(int, input().split()))
matrix = [[0 for p in range(m)] for q in range(n)]
for y in range(n):
	x = 0
	string = str(input())
	for i in string:
		if i == '.':
			matrix[y][x] = 0
		else:
			matrix[y][x] = 1
		x += 1
for y in range(n):
	for x in range(m):
		if check_avail(y, x):
			fill_matrix(y, x)
for y in range(n):
	for x in range(m):
		if matrix[y][x] == 1:
			print('NO')
			exit(0)
print('YES')
exit(0)


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(input())
b = [['.' for i in range(m)] for i in range(n)]
for i in range(n - 2):
	for j in range(m - 2):
		if a[i][j] == '#' and a[i][j + 1] == '#' and (a[i][j + 2] == '#') and (a[i + 1][j] == '#') and (a[i + 2][j + 1] == '#') and (a[i + 1][j + 2] == '#') and (a[i + 2][j] == '#') and (a[i + 2][j + 2] == '#'):
			for k in range(3):
				for w in range(3):
					if k != 1 or w != 1:
						b[i + k][j + w] = '#'
flag = 0
for i in range(n):
	s = ''.join(b[i])
	if a[i] != s:
		flag = 1
		break
if flag:
	print('NO')
else:
	print('YES')


(a, b) = map(int, input().split())
z = []
z1 = []
for _ in ' ' * a:
	z += [list(map(str, input().replace('', ' ').split()))]
	z1 += [['.'] * b]
for i in range(a - 2):
	for j in range(b - 2):
		ans = True
		for x in range(3):
			for y in range(3):
				if x == 1 and y == 1:
					continue
				if z[i + x][j + y] == '.':
					ans = False
		if ans:
			for x in range(3):
				for y in range(3):
					if x == 1 and y == 1:
						continue
					z1[i + x][j + y] = '#'
if z == z1:
	exit(print('YES'))
print('NO')


(n, m) = map(int, input().split())
a = [input() for _ in [0] * n]
b = [*map(list, a)]
p = ((0, 0), (0, 1), (0, 2), (1, 0), (1, 2), (2, 0), (2, 1), (2, 2))
for i in range(n - 2):
	for j in range(m - 2):
		if all((a[i + k][j + l] == '#' for (k, l) in p)):
			for (k, l) in p:
				b[i + k][j + l] = '.'
print('YNEOS'[any(('#' in x for x in b))::2])


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

def is_painted(i, j):
	for k in range(i - 1, i + 2):
		for l in range(j - 1, j + 2):
			if k == i and l == j:
				continue
			if arr[k][l] != '#':
				return False
	return True

def is_possible():
	narr = [['.'] * m for i in range(n)]
	for i in range(1, n - 1):
		for j in range(1, m - 1):
			if is_painted(i, j):
				for k in range(i - 1, i + 2):
					for l in range(j - 1, j + 2):
						if k == i and l == j:
							continue
						narr[k][l] = '#'
	for i in range(n):
		for j in range(m):
			if narr[i][j] != arr[i][j]:
				return False
	return True
print('YES' if is_possible() else 'NO')


(n, m) = map(int, input().split())
a = []
b = [['.' for i in range(m)] for j in range(n)]
for i in range(n):
	a.append(list(input()))
f = 0
for i in range(n - 2):
	for j in range(m - 2):
		if a[i][j] == '#' and a[i + 1][j] == '#' and (a[i + 2][j] == '#') and (a[i][j + 1] == '#') and (a[i + 2][j + 1] == '#') and (a[i][j + 2] == '#') and (a[i + 1][j + 2] == '#') and (a[i + 2][j + 2] == '#'):
			b[i][j] = '#'
			b[i + 1][j] = '#'
			b[i + 2][j] = '#'
			b[i][j + 1] = '#'
			b[i + 2][j + 1] = '#'
			b[i][j + 2] = '#'
			b[i + 1][j + 2] = '#'
			b[i + 2][j + 2] = '#'
if a == b:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
signature = []
for row in range(n):
	signature.append(list(input()))
adjacencies = {(i, j): 0 for i in range(1, n - 1) for j in range(1, m - 1)}
filled = {}
for row in range(n):
	for col in range(m):
		if signature[row][col] == '#':
			filled[row, col] = 0
			for i in range(-1, 2):
				for j in range(-1, 2):
					if (i, j) != (0, 0) and (row + i, col + j) in adjacencies:
						adjacencies[row + i, col + j] += 1
						if adjacencies[row + i, col + j] == 8:
							for k in range(-1, 2):
								for l in range(-1, 2):
									if (k, l) != (0, 0) and (row + i + k, col + j + l) in filled:
										filled[row + i + k, col + j + l] = 1
		elif signature[row][col] == '.':
			for i in range(-1, 2):
				for j in range(-1, 2):
					if (i, j) != (0, 0) and (row + i, col + j) in adjacencies:
						del adjacencies[row + i, col + j]
if 0 in filled.values():
	print('NO')
else:
	print('YES')


(n, m) = list(map(int, input().split()))
cl = []
for i in range(n):
	cl.append(input())

def is_squad(x, y):
	if cl[x][y] == '#' and cl[x + 1][y] == '#' and (cl[x + 2][y] == '#') and (cl[x + 2][y + 1] == '#') and (cl[x + 2][y + 2] == '#') and (cl[x + 1][y + 2] == '#') and (cl[x][y + 2] == '#') and (cl[x][y + 1] == '#'):
		return True
	else:
		return False

def cv(x, y):
	counter = 0
	if x - 2 >= 0 and y + 2 <= m - 1 and is_squad(x - 2, y):
		return True
	elif x - 1 >= 0 and x + 1 <= n - 1 and (y + 2 <= m - 1) and is_squad(x - 1, y):
		return True
	elif x + 2 <= n - 1 and y + 2 <= m - 1 and is_squad(x, y):
		return True
	elif x + 2 <= n - 1 and y + 1 <= m - 1 and (y - 1 >= 0) and is_squad(x, y - 1):
		return True
	elif x + 2 <= n - 1 and y - 2 >= 0 and is_squad(x, y - 2):
		return True
	elif x + 1 <= n - 1 and x - 1 >= 0 and (y - 2 >= 0) and is_squad(x - 1, y - 2):
		return True
	elif x - 2 >= 0 and y - 2 >= 0 and is_squad(x - 2, y - 2):
		return True
	elif x - 2 >= 0 and y - 1 >= 0 and (y + 1 <= m - 1) and is_squad(x - 2, y - 1):
		return True
	else:
		return False
for i in range(n):
	for j in range(m):
		if cl[i][j] == '#':
			if not cv(i, j):
				print('NO')
				return
print('YES')


(n, m) = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
	a[i] = list(input())
	b[i] = a[i].copy()
for i in range(n - 2):
	for j in range(m - 2):
		if a[i][j] == '#' and a[i + 1][j] == '#' and (a[i + 2][j] == '#') and (a[i + 2][j + 1] == '#') and (a[i + 2][j + 2] == '#') and (a[i + 1][j + 2] == '#') and (a[i][j + 2] == '#') and (a[i][j + 1] == '#'):
			b[i][j] = b[i + 1][j] = b[i + 2][j] = b[i + 2][j + 1] = b[i + 2][j + 2] = b[i + 1][j + 2] = b[i][j + 2] = b[i][j + 1] = '.'
for i in range(n):
	for j in range(m):
		if b[i][j] == '#':
			print('NO')
			exit(0)
print('YES')


(N, M) = map(int, input().split())
grid = []
for _ in range(N):
	grid.append(list(input()))

def check(grid, i, j, sx, sy):
	if i - sx >= 0 and j - sy >= 0 and (i + 2 - sx < N) and (j + 2 - sy < M):
		i -= sx
		j -= sy
		v = grid[i][j] == '#' and grid[i + 1][j] == '#' and (grid[i + 2][j] == '#') and (grid[i][j + 1] == '#') and (grid[i + 2][j + 1] == '#') and (grid[i][j + 2] == '#') and (grid[i + 1][j + 2] == '#') and (grid[i + 2][j + 2] == '#')
		return v
	return False
prev = False
for m in range(M):
	for n in range(N):
		if grid[n][m] == '#':
			if not (check(grid, n, m, 0, 0) or check(grid, n, m, 1, 0) or check(grid, n, m, 2, 0) or check(grid, n, m, 0, 1) or check(grid, n, m, 2, 1) or check(grid, n, m, 0, 2) or check(grid, n, m, 1, 2) or check(grid, n, m, 2, 2)):
				print('NO')
				exit(0)
print('YES')


import sys
import copy
lines = iter(sys.stdin)

def nexts():
	return next(lines)

def nextint():
	return int(nexts())

def snexts():
	return next(lines).split(' ')

def snextint():
	return map(int, snexts())

def array(length, base=0):
	return [base] * length

def matrix(length, width, base=0):
	return [[base] * width for _ in range(length)]
(n, m) = snextint()
grid = array(n, [])
for i in range(n):
	grid[i] = list(nexts())
grid2 = copy.deepcopy(grid)
for i in range(1, n - 1):
	for j in range(1, m - 1):
		if grid[i - 1][j] == '#' and grid[i - 1][j + 1] == '#' and (grid[i][j + 1] == '#') and (grid[i + 1][j + 1] == '#') and (grid[i + 1][j] == '#') and (grid[i + 1][j - 1] == '#') and (grid[i][j - 1] == '#') and (grid[i - 1][j - 1] == '#'):
			grid2[i - 1][j] = '.'
			grid2[i - 1][j + 1] = '.'
			grid2[i][j + 1] = '.'
			grid2[i + 1][j + 1] = '.'
			grid2[i + 1][j] = '.'
			grid2[i + 1][j - 1] = '.'
			grid2[i][j - 1] = '.'
			grid2[i - 1][j - 1] = '.'
match = True
for i in grid2:
	for ch in i:
		if ch == '#':
			match = False
			break
if match:
	print('YES')
else:
	print('NO')


def main():
	(n, m) = map(int, input().split())
	grid = [list(input()) for i in range(n)]
	cnt = [[0] * m for i in range(n)]
	for i in range(1, n - 1):
		for j in range(1, m - 1):
			need = True
			for k in range(i - 1, i + 2):
				for l in range(j - 1, j + 2):
					if 0 <= k < n and 0 <= l < m and (grid[k][l] == '#' or (i == k and j == l)):
						continue
					need = False
			if not need:
				continue
			for k in range(i - 1, i + 2):
				for l in range(j - 1, j + 2):
					if i != k or j != l:
						cnt[k][l] += 1
	for i in range(n):
		for j in range(m):
			if grid[i][j] == '#' and (not cnt[i][j]):
				print('NO')
				exit()
	print('YES')
main()


import math as ma
import sys
from sys import exit
from decimal import Decimal as dec
from itertools import permutations

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

def modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x

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

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
(n, m) = num()
a = [0] * n
for i in range(n):
	a[i] = [0] * m
for i in range(n):
	s = input()
	for j in range(m):
		a[i][j] = s[j]
z = ['.'] * n
for i in range(n):
	z[i] = ['.'] * m
for i in range(n):
	for j in range(m):
		if j - 1 >= 0 and j + 1 < m and (i + 1 < n) and (i - 1 >= 0):
			if a[i - 1][j] == '#' and a[i + 1][j] == '#' and (a[i][j - 1] == '#') and (a[i][j + 1] == '#') and (a[i - 1][j - 1] == '#') and (a[i - 1][j + 1] == '#') and (a[i + 1][j - 1] == '#') and (a[i + 1][j + 1] == '#'):
				z[i - 1][j] = '#'
				z[i + 1][j] = '#'
				z[i][j - 1] = '#'
				z[i][j + 1] = '#'
				z[i - 1][j - 1] = '#'
				z[i - 1][j + 1] = '#'
				z[i + 1][j - 1] = '#'
				z[i + 1][j + 1] = '#'
ff = True
for i in range(n):
	for j in range(m):
		if z[i][j] != a[i][j]:
			ff = False
			break
if ff:
	print('YES')
else:
	print('NO')


def color8(i, j, ip):
	if i > n - 3 or j > m - 3:
		return
	else:
		ip[i][j] = '#'
		ip[i][j + 1] = '#'
		ip[i][j + 2] = '#'
		ip[i + 1][j] = '#'
		ip[i + 1][j + 2] = '#'
		ip[i + 2][j] = '#'
		ip[i + 2][j + 1] = '#'
		ip[i + 2][j + 2] = '#'
(n, m) = list(map(int, input().split()))
ip = []
op = [['.' for i in range(m)] for j in range(n)]
b = 0
for i in range(n):
	ip.append(str(input()))
for i in range(n):
	for j in range(m):
		if ip[i][j] == '#':
			try:
				if ip[i + 2][j + 2] == '#':
					temp = ip[i][j] == '#' and ip[i][j + 1] == '#' and (ip[i][j + 2] == '#') and (ip[i + 1][j] == '#') and (ip[i + 1][j + 2] == '#') and (ip[i + 2][j] == '#') and (ip[i + 2][j + 1] == '#') and (ip[i + 2][j + 2] == '#')
					if temp == True:
						color8(i, j, op)
			except:
				pass
for i in range(n):
	if ''.join(op[i]) != ip[i]:
		print('NO')
		b = 1
		break
if b == 0:
	print('YES')


(n, m) = map(int, input().split())
rows = []
for i in range(n):
	rows.append(input())
copy = rows[:]
for i in range(n - 2):
	for j in range(m - 2):
		if rows[i][j:j + 3] == '###':
			if rows[i + 2][j:j + 3] == '###':
				if rows[i + 1][j] == '#':
					if rows[i + 1][j + 2] == '#':
						copy[i] = copy[i][:j] + 'aaa' + copy[i][j + 3:]
						copy[i + 1] = copy[i + 1][:j] + 'a' + copy[i + 1][j + 1] + 'a' + copy[i + 1][j + 3:]
						copy[i + 2] = copy[i + 2][:j] + 'aaa' + copy[i + 2][j + 3:]
done = False
for i in range(n):
	if done:
		break
	for j in range(m):
		if rows[i][j] == '#' and copy[i][j] != 'a':
			print('NO')
			done = True
			break
if not done:
	print('YES')


import sys
(n, m) = map(int, input().split())
l = []
for i in range(n):
	s = input()
	l.append(s)
arr = [[0 for x in range(m)] for k in range(n)]
for i in range(1, n - 1):
	for j in range(1, m - 1):
		if l[i][j + 1] == '#' and l[i][j - 1] == '#':
			if l[i - 1][j] == '#' and l[i + 1][j] == '#':
				if l[i - 1][j + 1] == '#' and l[i - 1][j - 1] == '#':
					if l[i + 1][j + 1] == '#' and l[i + 1][j - 1] == '#':
						arr[i][j + 1] = 1
						arr[i][j - 1] = 1
						arr[i - 1][j + 1] = 1
						arr[i - 1][j - 1] = 1
						arr[i + 1][j + 1] = 1
						arr[i + 1][j - 1] = 1
						arr[i - 1][j] = 1
						arr[i + 1][j] = 1
for i in range(n):
	for j in range(m):
		if l[i][j] == '#':
			if arr[i][j] == 1:
				continue
			else:
				print('NO')
				sys.exit(0)
print('YES')


(n, m) = map(int, input().split())
di = {}
res = {}
for i in range(n):
	di[i] = {}
	res[i] = {}
	q = input()
	for (j, x) in enumerate(q):
		di[i][j] = x
		res[i][j] = '.'
for i in range(1, n - 1):
	for j in range(1, m - 1):
		e = 0
		(a, b, c, d) = (i - 1, i + 1, j - 1, j + 1)
		if di[a][c] == '#':
			e += 1
		if di[a][j] == '#':
			e += 1
		if di[a][d] == '#':
			e += 1
		if di[i][c] == '#':
			e += 1
		if di[i][d] == '#':
			e += 1
		if di[b][c] == '#':
			e += 1
		if di[b][j] == '#':
			e += 1
		if di[b][d] == '#':
			e += 1
		if e == 8:
			res[a][c] = '#'
			res[a][j] = '#'
			res[a][d] = '#'
			res[i][c] = '#'
			res[i][d] = '#'
			res[b][c] = '#'
			res[b][j] = '#'
			res[b][d] = '#'
if res == di:
	print('YES')
else:
	print('NO')


(n, m) = list(map(int, input().split()))
(maps, visited) = ([], [])
for i in range(n):
	cur = input().strip()
	maps.append(cur)
	map_cur = [1 if item == '#' else 0 for item in cur]
	visited.append(map_cur)
for i in range(1, n - 1):
	for j in range(1, m - 1):
		cur = 0
		for u in range(-1, 2):
			for v in range(-1, 2):
				if u == 0 and v == 0:
					continue
				if maps[i + u][j + v] == '#':
					cur += 1
		if cur < 8:
			continue
		for u in range(-1, 2):
			for v in range(-1, 2):
				if u == 0 and v == 0:
					continue
				visited[i + u][j + v] = 0
can = True
for i in range(n):
	for j in range(m):
		if visited[i][j] == 1:
			can = False
			break
if can:
	print('YES')
else:
	print('NO')


from sys import stdin

def arr_inp(n):
	if n == 1:
		return [int(x) for x in stdin.readline().split()]
	elif n == 2:
		return [float(x) for x in stdin.readline().split()]
	else:
		return list(stdin.readline()[:-1])
(n, m) = arr_inp(1)
(maze, ans) = ([arr_inp(3) for i in range(n)], [['.' for i in range(m)] for j in range(n)])
for i in range(n - 2):
	for j in range(m - 2):
		co = 0
		for r in range(3):
			for c in range(3):
				if r == 1 and c == 1:
					continue
				if maze[i + r][j + c] == '#':
					co += 1
		if co == 8:
			for r in range(3):
				for c in range(3):
					if r == 1 and c == 1:
						continue
					if maze[i + r][j + c] == '#':
						ans[i + r][j + c] = '#'
print('YES' if ans == maze else 'NO')


(n, m) = [int(s) for s in input().split()]
gr = []
cs = [(-1, -1), (0, -1), (1, -1), (-1, 0), (1, 0), (-1, 1), (0, 1), (1, 1)]
for i in range(n):
	gr.append(list(input()))

def solve():
	for i in range(n):
		for j in range(m):
			if not check(i, j):
				return 'NO'
	return 'YES'

def check(i, j):
	if gr[i][j] in ['.', 'o']:
		return True
	for c in cs:
		if i + c[0] > 0 and i + c[0] < n - 1 and (j + c[1] > 0) and (j + c[1] < m - 1):
			possib = True
			for e in cs:
				if gr[i + c[0] + e[0]][j + c[1] + e[1]] == '.':
					possib = False
					break
			if possib:
				for e in cs:
					gr[i + c[0] + e[0]][j + c[1] + e[1]] = 'o'
				return True
	return False
print(solve())


(n, m) = [int(i) for i in input().split()]
b = []
a = []
for i in range(n):
	b.append([i for i in input()])
	a.append([0 for i in range(m)])

def check(e, r, q):
	if e >= 0 and r >= 0 and (e + 2 < n) and (r + 2 < m):
		if b[e][r] == '#' and b[e + 1][r] == '#' and (b[e + 2][r] == '#') and (b[e + 2][r + 1] == '#') and (b[e + 2][r + 2] == '#') and (b[e + 1][r + 2] == '#') and (b[e][r + 2] == '#') and (b[e][r + 1] == '#'):
			a[e][r] == 1
			a[e + 1][r] == 1
			a[e + 2][r] == 1
			a[e + 2][r + 1] == 1
			a[e + 2][r + 2] == 1
			a[e + 1][r + 2] == 1
			a[e][r + 2] == 1
			a[e][r + 1] == 1
			return True
	if q == 1:
		return False
	return check(e, r - 1, 1) or check(e, r - 2, 1) or check(e - 1, r - 2, 1) or check(e - 2, r - 2, 1) or check(e - 2, r - 1, 1) or check(e - 2, r, 1) or check(e - 1, r, 1)
for i in range(n):
	for j in range(m):
		if b[i][j] == '#':
			if not check(i, j, 0) and a[i][j] == 0:
				print('NO')
				exit()
print('YES')


(n, m) = [int(x) for x in input().split()]
s = []
for i in range(n):
	s.append(input())
mapp = [[False] * m for i in range(n)]
rnd = ((-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1))

def gene(x, y, p):
	cx = x - rnd[p][0]
	cy = y - rnd[p][1]
	ans = []
	for i in range(8):
		ans.append((cx + rnd[i][0], cy + rnd[i][1]))
	return ans

def judge(ps):
	for (x, y) in ps:
		if x >= 0 and x < n and (y >= 0) and (y < m) and (s[x][y] == '#'):
			continue
		else:
			return False
	return True

def dye(ps):
	global mapp
	for (x, y) in ps:
		mapp[x][y] = True

def check(x, y):
	for i in range(8):
		r = gene(x, y, i)
		if judge(r):
			dye(r)
			return True
	return False
for i in range(n):
	for j in range(m):
		if s[i][j] == '#' and mapp[i][j] == False:
			if check(i, j):
				continue
			else:
				print('NO')
				quit()
print('YES')


(n, m) = [int(x) for x in input().split()]
p = []
for i in range(n):
	sp = [1 if x == '#' else 0 for x in input().strip()]
	p.append(sp)
yes = True
for y in range(n - 2):
	for x in range(m - 2):
		if p[y][x] > 0 and p[y + 1][x] > 0 and (p[y + 2][x] > 0) and (p[y + 2][x + 1] > 0) and (p[y + 2][x + 2] > 0) and (p[y + 1][x + 2] > 0) and (p[y][x + 2] > 0) and (p[y][x + 1] > 0):
			p[y][x] = 2
			p[y + 1][x] = 2
			p[y + 2][x] = 2
			p[y + 2][x + 1] = 2
			p[y + 2][x + 2] = 2
			p[y + 1][x + 2] = 2
			p[y][x + 2] = 2
			p[y][x + 1] = 2
for y in range(n):
	if p[y].count(1) != 0:
		yes = False
		break
print('YES' if yes else 'NO')


usl = list(map(int, input().split()))
mapa = []
m = usl[1]
n = usl[0]
cou = 0
met = list((0 for i in range(n * m + 2)))
met[n * m + 1] = -1
for i in range(n):
	temp = input()
	for j in range(m):
		mapa.append(temp[j])
		if temp[j] == '#':
			met[cou] = 1
		cou += 1
for i in range(n * m):
	kor = i
	if kor > m and kor < m * (n - 1) and (kor % m != 0) and ((kor + 1) % m != 0):
		if mapa[kor + 1] == '#' and mapa[kor - 1] == '#' and (mapa[kor - m] == '#') and (mapa[kor + m] == '#') and (mapa[kor + m - 1] == '#') and (mapa[kor + m + 1] == '#') and (mapa[kor - m + 1] == '#') and (mapa[kor - m - 1] == '#'):
			if mapa[kor] == '#' and met[kor] == 0:
				met[kor] = 1
			met[kor + 1] = -1
			met[kor - 1] = -1
			met[kor - m] = -1
			met[kor + m] = -1
			met[kor + m - 1] = -1
			met[kor + m + 1] = -1
			met[kor - m + 1] = -1
			met[kor - m - 1] = -1
if len(set(met)) == 3:
	print('NO')
else:
	print('YES')


(n, m) = str.split(input())
n = int(n)
m = int(m)
Map = []
Map1 = []
for i in range(n):
	Map.append(input())
for i in range(n):
	Map1.append([])
	for j in range(m):
		Map1[i].append('.')
dir = [[1, 0], [2, 0], [0, 1], [0, 2], [1, 2], [2, 1], [2, 2]]
for i in range(n):
	for j in range(m):
		if Map[i][j] == '#':
			flag = True
			for [x, y] in dir:
				i1 = i + x
				j1 = j + y
				if i1 >= n or j1 >= m:
					flag = False
					break
				if not Map[i1][j1] == '#':
					flag = False
					break
			if flag:
				Map1[i][j] = '#'
				for [x, y] in dir:
					i1 = i + x
					j1 = j + y
					Map1[i1][j1] = '#'
flag = True
for i in range(n):
	for j in range(m):
		if Map[i][j] != Map1[i][j]:
			flag = False
			break
if flag:
	print('YES')
else:
	print('NO')


import sys

def main():
	input = sys.stdin.readline
	(n, m) = map(int, input().split())
	matrix = [['' for i in range(m)] for j in range(n)]
	f = False
	for i in range(n):
		s = input()
		for j in range(m):
			if s[j] == '.':
				f = True
			matrix[i][j] = s[j]
	current = [['.' for i in range(m)] for j in range(n)]
	for i in range(1, n - 1):
		for j in range(1, m - 1):
			if matrix[i - 1][j - 1] == matrix[i - 1][j] == matrix[i - 1][j + 1] == matrix[i][j - 1] == matrix[i][j + 1] == matrix[i + 1][j - 1] == matrix[i + 1][j] == matrix[i + 1][j + 1] == '#':
				current[i - 1][j - 1] = '#'
				current[i - 1][j] = '#'
				current[i - 1][j + 1] = '#'
				current[i][j - 1] = '#'
				current[i][j + 1] = '#'
				current[i + 1][j - 1] = '#'
				current[i + 1][j] = '#'
				current[i + 1][j + 1] = '#'
	if matrix == current:
		return 'YES'
	return 'NO'
print(main())


(n, m) = (int(x) for x in input().split())
hashtags = 0
if m < 3:
	print('NO')
else:
	grid = []
	for line in range(n):
		mapline = input()
		grid.append(mapline)
		hashtags += mapline.count('#')
sign = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 2], [2, 0], [2, 1], [2, 2]]
checked = set([])
for row in range(n - 2):
	for col in range(m - 2):
		if grid[row][col] == '#':
			signed = True
			cur_list = set([])
			for cell in sign:
				if grid[row + cell[0]][col + cell[1]] != '#':
					signed = False
					break
				else:
					cur_list.add((row + cell[0], col + cell[1]))
			if signed:
				checked.update(cur_list)
				if len(checked) == hashtags:
					break
	if len(checked) == hashtags:
		break
if len(checked) == hashtags:
	print('YES')
else:
	print('NO')


(n, m) = (int(i) for i in input().split())
a = []
for i in range(n):
	a.append(list(input()))
bbb = 0
for y in range(n):
	bb = 0
	for x in range(m):
		if a[y][x] != '#':
			continue
		good = 0
		for yy in range(max(0, y - 1), min(y + 2, n)):
			for xx in range(max(0, x - 1), min(x + 2, m)):
				if yy == y and xx == x:
					continue
				br = 0
				if yy - 1 < 0 or yy + 2 > n or xx - 1 < 0 or (xx + 2 > m):
					continue
				for yyy in range(yy - 1, yy + 2):
					for xxx in range(xx - 1, xx + 2):
						if yyy == yy and xxx == xx:
							continue
						if a[yyy][xxx] == '.':
							br = 1
							break
					if br:
						break
				if not br:
					for yyy in range(yy - 1, yy + 2):
						for xxx in range(xx - 1, xx + 2):
							if yyy == yy and xxx == xx:
								continue
							a[yyy][xxx] = '*'
					good = 1
					break
			if good:
				break
		if not good:
			bb = 1
			break
	if bb:
		bbb = 1
		break
if bbb:
	print('NO')
else:
	print('YES')


(n, m) = map(int, input().split())
a = [input() for _ in range(n)]
b = [*map(list, a)]
p = [*zip((0, 0, 0, 1, 1, 2, 2, 2), (0, 1, 2, 0, 2, 0, 1, 2))]
for i in range(n - 2):
	for j in range(m - 2):
		if all((a[i + l][j + k] == '#' for (l, k) in p)):
			for (l, k) in p:
				b[i + l][j + k] = '.'
if any(('#' in x for x in b)):
	print('NO')
else:
	print('YES')


import sys

def solve(n, m, grid):
	for (i, row) in enumerate(grid):
		for (j, cell) in enumerate(row):
			if cell == 0:
				continue
			must = cell == 1
			if i >= n - 2 or j >= m - 2:
				if must:
					return 'NO'
				continue
			for (di, dj) in [(0, 1), (0, 2), (1, 0), (1, 2), (2, 0), (2, 1), (2, 2)]:
				if grid[i + di][j + dj] == 0:
					if must:
						return 'NO'
					break
			else:
				for (di, dj) in [(0, 1), (0, 2), (1, 0), (1, 2), (2, 0), (2, 1), (2, 2)]:
					grid[i + di][j + dj] = 2
				grid[i][j] = 2
	return 'YES'
(n, m) = list(map(int, input().split()))
grid = [['.#'.index(c) for c in line.strip()] for line in sys.stdin.readlines()]
print(solve(n, m, grid))


(n, m) = map(int, input().split())
a = []
for i in range(n):
	s = input()
	a.append(s)
for i in range(n):
	for j in range(m):
		if a[i][j] == '.':
			continue
		if i >= 2 and j >= 2:
			if a[i - 2][j - 2] == '#' and a[i - 2][j - 1] == '#' and (a[i - 2][j] == '#') and (a[i - 1][j] == '#') and (a[i - 1][j - 2] == '#') and (a[i][j - 1] == '#') and (a[i][j - 2] == '#'):
				continue
		if i >= 1 and i <= n - 2 and (j >= 2) and (a[i - 1][j - 2] == '#') and (a[i - 1][j - 1] == '#') and (a[i - 1][j] == '#') and (a[i][j - 2] == '#') and (a[i + 1][j - 2] == '#') and (a[i + 1][j - 1] == '#') and (a[i + 1][j] == '#'):
			continue
		if i <= n - 3 and j >= 2 and (a[i][j - 1] == '#') and (a[i][j - 2] == '#') and (a[i + 1][j] == '#') and (a[i + 1][j - 2] == '#') and (a[i + 2][j] == '#') and (a[i + 2][j - 1] == '#') and (a[i + 2][j - 2] == '#'):
			continue
		if i <= n - 3 and j >= 1 and (j <= m - 2) and (a[i][j - 1] == '#') and (a[i][j + 1] == '#') and (a[i + 1][j - 1] == '#') and (a[i + 1][j + 1] == '#') and (a[i + 2][j] == '#') and (a[i + 2][j - 1] == '#') and (a[i + 2][j + 1] == '#'):
			continue
		if i <= n - 3 and j <= m - 3 and (a[i][j + 1] == '#') and (a[i][j + 2] == '#') and (a[i + 1][j] == '#') and (a[i + 1][j + 2] == '#') and (a[i + 2][j] == '#') and (a[i + 2][j + 1] == '#') and (a[i + 2][j + 2] == '#'):
			continue
		if i <= n - 2 and i >= 1 and (j <= m - 3) and (a[i - 1][j] == '#') and (a[i - 1][j + 1] == '#') and (a[i - 1][j + 2] == '#') and (a[i][j + 2] == '#') and (a[i + 1][j] == '#') and (a[i + 1][j + 1] == '#') and (a[i + 1][j + 2] == '#'):
			continue
		if i >= 2 and j <= m - 3 and (a[i - 2][j] == '#') and (a[i - 2][j + 1] == '#') and (a[i - 2][j + 2] == '#') and (a[i - 1][j] == '#') and (a[i - 1][j + 2] == '#') and (a[i][j + 1] == '#') and (a[i][j + 2] == '#'):
			continue
		if i >= 2 and j <= m - 2 and (j >= 1) and (a[i - 2][j - 1] == '#') and (a[i - 2][j] == '#') and (a[i - 2][j + 1] == '#') and (a[i - 1][j - 1] == '#') and (a[i - 1][j + 1] == '#') and (a[i][j - 1] == '#') and (a[i][j + 1] == '#'):
			continue
		print('NO')
		exit()
print('YES')


(n, m) = map(int, input().split())
a = [list('') for x in range(n)]
b = [list('.' * m) for x in range(n)]
start = 0
for i in range(n):
	a[i] = list(input())
	if start == 0:
		if '.' in a[i]:
			start = (i - 3) // 3 * 3
for i in range(start):
	b[i] = list('#' * m)
for i in range(start, n - 2):
	for j in range(m - 2):
		ok = True
		if a[i][j] == '#':
			for y in range(i, i + 3):
				if ok == False:
					break
				for x in range(j, j + 3):
					if not (y == i + 1 and x == j + 1):
						if a[y][x] != '#':
							ok = False
							break
			if ok:
				for y in range(i, i + 3):
					for x in range(j, j + 3):
						if not (y == i + 1 and x == j + 1):
							b[y][x] = '#'
if a == b:
	print('YES')
else:
	print('NO')


(n, m) = list(map(int, input().split()))
arr = [['.'] * m for i in range(n)]
visit = [['.'] * m for i in range(n)]
sign = []
dx = [1, 1, 1, 0, 0, 0, -1, -1, -1]
dy = [1, 0, -1, 1, 0, -1, 1, 0, -1]

def check(y, x):
	for i in range(3):
		for j in range(3):
			if i == 1 and j == 1:
				continue
			if sign[y + i][x + j] == '.':
				return
	for i in range(3):
		for j in range(3):
			if i == 1 and j == 1:
				continue
			visit[y + i][x + j] = '#'
for i in range(n):
	sign.append(list(input()))
for i in range(n - 2):
	for j in range(m - 2):
		check(i, j)
if visit == sign:
	print('YES')
else:
	print('NO')


(n, m) = list(map(int, input().split()))
u = []
u1 = []
for i in range(n):
	u.append(list(input()))
	u1.append(['.'] * m)
for i in range(n - 2):
	for j in range(m - 2):
		ok = True
		for k in range(3):
			if u[i][j + k] != '#' or u[i + k][j] != '#':
				ok = False
				break
		if ok:
			if u[i + 2][j + 1] != '#' or u[i + 2][j + 2] != '#' or u[i + 1][j + 2] != '#':
				ok = False
			else:
				for k in range(3):
					u1[i][j + k] = '#'
					u1[i + k][j] = '#'
				u1[i + 2][j + 1] = '#'
				u1[i + 2][j + 2] = '#'
				u1[i + 1][j + 2] = '#'
ok = True
for i in range(n):
	for j in range(m):
		if u[i][j] != u1[i][j]:
			ok = False
			break
	if not ok:
		break
if ok:
	print('YES')
else:
	print('NO')


def readint():
	return int(input())

def readline():
	return [int(c) for c in input().split()]

def main():
	(N, M) = readline()
	grid = []
	for i in range(N):
		grid.append([e for e in input()])
	empty = [['.'] * M for _ in range(N)]
	for crow in range(1, N - 1):
		for ccol in range(1, M - 1):
			apply = True
			for i in range(crow - 1, crow + 2):
				for j in range(ccol - 1, ccol + 2):
					if not (i == crow and j == ccol):
						if grid[i][j] == '.':
							apply = False
							break
				if not apply:
					break
			if apply:
				empty[crow - 1][ccol - 1] = '#'
				empty[crow - 1][ccol] = '#'
				empty[crow - 1][ccol + 1] = '#'
				empty[crow][ccol - 1] = '#'
				empty[crow][ccol + 1] = '#'
				empty[crow + 1][ccol - 1] = '#'
				empty[crow + 1][ccol] = '#'
				empty[crow + 1][ccol + 1] = '#'
	for i in range(N):
		for j in range(M):
			if grid[i][j] != empty[i][j]:
				print('NO')
				return
	print('YES')
main()


(n, m) = map(int, input().split())
(sign, d) = ([], 1)
for i in range(n):
	sign.append(input())

def fun1(i, j):
	if i + 2 < n and j + 2 < m:
		if sign[i][j + 1] == '#' and sign[i][j + 2] == '#' and (sign[i + 1][j] == '#') and (sign[i + 1][j + 2] == '#') and (sign[i + 2][j] == '#') and (sign[i + 2][j + 1] == '#') and (sign[i + 2][j + 2] == '#'):
			return True
	return False

def fun2(i, j):
	if i + 2 < n and j + 1 < m and (j >= 1) and (i >= 0):
		if sign[i][j + 1] == '#' and sign[i][j - 1] == '#' and (sign[i + 1][j - 1] == '#') and (sign[i + 1][j + 1] == '#') and (sign[i + 2][j - 1] == '#') and (sign[i + 2][j + 1] == '#') and (sign[i + 2][j] == '#'):
			return True
	return False

def fun3(i, j):
	if i + 2 < n and j < m and (j >= 2) and (i >= 0):
		if sign[i][j - 2] == '#' and sign[i][j - 1] == '#' and (sign[i + 1][j] == '#') and (sign[i + 1][j - 2] == '#') and (sign[i + 2][j - 1] == '#') and (sign[i + 2][j] == '#') and (sign[i + 2][j - 2] == '#'):
			return True
	return False

def fun4(i, j):
	if i + 1 < n and j + 2 < m and (i >= 1):
		if sign[i][j + 2] == '#' and sign[i - 1][j] == '#' and (sign[i - 1][j + 1] == '#') and (sign[i - 1][j + 2] == '#') and (sign[i + 1][j] == '#') and (sign[i + 1][j + 1] == '#') and (sign[i + 1][j + 2] == '#'):
			return True
	return False

def fun6(i, j):
	if i + 1 < n and j < m and (j >= 2) and (i >= 1):
		if sign[i][j - 2] == '#' and sign[i - 1][j - 2] == '#' and (sign[i - 1][j - 1] == '#') and (sign[i - 1][j] == '#') and (sign[i + 1][j - 1] == '#') and (sign[i + 1][j] == '#') and (sign[i + 1][j - 2] == '#'):
			return True
	return False

def fun9(i, j):
	if i >= 2 and j >= 2:
		if sign[i][j - 1] == '#' and sign[i][j - 2] == '#' and (sign[i - 1][j] == '#') and (sign[i - 1][j - 2] == '#') and (sign[i - 2][j] == '#') and (sign[i - 2][j - 1] == '#') and (sign[i - 2][j - 2] == '#'):
			return True
	return False

def fun8(i, j):
	if j >= 1 and i >= 2 and (j + 1 < m):
		if sign[i][j - 1] == '#' and sign[i][j + 1] == '#' and (sign[i - 1][j + 1] == '#') and (sign[i - 1][j - 1] == '#') and (sign[i - 2][j + 1] == '#') and (sign[i - 2][j - 1] == '#') and (sign[i - 2][j] == '#'):
			return True
	return False

def fun7(i, j):
	if i >= 2 and j + 2 < m:
		if sign[i][j + 2] == '#' and sign[i][j + 1] == '#' and (sign[i - 1][j] == '#') and (sign[i - 1][j + 2] == '#') and (sign[i - 2][j + 1] == '#') and (sign[i - 2][j] == '#') and (sign[i - 2][j + 2] == '#'):
			return True
	return False
for i in range(n):
	if d == 0:
		break
	for j in range(m):
		if sign[i][j] == '#':
			if fun1(i, j):
				continue
			elif fun2(i, j):
				continue
			elif fun3(i, j):
				continue
			elif fun4(i, j):
				continue
			elif fun6(i, j):
				continue
			elif fun7(i, j):
				continue
			elif fun8(i, j):
				continue
			elif fun9(i, j):
				continue
			else:
				d = 0
				break
if d == 0:
	print('NO')
else:
	print('YES')


(n, m) = input().strip().split()
n = int(n)
m = int(m)
sig = [['#', '#', '#'], ['#', '.', '#'], ['#', '#', '#']]
sig2 = [['#', '#', '#'], ['#', '#', '#'], ['#', '#', '#']]
l = []
for i in range(n):
	x = input().strip()
	y = []
	for i in range(len(x)):
		y.append(x[i])
	l.append(y)
x = []
for i in range(n):
	y = []
	for j in range(m):
		y.append('.')
	x.append(y)
for i in range(2, n):
	for j in range(2, m):
		if l[i - 2][j - 2:j + 1] == sig[0] and l[i - 1][j - 2:j + 1] == sig[1] and (l[i][j - 2:j + 1] == sig[2]):
			x[i - 2][j - 2:j + 1] = sig[0]
			x[i - 1][j - 2:j + 1] = sig[1]
			x[i][j - 2:j + 1] = sig[2]
		elif l[i - 2][j - 2:j + 1] == sig2[0] and l[i - 1][j - 2:j + 1] == sig2[1] and (l[i][j - 2:j + 1] == sig2[2]):
			if x[i - 1][j - 1] == '#':
				x[i - 2][j - 2:j + 1] = sig2[0]
				x[i - 1][j - 2:j + 1] = sig2[1]
				x[i][j - 2:j + 1] = sig2[2]
			else:
				x[i - 2][j - 2:j + 1] = sig[0]
				x[i - 1][j - 2:j + 1] = sig[1]
				x[i][j - 2:j + 1] = sig[2]
if x == l:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
a = [input() for _ in [0] * n]
s = set()
p = [(0, 0), (0, 1), (0, 2), (1, 0), (1, 2), (2, 0), (2, 1), (2, 2)]
for i in range(n - 2):
	for j in range(m - 2):
		if '.' not in (a[i + k][j + l] for (k, l) in p):
			s.update(((i + k, j + l) for (k, l) in p))
print('YNEOS'[len(s) < sum((x.count('#') for x in a))::2])


read = lambda : list(map(int, input().split()))
getinfo = lambda grid: print(list(map(print, grid)))
mod = 10 ** 9 + 7
inf = float('inf')
dx = [-1, 0, 1]
dy = [-1, 0, 1]

def point(i, j):
	for x in dx:
		for y in dy:
			if x == y == 0:
				continue
			yield (i + x, j + y)
(n, m) = read()
grid = []
for _ in range(n):
	grid.append(list(input()))
canset = [[1] * m for _ in range(n)]
left = set()
for i in range(n):
	for j in range(m):
		if grid[i][j] == '.':
			for (x, y) in point(i, j):
				if 0 <= x < n and 0 <= y < m:
					canset[x][y] = 0
		elif grid[i][j] == '#':
			left.add((i, j))
for i in range(1, n - 1):
	for j in range(1, m - 1):
		if canset[i][j]:
			for (x, y) in point(i, j):
				left.discard((x, y))
if len(left) == 0:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
lis = []
for i in range(n):
	aa = list(input())
	lis.append(aa)
for i in range(1, n - 1):
	for j in range(1, m - 1):
		if (lis[i - 1][j - 1] == '#' or lis[i - 1][j - 1] == '@') and (lis[i - 1][j + 1] == '#' or lis[i - 1][j + 1] == '@') and (lis[i - 1][j] == '#' or lis[i - 1][j] == '@') and (lis[i + 1][j - 1] == '#' or lis[i + 1][j - 1] == '@') and (lis[i + 1][j] == '#' or lis[i + 1][j] == '@') and (lis[i + 1][j + 1] == '#' or lis[i + 1][j + 1] == '@') and (lis[i][j - 1] == '#' or lis[i][j - 1] == '@') and (lis[i][j + 1] == '#' or lis[i][j + 1] == '@'):
			lis[i + 1][j] = '@'
			lis[i + 1][j + 1] = '@'
			lis[i + 1][j - 1] = '@'
			lis[i - 1][j] = '@'
			lis[i - 1][j + 1] = '@'
			lis[i - 1][j - 1] = '@'
			lis[i][j + 1] = '@'
			lis[i][j - 1] = '@'
for i in range(1, n):
	for j in range(1, m):
		if lis[i][j] == '#':
			print('NO')
			exit()
print('YES')


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
C = [['#', '#', '#'], ['#', '', '#'], ['#', '#', '#']]
(N, M) = map(int, input().split())
A = []
for i in range(N):
	A.append([x for x in input()])
t0 = time.time()
res = [['.' for _ in range(M)] for _ in range(N)]
ds = [(0, 0), (0, 1), (0, 2), (1, 0), (1, 2), (2, 0), (2, 1), (2, 2)]
for i in range(N - 2):
	for j in range(M - 2):
		if all((A[i + r][j + c] == '#' for (r, c) in ds)):
			for (r, c) in ds:
				res[i + r][j + c] = '#'
		elif A[i][j] != res[i][j]:
			print('NO')
			exit(0)
if res == A:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
cur_inp = [1] * (m + 1)
prev_inp = [1] * (m + 1)
old_inp = [1] * (m + 1)
res = 1
tr = 1
while tr <= n:
	old_inp = prev_inp
	prev_inp = cur_inp
	cur_inp = [1] * (m + 1)
	i = 1
	for c in input():
		if c == '.':
			cur_inp[i] = 1
		else:
			cur_inp[i] = 2
			res += 1
			if i > 2:
				i_1 = i - 1
				backup = prev_inp[i_1]
				prev_inp[i_1] = 2
				cur_can = 1
				for j in (i, i_1, i - 2):
					for arr in (cur_inp, prev_inp, old_inp):
						if arr[j] == 1:
							cur_can = 2
				if cur_can == 1:
					res += 1
					for j in (i, i_1, i - 2):
						for arr in (cur_inp, prev_inp, old_inp):
							if arr[j] == 2:
								res -= 1
								arr[j] = 3
				prev_inp[i_1] = backup
		i += 1
	tr += 1
if res == 1:
	print('YES')
else:
	print('NO')


p = input().split()
n = int(p[0])
m = int(p[1])
a = []
o = []
for i in range(n):
	a.append([])
	o.append([])
	p = input()
	for j in range(m):
		a[i].append(p[j])
		o[i].append('.')
for i in range(1, n - 1):
	for j in range(1, m - 1):
		if a[i - 1][j - 1] == '#' and a[i - 1][j] == '#' and (a[i - 1][j + 1] == '#') and (a[i][j - 1] == '#') and (a[i - 1][j + 1] == '#') and (a[i + 1][j - 1] == '#') and (a[i + 1][j] == '#') and (a[i + 1][j + 1] == '#'):
			o[i - 1][j - 1] = '#'
			o[i - 1][j] = '#'
			o[i - 1][j + 1] = '#'
			o[i][j - 1] = '#'
			o[i][j + 1] = '#'
			o[i + 1][j - 1] = '#'
			o[i + 1][j] = '#'
			o[i + 1][j + 1] = '#'
if a == o:
	print('YES')
else:
	print('NO')


def get_input_list():
	return list(map(int, input().split()))
(N, M) = get_input_list()
data = []
l_ = []
for _ in range(M + 4):
	l_.append(False)
data.append(l_)
data.append(l_)
for i in range(N):
	r = input()
	l = []
	l.append(False)
	l.append(False)
	for i in r:
		if i == '.':
			l.append(False)
		else:
			l.append(True)
	l.append(False)
	l.append(False)
	data.append(l)
data.append(l_)
data.append(l_)
v = [[True, True, True], [True, False, True], [True, True, True]]
anws = 'YES'

def compare(n, m):
	return data[n][m] == True and data[n][m + 1] == True and (data[n][m + 2] == True) and (data[n + 1][m] == True) and (data[n + 1][m + 2] == True) and (data[n + 2][m] == True) and (data[n + 2][m + 1] == True) and (data[n + 2][m + 2] == True)
for n in range(2, N + 2):
	for m in range(2, M + 2):
		if data[n][m] == True:
			if compare(n - 2, m - 2):
				continue
			elif compare(n - 1, m - 2):
				continue
			elif compare(n, m - 2):
				continue
			elif compare(n - 2, m - 1):
				continue
			elif compare(n, m - 1):
				continue
			elif compare(n - 2, m):
				continue
			elif compare(n - 1, m):
				continue
			elif compare(n, m):
				continue
			else:
				anws = 'NO'
				break
	if anws == 'NO':
		break
print(anws)


try:
	while True:
		ss = []
		visited = []
		(n, m) = list(map(int, input().split()))
		flag = True
		ss.append('.' * (m + 4))
		ss.append('.' * (m + 4))
		visited.append([1] * (m + 4))
		visited.append([1] * (m + 4))
		for i in range(n):
			s = input()
			s = '..' + s + '..'
			ss.append(s)
			visited.append([1, 1] + [0] * m + [1, 1])
		ss.append('.' * (m + 4))
		ss.append('.' * (m + 4))
		visited.append([1] * (m + 4))
		visited.append([1] * (m + 4))
		for i in range(n + 2):
			if not flag:
				break
			for j in range(m + 2):
				if ss[i][j:j + 3] == '###' and ss[i + 1][j] == '#' and (ss[i + 1][j + 2] == '#') and (ss[i + 2][j:j + 3] == '###'):
					visited[i][j:j + 3] = [1, 1, 1]
					if ss[i + 1][j + 1] == '.':
						visited[i + 1][j + 1] = 1
					visited[i + 1][j] = 1
					visited[i + 1][j + 2] = 1
					visited[i + 2][j:j + 3] = [1, 1, 1]
				if ss[i][j] == '#' and (not visited[i][j]):
					flag = False
		if not flag:
			print('NO')
		else:
			print('YES')
except Exception as e:
	pass


def solve_b(n=None, m=None, sign=None):
	if n is None or m is None or sign is None:
		(n, m) = (int(x) for x in input().split())
		sign = [input() for _ in range(n)]
	sheet = [list('.' * m) for _ in range(n)]

	def can_write(r, c):
		for i in range(r - 1, r + 2):
			for j in range(c - 1, c + 2):
				if (i, j) == (r, c):
					continue
				if sign[i][j] != '#':
					return False
		return True

	def write(r, c):
		for i in range(r - 1, r + 2):
			for j in range(c - 1, c + 2):
				if (i, j) == (r, c):
					pass
				else:
					sheet[i][j] = '#'
	for r in range(1, n - 1):
		for c in range(1, m - 1):
			if can_write(r, c):
				write(r, c)
	for r in range(n):
		sheet[r] = ''.join(sheet[r])
		if sheet[r] != sign[r]:
			print('NO')
			return 'NO'
	print('YES')
	return 'YES'
solve_b()


import math
import sys
DEBUG = False

def inp():
	return sys.stdin.readline().rstrip()

def dprint(*value, sep=' ', end='\n'):
	if DEBUG:
		print(*value, sep=sep, end=end)

def solve(H, W, A):
	visited = [bytearray(W) for _ in range(H)]
	for y in range(H):
		for x in range(W):
			if A[y][x] == '.' or visited[y][x]:
				continue
			dprint(x, y)
			for (dx, dy) in [(0, 0), (-1, 0), (-2, 0), (0, -1), (-2, -1), (0, -2), (-1, -2), (-2, -2)]:
				tx = x + dx
				ty = y + dy
				dprint('  ', tx, ty)
				if tx < 0 or ty < 0 or tx + 2 >= W or (ty + 2 >= H):
					continue
				bad = False
				for (ex, ey) in [(0, 0), (1, 0), (2, 0), (0, 1), (2, 1), (0, 2), (1, 2), (2, 2)]:
					nx = tx + ex
					ny = ty + ey
					if A[ny][nx] == '.':
						bad = True
						break
				if bad:
					continue
				for (ex, ey) in [(0, 0), (1, 0), (2, 0), (0, 1), (2, 1), (0, 2), (1, 2), (2, 2)]:
					nx = tx + ex
					ny = ty + ey
					visited[ny][nx] = 1
				assert visited[ny][nx] == 1
				break
			if visited[y][x] == 0:
				return False
	return True

def main():
	(H, W) = [int(e) for e in inp().split()]
	A = [inp() for _ in range(H)]
	print('YES' if solve(H, W, A) else 'NO')
main()


def check(matrix, x, y):
	return matrix[x][y] == '#'
(n, m) = list(map(int, input().split()))
matrix = []
for i in range(n):
	matrix.append(input())
possible = [[False] * m for _ in range(n)]
for x in range(1, n - 1):
	for y in range(1, m - 1):
		if check(matrix, x - 1, y - 1) and check(matrix, x - 1, y) and check(matrix, x - 1, y + 1) and check(matrix, x, y - 1) and check(matrix, x, y + 1) and check(matrix, x + 1, y - 1) and check(matrix, x + 1, y) and check(matrix, x + 1, y + 1):
			possible[x - 1][y - 1] = True
			possible[x - 1][y] = True
			possible[x - 1][y + 1] = True
			possible[x][y - 1] = True
			possible[x][y + 1] = True
			possible[x + 1][y - 1] = True
			possible[x + 1][y] = True
			possible[x + 1][y + 1] = True
flag = False
for x in range(n):
	for y in range(m):
		if check(matrix, x, y) and (not possible[x][y]):
			flag = True
if not flag:
	print('YES')
else:
	print('NO')


from collections import Counter, defaultdict, deque
import sys
sys.setrecursionlimit(1000000)
read = lambda : list(map(int, input().split()))
getinfo = lambda grid: print(list(map(print, grid)))
mod = 10 ** 9 + 7
inf = float('inf')
dx = [-1, 0, 1]
dy = [-1, 0, 1]
(n, m) = read()
grid = []
for _ in range(n):
	grid.append(list(input()))
canset = [[1] * m for _ in range(n)]
left = set()
for i in range(n):
	for j in range(m):
		if grid[i][j] == '.':
			for xx in dx:
				for yy in dy:
					if xx == yy == 0:
						continue
					x = i + xx
					y = j + yy
					if 0 <= x < n and 0 <= y < m:
						canset[x][y] = 0
		if grid[i][j] == '#':
			left.add((i, j))
for i in range(1, n - 1):
	for j in range(1, m - 1):
		if canset[i][j]:
			for xx in dx:
				for yy in dy:
					if xx == yy == 0:
						continue
					x = i + xx
					y = j + yy
					left.discard((x, y))
if len(left) == 0:
	print('YES')
else:
	print('NO')


import sys, math
(n, m) = map(int, sys.stdin.readline().split())
arr = [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ans = [['.'] * m for _ in range(n)]
dx = [0, 1, 0, -1, 1, 1, -1, -1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
for i in range(n):
	for j in range(m):
		cnt = 0
		for k in range(8):
			(nx, ny) = (i + dx[k], j + dy[k])
			if 0 <= nx < n and 0 <= ny < m:
				cnt += 1
		if cnt == 8:
			can = True
			for k in range(8):
				(nx, ny) = (i + dx[k], j + dy[k])
				if arr[nx][ny] == '.':
					can = False
					break
			if can:
				for k in range(8):
					(nx, ny) = (i + dx[k], j + dy[k])
					ans[nx][ny] = '#'
if ans == arr:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
a = [[*input()] for _ in range(n)]
b = [['.'] * m for i in range(n)]
p = [(0, 0), (0, 1), (0, 2), (1, 0), (1, 2), (2, 0), (2, 1), (2, 2)]
for i in range(n - 2):
	for j in range(m - 2):
		if all((a[i + x][j + y] == '#' for (x, y) in p)):
			for (x, y) in p:
				b[i + x][y + j] = '#'
if a == b:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
g = []
visited = []
flag = 0
for i in range(n):
	gt = input()
	temp = [0] * m
	visited.append(temp)
	g.append(gt)
for i in range(n):
	for j in range(m):
		if g[i][j] == '#' and visited[i][j] == 0:
			if i + 2 < n and j + 2 < m and (g[i + 1][j] == '#') and (g[i + 2][j] == '#') and (g[i][j + 1] == '#') and (g[i][j + 2] == '#') and (g[i + 1][j + 2] == '#') and (g[i + 2][j + 1] == '#') and (g[i + 2][j + 2] == '#'):
				continue
			elif i + 2 < n and j + 1 < m and (j - 1 >= 0) and (g[i][j - 1] == '#') and (g[i][j + 1] == '#') and (g[i + 1][j - 1] == '#') and (g[i + 1][j + 1] == '#') and (g[i + 2][j - 1] == '#') and (g[i + 2][j + 1] == '#') and (g[i + 2][j] == '#'):
				continue
			elif i + 2 < n and j - 2 >= 0 and (g[i][j - 1] == '#') and (g[i][j - 2] == '#') and (g[i + 1][j] == '#') and (g[i + 1][j - 2] == '#') and (g[i + 2][j] == '#') and (g[i + 2][j - 1] == '#') and (g[i + 2][j - 2] == '#'):
				continue
			elif i + 1 < n and i - 1 >= 0 and (j + 2 < m) and (g[i][j + 2] == '#') and (g[i - 1][j] == '#') and (g[i - 1][j + 1] == '#') and (g[i - 1][j + 2] == '#') and (g[i + 1][j] == '#') and (g[i + 1][j + 1] == '#') and (g[i + 1][j + 2] == '#'):
				continue
			elif i + 1 < n and i - 1 >= 0 and (j - 2 >= 0) and (g[i][j - 2] == '#') and (g[i - 1][j] == '#') and (g[i - 1][j - 1] == '#') and (g[i - 1][j - 2] == '#') and (g[i + 1][j] == '#') and (g[i + 1][j - 1] == '#') and (g[i + 1][j - 2] == '#'):
				continue
			elif i - 2 >= 0 and j + 2 < m and (g[i][j + 1] == '#') and (g[i][j + 2] == '#') and (g[i - 1][j] == '#') and (g[i - 1][j + 2] == '#') and (g[i - 2][j] == '#') and (g[i - 2][j + 1] == '#') and (g[i - 2][j + 2] == '#'):
				continue
			elif i - 2 >= 0 and j + 1 < m and (j - 1 >= 0) and (g[i][j + 1] == '#') and (g[i][j - 1] == '#') and (g[i - 1][j + 1] == '#') and (g[i - 1][j - 1] == '#') and (g[i - 2][j - 1] == '#') and (g[i - 2][j] == '#') and (g[i - 2][j + 1] == '#'):
				continue
			elif i - 2 >= 0 and j - 2 >= 0 and (g[i - 2][j - 2] == '#') and (g[i][j - 1] == '#') and (g[i][j - 2] == '#') and (g[i - 1][j] == '#') and (g[i - 1][j - 2] == '#') and (g[i - 2][j] == '#') and (g[i - 2][j - 1] == '#'):
				continue
			else:
				flag = 1
				break
	if flag == 1:
		break
if flag == 1:
	print('NO')
else:
	print('YES')


(n, m) = map(int, input().split())
mp = []
for i in range(n):
	line = input().strip()
	mp.append(list(map(lambda c: c == '#', line)))
mp1 = [[False for _ in range(m)] for _ in range(n)]
for i in range(1, n - 1):
	for j in range(1, m - 1):
		f = all((mp[i - 1][j - k] for k in range(-1, 1 + 1)))
		f = f and all((mp[i + 1][j - k] for k in range(-1, 1 + 1)))
		f = f and (mp[i][j - 1] and mp[i][j + 1])
		if not f:
			continue
		for ik in range(-1, 2):
			for jk in range(-1, 2):
				if ik == 0 and jk == 0:
					continue
				mp1[i + ik][j + jk] = True
if all((all((mp[i][j] == mp1[i][j] for j in range(m))) for i in range(n))):
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
arr = [list(input().strip()) for i in range(n)]
arr1 = [['.' for j in range(m)] for i in range(n)]
for i in range(1, n - 1):
	for j in range(1, m - 1):
		if arr[i - 1][j - 1] == '#' and arr[i - 1][j] == '#' and (arr[i - 1][j + 1] == '#') and (arr[i][j - 1] == '#') and (arr[i][j + 1] == '#') and (arr[i + 1][j - 1] == '#') and (arr[i + 1][j] == '#') and (arr[i + 1][j + 1] == '#'):
			arr1[i - 1][j - 1] = '#'
			arr1[i - 1][j] = '#'
			arr1[i - 1][j + 1] = '#'
			arr1[i][j - 1] = '#'
			arr1[i][j + 1] = '#'
			arr1[i + 1][j - 1] = '#'
			arr1[i + 1][j] = '#'
			arr1[i + 1][j + 1] = '#'
flag = 1
for i in range(n):
	for j in range(m):
		if arr[i][j] != arr1[i][j]:
			flag = 0
			break
	if flag == 0:
		break
if flag == 1:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
S = [input() for i in range(n)]
T = [['.'] * m for i in range(n)]
for i in range(n - 2):
	for j in range(m - 2):
		if S[i][j] == '#' and S[i][j + 1] == '#' and (S[i][j + 2] == '#') and (S[i + 1][j] == '#') and (S[i + 1][j + 2] == '#') and (S[i + 2][j] == '#') and (S[i + 2][j + 1] == '#') and (S[i + 2][j + 2] == '#'):
			T[i][j] = '#'
			T[i][j + 1] = '#'
			T[i][j + 2] = '#'
			T[i + 1][j] = '#'
			T[i + 1][j + 2] = '#'
			T[i + 2][j] = '#'
			T[i + 2][j + 1] = '#'
			T[i + 2][j + 2] = '#'
for i in range(n):
	for j in range(m):
		if S[i][j] != T[i][j]:
			print('NO')
			exit()
else:
	print('YES')


def check(a, b):
	for i in range(3):
		for j in range(3):
			if i == 1 and j == 1:
				continue
			elif l[a + i][b + j] == '.':
				return False
	return True

def make(a, b):
	for i in range(3):
		for j in range(3):
			if i == 1 and j == 1:
				continue
			else:
				l1[a + i][b + j] = '#'
l = []
l1 = []
for _ in range(1):
	(n, m) = map(int, input().split())
	for i in range(n):
		l.append(list(input()))
		l1.append(['.'] * m)
	for i in range(n - 2):
		for j in range(m - 2):
			if check(i, j):
				make(i, j)
	if l == l1:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
grid = []
ansgrid = []
for i in range(n):
	grid.append(input())
	ansgrid.append([0] * m)
for i in range(n - 2):
	for j in range(m - 2):
		if grid[i][j] == '#' and grid[i + 1][j] == '#' and (grid[i + 2][j] == '#') and (grid[i][j + 1] == '#') and (grid[i][j + 2] == '#') and (grid[i + 2][j + 1] == '#') and (grid[i + 2][j + 2] == '#') and (grid[i + 1][j + 2] == '#'):
			ansgrid[i][j] = 1
			ansgrid[i + 1][j] = 1
			ansgrid[i + 2][j] = 1
			ansgrid[i + 1][j + 2] = 1
			ansgrid[i + 2][j + 2] = 1
			ansgrid[i + 2][j + 1] = 1
			ansgrid[i][j + 2] = 1
			ansgrid[i][j + 1] = 1
flag = 0
for i in range(n):
	for j in range(m):
		if grid[i][j] == '#' and ansgrid[i][j] == 0 or (grid[i][j] == '.' and ansgrid[i][j] == 1):
			flag = 1
if flag:
	print('NO')
else:
	print('YES')


import sys
cin = sys.stdin
(n, m) = map(int, next(cin).split())
sign = []
for _ in range(n):
	sign.append(next(cin))
pattern = [[0, 0], [0, 1], [0, 2], [1, 0], [1, 2], [2, 0], [2, 1], [2, 2]]
for i in range(n):
	for j in range(m):
		if sign[i][j] == '#':
			fill_flag = False
			for zero in pattern:
				for shift in pattern:
					(ii, jj) = (i + zero[0] - shift[0], j + zero[1] - shift[1])
					if ii < 0 or ii >= n or jj < 0 or (jj >= m):
						break
					if sign[ii][jj] != '#':
						break
				else:
					fill_flag = True
				if fill_flag:
					break
			if not fill_flag:
				print('NO')
				sys.exit()
print('YES')


(n, m) = map(int, input().split())

def check(x, y):
	po = [(x, y), (x + 1, y), (x + 2, y), (x, y + 1), (x, y + 2), (x + 1, y + 2), (x + 2, y + 1), (x + 2, y + 2)]
	flag = True
	for (x, y) in po:
		if g[y][x] == '.':
			flag = False
			break
	if flag:
		for (x, y) in po:
			l[y][x] = '#'
l = [['.'] * m for _ in range(n)]
g = [0] * n
for i in range(n):
	t = list(input())
	g[i] = t
for y in range(n - 2):
	for x in range(m - 2):
		check(x, y)
if l == g:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
t = []
for x in range(0, n, +1):
	tmp_s = input()
	t.append(list(tmp_s))
for x in range(0, n, +1):
	for y in range(0, m, +1):
		if t[x][y] == '#' or t[x][y] == '0':
			if m - y < 3 or n - x < 3:
				continue
			if (t[x + 1][y] == '#' or t[x + 1][y] == '0') and (t[x + 2][y] == '#' or t[x + 2][y] == '0') and (t[x][y + 1] == '#' or t[x][y + 1] == '0') and (t[x][y + 2] == '#' or t[x][y + 2] == '0') and (t[x + 1][y + 2] == '#' or t[x + 1][y + 2] == '0') and (t[x + 2][y + 1] == '#' or t[x + 2][y + 1] == '0') and (t[x + 2][y + 2] == '#' or t[x + 2][y + 2] == '0'):
				t[x + 1][y] = '0'
				t[x + 2][y] = '0'
				t[x][y + 1] = '0'
				t[x][y + 2] = '0'
				t[x + 1][y + 2] = '0'
				t[x + 2][y + 1] = '0'
				t[x + 2][y + 2] = '0'
				t[x][y] = '0'
for x in range(0, n, +1):
	for y in range(0, m, +1):
		if t[x][y] == '#':
			print('NO')
			exit(0)
print('YES')
exit(0)


(x, y) = map(int, input().split())
m = [[0 for f in range(y)] for g in range(x)]
xm = [[0 for f in range(y)] for g in range(x)]
for i in range(x):
	li = input()
	for j in range(y):
		if li[j] == '#':
			m[i][j] = 1

def allNeighbourOkay(i, j):
	for a in range(-1, 2):
		for b in range(-1, 2):
			if a != 0 or b != 0:
				if m[i + a][j + b] == 0:
					return False
	return True

def isSameArray(m, xm):
	for i in range(x):
		for j in range(y):
			if m[i][j] != xm[i][j]:
				return False
	return True
for i in range(1, x - 1):
	for j in range(1, y - 1):
		if allNeighbourOkay(i, j):
			for a in range(-1, 2):
				for b in range(-1, 2):
					if a != 0 or b != 0:
						xm[i - a][j - b] = 1
if isSameArray(m, xm):
	print('YES')
else:
	print('No')


d = dict()
(n, m) = map(int, input().split())
b = set()
l = []
for i in range(n):
	s = input()
	for j in range(m):
		d[i, j] = s[j]
		if s[j] == '#':
			b.add((i, j))
a = set()
for i in range(1, n - 1):
	for j in range(1, m - 1):
		if d[i - 1, j - 1] == '#' and d[i, j - 1] == '#' and (d[i + 1, j - 1] == '#') and (d[i - 1, j] == '#') and (d[i + 1, j] == '#') and (d[i - 1, j + 1] == '#') and (d[i, j + 1] == '#') and (d[i + 1, j + 1] == '#'):
			a.update({(i - 1, j - 1), (i, j - 1), (i + 1, j - 1), (i - 1, j), (i + 1, j), (i - 1, j + 1), (i, j + 1), (i + 1, j + 1)})
if a == b:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
arr = []
ans = []
for i in range(n + 2):
	arr.append([])
	ans.append([])
	if i > 0 and i <= n:
		s = input()
	for j in range(m + 2):
		if j > 0 and j <= m and (i > 0) and (i <= n):
			if i == 1 or i == n or j == 1 or (j == m):
				ans[i].append(-1)
			else:
				ans[i].append(0)
			if s[j - 1] == '.':
				arr[i].append(0)
			else:
				arr[i].append(1)
		else:
			arr[i].append(-1)
			ans[i].append(-1)
for i in range(1, n + 1):
	for j in range(1, m + 1):
		if arr[i][j] == 0:
			ans[i + 1][j] = -1
			ans[i + 1][j + 1] = -1
			ans[i + 1][j - 1] = -1
			ans[i][j + 1] = -1
			ans[i][j - 1] = -1
			ans[i - 1][j - 1] = -1
			ans[i - 1][j] = -1
			ans[i - 1][j + 1] = -1
flag = False
for i in range(1, n + 1):
	for j in range(1, m + 1):
		if arr[i][j] == 1:
			if ans[i + 1][j] != 0 and ans[i + 1][j + 1] != 0 and (ans[i + 1][j - 1] != 0) and (ans[i][j + 1] != 0) and (ans[i][j - 1] != 0) and (ans[i - 1][j - 1] != 0) and (ans[i - 1][j] != 0) and (ans[i - 1][j + 1] != 0):
				flag = True
if not flag:
	print('YES')
else:
	print('NO')


(n, m) = list(map(int, input().split()))
MAP = [list(input()) for i in range(n)]
ANSMAP = [['.' for i in range(m)] for j in range(n)]
for i in range(1, n - 1):
	for j in range(1, m - 1):
		if MAP[i - 1][j - 1] == '#' and MAP[i - 1][j] == '#' and (MAP[i - 1][j + 1] == '#') and (MAP[i][j - 1] == '#') and (MAP[i - 1][j + 1] == '#') and (MAP[i + 1][j - 1] == '#') and (MAP[i + 1][j] == '#') and (MAP[i + 1][j + 1] == '#'):
			ANSMAP[i - 1][j - 1] = '#'
			ANSMAP[i - 1][j] = '#'
			ANSMAP[i - 1][j + 1] = '#'
			ANSMAP[i][j - 1] = '#'
			ANSMAP[i][j + 1] = '#'
			ANSMAP[i + 1][j - 1] = '#'
			ANSMAP[i + 1][j] = '#'
			ANSMAP[i + 1][j + 1] = '#'
if MAP == ANSMAP:
	print('YES')
else:
	print('NO')


from sys import stdin, stdout
(row, col) = map(int, input().split())
signature = [stdin.readline()[:-1] for i in range(row)]
ink = []
pred = []
for i in range(0, row):
	for j in range(0, col):
		if signature[i][j] == '#':
			ink.append((i, j))
for i in range(1, row - 1):
	for j in range(1, col - 1):
		if not (signature[i][j - 1] == '.' or signature[i][j + 1] == '.' or signature[i - 1][j - 1] == '.' or (signature[i - 1][j] == '.') or (signature[i - 1][j + 1] == '.') or (signature[i + 1][j - 1] == '.') or (signature[i + 1][j] == '.') or (signature[i + 1][j + 1] == '.')):
			pred.extend([(i, j - 1), (i, j + 1), (i - 1, j - 1), (i - 1, j), (i - 1, j + 1), (i + 1, j - 1), (i + 1, j), (i + 1, j + 1)])
if len(list(set(pred))) == len(ink):
	stdout.write('YES\n')
else:
	stdout.write('NO\n')


def check(cx, cy):
	if a[cx - 1][cy - 1] == '#' and a[cx - 1][cy] == '#' and (a[cx - 1][cy + 1] == '#') and (a[cx][cy - 1] == '#') and (a[cx][cy + 1] == '#') and (a[cx + 1][cy - 1] == '#') and (a[cx + 1][cy] == '#') and (a[cx + 1][cy + 1] == '#'):
		used[cx - 1][cy - 1] = used[cx - 1][cy] = used[cx - 1][cy + 1] = used[cx][cy - 1] = used[cx][cy + 1] = used[cx + 1][cy - 1] = used[cx + 1][cy] = used[cx + 1][cy + 1] = True
		return True
	return False
(n, m) = map(int, input().split())
a = [0] * (n + 1)
for i in range(n):
	a[i] = list(input()) + ['.']
a[-1] = ['.'] * (m + 1)
used = [[a[i][j] == '.' for j in range(m)] for i in range(n)]
f = True
for i in range(n):
	for j in range(m):
		if used[i][j]:
			continue
		if check(i - 1, j - 1) or check(i - 1, j) or check(i - 1, j + 1) or check(i, j - 1) or check(i, j + 1) or check(i + 1, j - 1) or check(i + 1, j) or check(i + 1, j + 1):
			continue
		print('NO')
		exit(0)
print('YES')


from copy import copy
(n, m) = map(int, input().split())
s = []
t = copy(s)
for i in range(n):
	s.append(input())
	t.append([0 for _ in range(m)])
DX = [-1, 0, 1, -1, 1, -1, 0, 1]
DY = [-1, -1, -1, 0, 0, 1, 1, 1]
for y in range(1, n - 1):
	for x in range(1, m - 1):
		if sum([s[y + dy][x + dx] == '#' for (dy, dx) in zip(DY, DX)]) == 8:
			for (dy, dx) in zip(DY, DX):
				t[y + dy][x + dx] = 1
for y in range(n):
	for x in range(m):
		if s[y][x] == '#' and t[y][x] == 0:
			print('NO')
			exit(0)
print('YES')


from math import ceil, sqrt
t = 1
for test in range(1, t + 1):
	(n, m) = list(map(int, input().split()))
	arr = [['.' for i in range(m)] for i in range(n)]
	arr2 = []
	for i in range(n):
		arr2.append(list(input()))
	for i in range(1, n - 1):
		for j in range(1, m - 1):
			if arr2[i + 1][j] == arr2[i][j + 1] == arr2[i + 1][j + 1] == arr2[i - 1][j] == arr2[i][j - 1] == arr2[i - 1][j - 1] == arr2[i + 1][j - 1] == arr2[i - 1][j + 1] == '#':
				arr[i + 1][j] = arr[i][j + 1] = arr[i + 1][j + 1] = arr[i - 1][j] = arr[i][j - 1] = arr[i - 1][j - 1] = arr[i + 1][j - 1] = arr[i - 1][j + 1] = '#'
	if arr == arr2:
		print('YES')
	else:
		print('NO')


(n, m) = map(int, input().split())
original = []
copied = [['.' for i in range(m)] for j in range(n)]
p = [(0, 0), (0, 1), (0, 2), (1, 0), (1, 2), (2, 0), (2, 1), (2, 2)]
for i in range(n):
	original.append(input())
for row in range(n - 2):
	for col in range(m - 2):
		if all((original[row + i][col + j] == '#' for (i, j) in p)):
			for (i, j) in p:
				copied[row + i][col + j] = '#'
print('YES' if all([original[i] == ''.join(copied[i]) for i in range(n)]) else 'NO')


(n, m) = list(map(int, input().split()))
dp = [[-1 for i in range(m)] for j in range(n)]
dp2 = [[-1 for i in range(m)] for j in range(n)]
for i in range(0, n):
	s = input()
	for j in range(0, m):
		if s[j] == '.':
			dp[i][j] = -1
		else:
			dp[i][j] = s[j]
for i in range(0, n - 2):
	for j in range(0, m - 2):
		p = 0
		c = 0
		for k in range(i, i + 3):
			for h in range(j, j + 3):
				p = p + 1
				if p != 5:
					if dp[k][h] == '#':
						c = c + 1
		if c == 8:
			p = 0
			for k in range(i, i + 3):
				for h in range(j, j + 3):
					p = p + 1
					if p != 5:
						dp2[k][h] = '#'
if dp == dp2:
	print('YES')
else:
	print('NO')


l = []
ans = []
(n, m) = map(int, input().split())
for i in range(n):
	ka = list(input())
	ja = ['.'] * m
	l.append(ka)
	ans.append(ja)
for i in range(n):
	for j in range(m):
		if l[i][j] == '#':
			count = 0
			if i + 2 < n:
				if l[i + 2][j] == '#':
					count += 1
			if j + 2 < m:
				if l[i][j + 2] == '#':
					count += 1
			if i + 2 < n and j + 2 < m:
				if l[i + 2][j + 2] == '#':
					count += 1
			if i + 1 < n:
				if l[i + 1][j] == '#':
					count += 1
			if j + 1 < m:
				if l[i][j + 1] == '#':
					count += 1
			if i + 2 < n and j + 1 < m:
				if l[i + 2][j + 1] == '#':
					count += 1
			if i + 1 < n and j + 2 < m:
				if l[i + 1][j + 2] == '#':
					count += 1
			if count == 7:
				(ans[i][j], ans[i + 2][j], ans[i][j + 2], ans[i + 1][j + 2], ans[i + 2][j + 2], ans[i + 1][j], ans[i][j + 1], ans[i + 2][j + 1]) = ('#', '#', '#', '#', '#', '#', '#', '#')
if ans == l:
	print('YES')
else:
	print('NO')


from sys import stdin

def read(x, y):
	if not (0 < x < n - 1 and 0 < y < m - 1):
		return False
	for i in range(x - 1, x + 2):
		for j in range(y - 1, y + 2):
			if i == x and j == y:
				continue
			elif podp[i][j] != '#':
				return False
	return True

def write(x, y):
	for i in range(x - 1, x + 2):
		for j in range(y - 1, y + 2):
			if i == x and j == y:
				continue
			ans[i][j] = '#'
(n, m) = map(int, input().split())
podp = list(map(lambda x: x.rstrip('\n'), stdin.readlines()))
ans = [['.' for j in range(m)] for i in range(n)]
for i in range(n):
	for j in range(m):
		if read(i, j):
			write(i, j)
print(('NO', 'YES')['\n'.join(map(lambda x: ''.join(x), ans)) == '\n'.join(map(lambda x: ''.join(x), podp))])


(n, m) = map(int, input().split())
a = []
array = []
for i in range(n):
	a.append(list(map(str, input())))
	listt = []
	for c in range(m):
		if a[i][c] == '#':
			listt.append(1)
		else:
			listt.append(0)
	array.append(listt)
for y in range(1, n - 1):
	for x in range(1, m - 1):
		f = a[y + 1][x] == '#' and a[y + 1][x + 1] == '#' and (a[y + 1][x - 1] == '#')
		s = a[y][x + 1] == '#' and a[y][x - 1] == '#'
		th = a[y - 1][x] == '#' and a[y - 1][x + 1] == '#' and (a[y - 1][x - 1] == '#')
		if f and s and th:
			array[y + 1][x] -= 1
			array[y + 1][x + 1] -= 1
			array[y + 1][x - 1] -= 1
			array[y][x + 1] -= 1
			array[y][x - 1] -= 1
			array[y - 1][x - 1] -= 1
			array[y - 1][x] -= 1
			array[y - 1][x + 1] -= 1
mb = True
for y in range(n):
	for x in range(m):
		if array[y][x] == 1:
			mb = False
			break
if mb:
	print('YES')
else:
	print('NO')


def gt(s, i, j, n, m):
	f = 0
	if (i + 2 < n and j + 2 < m) and s[i][j + 1] == s[i][j + 2] == s[i + 1][j] == s[i + 2][j] == s[i + 2][j + 1] == s[i + 2][j + 2] == s[i + 1][j + 2] == '#':
		f = 1
	elif (i + 2 < n and j + 1 < m and (j - 1 > -1)) and s[i][j - 1] == s[i][j + 1] == s[i + 1][j - 1] == s[i + 1][j + 1] == s[i + 2][j - 1] == s[i + 2][j] == s[i + 2][j + 1] == '#':
		f = 1
	elif (i + 2 < n and j - 2 > -1) and s[i][j - 2] == s[i][j - 1] == s[i + 1][j - 2] == s[i + 1][j] == s[i + 2][j - 2] == s[i + 2][j - 1] == s[i + 2][j] == '#':
		f = 1
	elif (i - 1 > -1 and i + 1 < n and (j + 2 < m)) and s[i - 1][j] == s[i - 1][j + 1] == s[i - 1][j + 2] == s[i][j + 2] == s[i + 1][j] == s[i + 1][j + 1] == s[i + 1][j + 2] == '#':
		f = 1
	elif (i - 1 > -1 and i + 1 < n and (j - 2 > -1)) and s[i - 1][j - 2] == s[i - 1][j - 1] == s[i - 1][j] == s[i][j - 2] == s[i + 1][j - 2] == s[i + 1][j - 1] == s[i + 1][j] == '#':
		f = 1
	elif (i - 2 > -1 and j + 2 < m) and s[i - 2][j] == s[i - 2][j + 1] == s[i - 2][j + 2] == s[i - 1][j] == s[i - 1][j + 2] == s[i][j + 1] == s[i][j + 2] == '#':
		f = 1
	elif (i - 2 > -1 and j - 1 > -1 and (j + 1 < m)) and s[i - 2][j - 1] == s[i - 2][j] == s[i - 2][j + 1] == s[i - 1][j - 1] == s[i - 1][j + 1] == s[i][j - 1] == s[i][j + 1] == '#':
		f = 1
	elif (i - 2 > -1 and j - 2 > -1) and s[i - 2][j - 2] == s[i - 2][j - 1] == s[i - 2][j] == s[i - 1][j - 2] == s[i - 1][j] == s[i][j - 2] == s[i][j - 1] == '#':
		f = 1
	if f == 1:
		return True
	return False
(n, m) = map(int, input().split())
s = [input() for _ in range(n)]
f = 0
for i in range(n):
	for j in range(m):
		if s[i][j] == '#':
			if gt(s, i, j, n, m):
				continue
			else:
				f = 1
				break
	if f == 1:
		break
if f == 1:
	print('NO')
else:
	print('YES')


(n, m) = map(int, input().split())
L = []
M = [['.'] * m for i in range(n)]
for i in ' ' * n:
	L.append(list(input()))
for i in range(1, n - 1):
	for j in range(1, m - 1):
		if L[i - 1][j - 1:j + 2] == L[i + 1][j - 1:j + 2] == ['#', '#', '#'] and L[i][j - 1] == L[i][j + 1] == '#':
			M[i - 1][j - 1:j + 2] = ['#', '#', '#']
			M[i + 1][j - 1:j + 2] = ['#', '#', '#']
			M[i][j - 1] = '#'
			M[i][j + 1] = '#'
print(['NO', 'YES'][L == M])


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append(list(input()))
ans = [['.' for i in range(m)] for i in range(n)]
for i in range(1, n - 1):
	for j in range(1, m - 1):
		if a[i - 1][j - 1] == '#' and a[i - 1][j] == '#' and (a[i - 1][j + 1] == '#') and (a[i][j - 1] == '#') and (a[i][j + 1] == '#') and (a[i + 1][j - 1] == '#') and (a[i + 1][j] == '#') and (a[i + 1][j + 1] == '#'):
			ans[i - 1][j - 1] = ans[i - 1][j] = ans[i - 1][j + 1] = ans[i][j - 1] = ans[i][j + 1] = ans[i + 1][j - 1] = ans[i + 1][j] = ans[i + 1][j + 1] = '#'
if ans == a:
	print('YES')
else:
	print('NO')


def main():
	(n, m) = map(int, input().split(' '))
	signature = [list(input()) for _ in range(n)]
	forgery = [['.'] * m for _ in range(n)]
	for i in range(1, n - 1):
		for j in range(1, m - 1):
			if all((cell == '#' for cell in (signature[i - 1][j], signature[i + 1][j], signature[i][j - 1], signature[i][j + 1], signature[i - 1][j - 1], signature[i + 1][j + 1], signature[i + 1][j - 1], signature[i - 1][j + 1]))):
				forgery[i - 1][j] = forgery[i + 1][j] = forgery[i][j - 1] = forgery[i][j + 1] = forgery[i - 1][j - 1] = forgery[i + 1][j + 1] = forgery[i + 1][j - 1] = forgery[i - 1][j + 1] = '#'
	print('YES' if forgery == signature else 'NO')
main()


def legal(stroke):
	cond1 = len(stroke & signature) == len(stroke)
	cond2 = len(stroke & blank) == 0
	return cond1 and cond2
(rows, cols) = map(int, input().split())
signature = set()
blank = set()
for y in range(rows):
	line = input()
	for (x, sym) in enumerate(line):
		if sym == '#':
			signature.add((y, x))
		else:
			blank.add((y, x))
remaining = signature.copy()
for y in range(1, rows - 1):
	for x in range(1, cols - 1):
		stroke = set([(y - 1, x - 1), (y - 1, x), (y - 1, x + 1), (y, x - 1), (y, x + 1), (y + 1, x - 1), (y + 1, x), (y + 1, x + 1)])
		if legal(stroke):
			remaining -= stroke
if remaining:
	print('NO')
else:
	print('YES')


(n, m) = [int(s) for s in input().split()]
c = [['.'] * m for s in range(n)]
a = []
for i in range(n):
	a.append([])
	b = input()
	for elem in b:
		a[i].append(elem)
for i in range(n):
	for j in range(m):
		if j + 2 < m and i + 2 < n and (a[i][j] == '#') and (a[i][j + 1] == '#') and (a[i][j + 2] == '#') and (a[i + 1][j] == '#') and (a[i + 2][j] == '#') and (a[i + 2][j + 1] == '#') and (a[i + 2][j + 2] == '#') and (a[i + 1][j + 2] == '#'):
			c[i][j] = '#'
			c[i][j + 1] = '#'
			c[i][j + 2] = '#'
			c[i + 1][j] = '#'
			c[i + 2][j] = '#'
			c[i + 2][j + 1] = '#'
			c[i + 2][j + 2] = '#'
			c[i + 1][j + 2] = '#'
if a == c:
	print('YES')
else:
	print('NO')


import sys
(m, n) = [int(i) for i in input().split(' ')]
l = [[] for _ in range(m)]
for i in range(m):
	l[i] = input()
inks = []
for i in range(1, m - 1):
	for j in range(1, n - 1):
		if l[i - 1][j - 1] == '#' and l[i][j - 1] == '#' and (l[i + 1][j - 1] == '#') and (l[i - 1][j] == '#') and (l[i + 1][j] == '#') and (l[i - 1][j + 1] == '#') and (l[i][j + 1] == '#') and (l[i + 1][j + 1] == '#'):
			inks += [(i - 1, j - 1), (i, j - 1), (i + 1, j - 1), (i - 1, j), (i + 1, j), (i - 1, j + 1), (i, j + 1), (i + 1, j + 1)]
for i in range(m):
	for j in range(n):
		if l[i][j] == '#' and (not (i, j) in inks):
			print('NO')
			sys.exit()
else:
	print('YES')


(n, m) = list(map(int, input().split()))
a = [[0] * (m + 4) for _ in range(n + 4)]
b = []

def conv(i, j):
	i = i + 2
	j = j + 2
	s = True
	for (k, m) in [(i - 1, j - 1), (i - 1, j), (i - 1, j + 1), (i, j - 1), (i, j + 1), (i + 1, j - 1), (i + 1, j), (i + 1, j + 1)]:
		if a[k][m] == 0:
			s = False
			break
	return s

def check(i, j):
	s = False
	for (t, s) in [(i - 1, j - 1), (i - 1, j), (i - 1, j + 1), (i, j - 1), (i, j + 1), (i + 1, j - 1), (i + 1, j), (i + 1, j + 1)]:
		if conv(t, s):
			return True
	return False
for i in range(n):
	s = input()
	for j in range(len(s)):
		if s[j] == '#':
			a[i + 2][j + 2] = 1
			b.append((i, j))
state = 'YES'
while len(b) > 0:
	(i, j) = b.pop()
	if check(i, j) == False:
		state = 'NO'
		break
print(state)


(n, m) = map(int, input().split())
a = []
for i in range(n):
	a.append([x for x in input()])
b = [['.' for x in range(m)] for y in range(n)]
for i in range(n - 2):
	for j in range(m - 2):
		if a[i][j] == '#' and a[i + 1][j] == '#' and (a[i + 2][j] == '#') and (a[i][j + 1] == '#') and (a[i + 2][j + 1] == '#') and (a[i][j + 2] == '#') and (a[i + 1][j + 2] == '#') and (a[i + 2][j + 2] == '#'):
			b[i][j] = '#'
			b[i + 1][j] = '#'
			b[i + 2][j] = '#'
			b[i][j + 1] = '#'
			b[i + 2][j + 1] = '#'
			b[i][j + 2] = '#'
			b[i + 1][j + 2] = '#'
			b[i + 2][j + 2] = '#'
if a == b:
	print('YES')
else:
	print('NO')


def main():
	(n, m) = map(int, input().split())
	li = [input() for _ in range(n)]
	r = [['.'] * m for _ in range(n)]
	for i in range(1, n - 1):
		for j in range(1, m - 1):
			ok = True
			for x in range(i - 1, i + 2):
				for y in range(j - 1, j + 2):
					if x == i and y == j:
						continue
					if li[x][y] == '.':
						ok = False
						break
				if not ok:
					break
			if not ok:
				continue
			for x in range(i - 1, i + 2):
				for y in range(j - 1, j + 2):
					if x == i and y == j:
						continue
					r[x][y] = '#'
	for i in range(n):
		for j in range(m):
			if li[i][j] != r[i][j]:
				print('NO')
				return False
	print('YES')
main()


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
r = []
for i in range(n):
	a = input().rstrip('\n')
	a = list(a)
	r.append(a)
r1 = []
for i in range(n):
	a = ['.' for i in range(m)]
	r1.append(a)
for i in range(n - 2):
	for j in range(m - 2):
		flag = 0
		for k in range(3):
			for k1 in range(3):
				if r[i + k][k1 + j] == '.' and (not k1 == k == 1):
					flag = 1
					break
		if flag == 0:
			for k in range(3):
				for k1 in range(3):
					if k == k1 == 1:
						continue
					r1[i + k][j + k1] = r[i + k][j + k1]
flag = 0
for i in range(n):
	for j in range(m):
		if r[i][j] != r1[i][j]:
			flag = 1
			break
if flag == 0:
	print('YES')
else:
	print('NO')


(N, M) = map(int, input().split())
T = [[] for i in range(N)]
for i in range(N):
	t = input()
	T[i] = t
R = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]
S = [['.'] * M for j in range(N)]
for i in range(N):
	for j in range(M):
		flag = True
		for (dx, dy) in R:
			(nx, ny) = (i + dx, j + dy)
			if not (0 <= nx < N and 0 <= ny < M):
				flag = False
				break
			if T[nx][ny] == '.':
				flag = False
				break
		if flag:
			for (dx, dy) in R:
				(nx, ny) = (i + dx, j + dy)
				if 0 <= nx < N and 0 <= ny < M:
					S[nx][ny] = '#'
flag1 = True
for i in range(N):
	for j in range(M):
		if T[i][j] != S[i][j]:
			flag1 = False
if flag1:
	print('YES')
else:
	print('NO')


import sys
input = sys.stdin.readline
from collections import *
(n, m) = map(int, input().split())
s = [list(input()[:-1]) for _ in range(n)]
t = [['.'] * m for _ in range(n)]
for i in range(n - 2):
	for j in range(m - 2):
		flag = True
		for k in range(i, i + 3):
			for l in range(j, j + 3):
				if k == i + 1 and l == j + 1:
					continue
				if s[k][l] == '.':
					flag = False
		if flag:
			for k in range(i, i + 3):
				for l in range(j, j + 3):
					if k == i + 1 and l == j + 1:
						continue
					t[k][l] = '#'
if s == t:
	print('YES')
else:
	print('NO')


import sys
import math
import collections
import heapq
import decimal
(n, m) = (int(i) for i in input().split())
l = []
for i in range(n):
	l.append(list(input()))
l2 = [['.' for i in range(m)] for j in range(n)]
for i in range(1, n - 1):
	for j in range(1, m - 1):
		l1 = [l[i - 1][j - 1], l[i - 1][j], l[i - 1][j + 1], l[i][j - 1], l[i][j + 1], l[i + 1][j - 1], l[i + 1][j], l[i + 1][j + 1]]
		s = set(l1)
		if len(s) == 1 and list(s)[0] == '#':
			(l2[i - 1][j - 1], l2[i - 1][j], l2[i - 1][j + 1], l2[i][j - 1], l2[i][j + 1], l2[i + 1][j - 1], l2[i + 1][j], l2[i + 1][j + 1]) = ('#', '#', '#', '#', '#', '#', '#', '#')
c = 1
for i in range(n):
	if l[i] != l2[i]:
		c = 0
		break
if c == 1:
	print('YES')
else:
	print('NO')


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

def points(x, y):
	return {(x - 1, y - 1), (x - 1, y), (x - 1, y + 1), (x, y - 1), (x, y + 1), (x + 1, y - 1), (x + 1, y), (x + 1, y + 1)}

def is_star(x, y):
	if sig[x - 1][y] == sig[x - 1][y - 1] == sig[x - 1][y + 1] == '#' and sig[x][y - 1] == sig[x][y + 1] == '#' and (sig[x + 1][y] == sig[x + 1][y - 1] == sig[x + 1][y + 1] == '#'):
		return True
	return False
cnt = 0
p = set()
for x in range(n):
	for y in range(m):
		if x != 0 and y != 0 and (x != n - 1) and (y != m - 1):
			if is_star(x, y):
				p.update(points(x, y))
			if sig[x][y] == '#':
				cnt += 1
		elif sig[x][y] == '#':
			cnt += 1
if len(p) == cnt:
	print('YES')
else:
	print('NO')


def answer(m, n, b, a):
	for i in range(0, n):
		for j in range(0, m):
			if a[i][j] == '#':
				try:
					if a[i + 1][j] == '#' and a[i + 2][j] == '#' and (a[i][j + 1] == '#') and (a[i][j + 2] == '#') and (a[i + 2][j + 1] == '#') and (a[i + 1][j + 2] == '#') and (a[i + 2][j + 2] == '#'):
						b[i][j] = 1
						b[i + 1][j] = 1
						b[i + 2][j] = 1
						b[i][j + 1] = 1
						b[i][j + 2] = 1
						b[i + 2][j + 1] = 1
						b[i + 2][j + 2] = 1
						b[i + 1][j + 2] = 1
				except:
					continue
	for i in range(0, n):
		for j in range(0, m):
			if a[i][j] == '#':
				if b[i][j] == 0:
					return 'NO'
	return 'YES'
(n, m) = map(int, input().strip().split())
a = []
b = []
for ijk in range(0, n):
	s = input().strip()
	c = [0] * m
	b.append(c)
	a.append(list(s))
print(answer(m, n, b, a))


def check_cell(x, y, sig):
	cord = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
	for shift in cord:
		count = 0
		for pos in cord:
			nx = x + pos[0] + shift[0]
			ny = y + pos[1] + shift[1]
			if nx >= n or nx < 0 or ny >= m or (ny < 0):
				break
			elif sig[nx][ny] == '#':
				count += 1
		if count == 8:
			return True
	return False

def check_grid(n, m, sig):
	for i in range(n):
		for j in range(m):
			if sig[i][j] == '#' and (not check_cell(i, j, sig)):
				return False
	return True
(n, m) = [int(x) for x in input().split()]
l = []
for i in range(n):
	l.append(list(input()))
sig = l
if check_grid(n, m, sig):
	print('YES')
else:
	print('NO')


def main():
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		s = input()
		b = []
		for l in s:
			b.append(l)
		a.append(b)
	for i in range(1, n - 1):
		for j in range(1, m - 1):
			may = True
			if a[i][j - 1] == '.' or a[i][j + 1] == '.' or a[i + 1][j - 1] == '.' or (a[i + 1][j + 1] == '.') or (a[i + 1][j] == '.') or (a[i - 1][j - 1] == '.') or (a[i - 1][j + 1] == '.') or (a[i - 1][j] == '.'):
				may = False
			if may:
				a[i][j - 1] = a[i][j + 1] = a[i + 1][j - 1] = a[i + 1][j + 1] = a[i + 1][j] = a[i - 1][j - 1] = a[i - 1][j + 1] = a[i - 1][j] = '?'
	for i in range(n):
		for j in range(m):
			if a[i][j] == '#':
				print('NO')
				return
	print('YES')
main()


(col, row) = map(int, input().split())
s = []
s_ = []
for i in range(col):
	si = list(input())
	si_ = list(si)
	s.append(si)
	s_.append(si_)

def protect(Matric, x):
	col = len(Matric)
	row = len(Matric[0])
	for col in Matric:
		col.append(x)
		col.insert(0, x)
	Matric.append([x] * (row + 2))
	Matric.insert(0, [x] * (row + 2))
	return Matric
s = protect(s, '.')
s_ = protect(s_, '.')

def xie(yuan, xian, col, row):
	lis = [[1, 0], [-1, 0], [0, 1], [0, -1], [1, 1], [1, -1], [-1, 1], [-1, -1]]
	for e in lis:
		ok = True
		for u in lis:
			if yuan[col + e[0] + u[0]][row + e[1] + u[1]] == '#':
				continue
			else:
				ok = False
				break
		if ok:
			for i in lis:
				xian[col + e[0] + i[0]][row + e[1] + i[1]] = '.'
			return True
	if not ok:
		return False
for c in range(1, col + 1):
	for r in range(1, row + 1):
		if s_[c][r] == '#':
			if not xie(s, s_, c, r):
				print('NO')
				exit()
print('YES')


ans = 'YES'
(n, m) = map(int, input().split())
lis = []
lis2 = [['.'] * m for i in range(n)]

def check(x, y):
	d = True
	for i in range(3):
		for j in range(3):
			if lis[x + i - 1][y + j - 1] == '.' and (not (i == 1 and j == 1)):
				d = False
				break
		if not d:
			break
	if d:
		draw(x, y)

def draw(x, y):
	for i in range(3):
		for j in range(3):
			if not (i == 1 and j == 1):
				lis2[x + i - 1][y + j - 1] = '#'
for i in range(n):
	lis.append(list(input()))
for i in range(1, n - 1):
	for j in range(1, m - 1):
		check(i, j)
for i in range(n):
	if lis[i] == lis2[i]:
		continue
	else:
		ans = 'NO'
		break
print(ans)


import sys

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

def writable(r, c):
	if r + 2 >= n or c + 2 >= m:
		return False
	t = set()
	t.add(cells[r][c])
	t.add(cells[r][c + 1])
	t.add(cells[r][c + 2])
	t.add(cells[r + 1][c])
	t.add(cells[r + 1][c + 2])
	t.add(cells[r + 2][c])
	t.add(cells[r + 2][c + 1])
	t.add(cells[r + 2][c + 2])
	return not '.' in t

def fill_ink(r, c):
	paper[r][c] = '#'
	paper[r][c + 1] = '#'
	paper[r][c + 2] = '#'
	paper[r + 1][c] = '#'
	paper[r + 1][c + 2] = '#'
	paper[r + 2][c] = '#'
	paper[r + 2][c + 1] = '#'
	paper[r + 2][c + 2] = '#'
(n, m) = rint()
cells = []
for i in range(n):
	cells.append(input())
paper = [['.' for j in range(m)] for i in range(n)]
for r in range(n):
	for c in range(m):
		if writable(r, c) is True:
			fill_ink(r, c)
for r in range(n):
	for c in range(m):
		if cells[r][c] != paper[r][c]:
			print('NO')
			exit()
print('YES')


import sys
(n, m) = map(int, input().split())
mat = [sys.stdin.readline() for _ in range(n)]
val = [[False] * m for _ in range(n)]
neighbors = [(i, j) for i in range(-1, 2) for j in range(-1, 2) if (i, j) != (0, 0)]
for i in range(1, n - 1):
	for j in range(1, m - 1):
		cnt = 0
		for (oi, oj) in neighbors:
			cnt += mat[i + oi][j + oj] == '#'
		if cnt == 8:
			for (oi, oj) in neighbors:
				val[i + oi][j + oj] = True
can_forge = True
for i in range(n):
	for j in range(m):
		if mat[i][j] == '#' and (not val[i][j]):
			can_forge = False
			break
	if not can_forge:
		break
print('YES' if can_forge else 'NO')


(n, m) = list(map(int, input().split()))
s = []
for i in range(n):
	s.append(list(map(str, input().strip())))
t = []
for i in range(n):
	p = ['.'] * m
	t.append(p)
for i in range(1, n - 1):
	for j in range(1, m - 1):
		f = 0
		if s[i - 1][j - 1] == '#' and s[i - 1][j] == '#' and (s[i - 1][j + 1] == '#') and (s[i][j - 1] == '#') and (s[i][j + 1] == '#') and (s[i + 1][j - 1] == '#') and (s[i + 1][j] == '#') and (s[i + 1][j + 1] == '#'):
			f = 1
		if f == 1:
			t[i - 1][j - 1] = '#'
			t[i - 1][j] = '#'
			t[i - 1][j + 1] = '#'
			t[i][j - 1] = '#'
			t[i][j + 1] = '#'
			t[i + 1][j - 1] = '#'
			t[i + 1][j] = '#'
			t[i + 1][j + 1] = '#'
f = 1
for i in range(n):
	for j in range(m):
		if s[i][j] == '#' and s[i][j] != t[i][j]:
			f = 0
			break
	if f == 0:
		break
if f == 1:
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
mat = []
cnt = 0
for i in range(n):
	s = input()
	cnt += s.count('#')
	mat.append(s)
tmat = []
for i in range(n):
	o = []
	for j in range(m):
		o.append('.')
	tmat.append(o)
for i in range(n):
	for j in range(m):
		l = []
		for e1 in range(i - 1, i + 2):
			for e2 in range(j - 1, j + 2):
				if e1 > -1 and e1 < n and (e2 > -1) and (e2 < m):
					if e1 == i and e2 == j:
						continue
					l.append((e1, e2))
		if len(l) < 8:
			continue
		flag = 1
		for x in l:
			if mat[x[0]][x[1]] == '.':
				flag = 0
				break
		if flag:
			for x in l:
				tmat[x[0]][x[1]] = '#'
res = []
for x in tmat:
	res.append(''.join(x))
if res == mat:
	print('YES')
else:
	print('NO')


ss = []
visited = []
(n, m) = list(map(int, input().split()))
flag = True
ss.append('.' * (m + 4))
ss.append('.' * (m + 4))
visited.append([1] * (m + 4))
visited.append([1] * (m + 4))
for i in range(n):
	s = input()
	s = '..' + s + '..'
	ss.append(s)
	visited.append([1, 1] + [0] * m + [1, 1])
ss.append('.' * (m + 4))
ss.append('.' * (m + 4))
visited.append([1] * (m + 4))
visited.append([1] * (m + 4))
for i in range(n + 2):
	if not flag:
		break
	for j in range(m + 2):
		if ss[i][j:j + 3] == '###' and ss[i + 1][j] == '#' and (ss[i + 1][j + 2] == '#') and (ss[i + 2][j:j + 3] == '###'):
			visited[i][j:j + 3] = [1, 1, 1]
			if ss[i + 1][j + 1] == '.':
				visited[i + 1][j + 1] = 1
			visited[i + 1][j] = 1
			visited[i + 1][j + 2] = 1
			visited[i + 2][j:j + 3] = [1, 1, 1]
		if ss[i][j] == '#' and (not visited[i][j]):
			flag = False
if not flag:
	print('NO')
else:
	print('YES')


import sys

def transform(c):
	if c == '.':
		return 0
	if c == '#':
		return 1
	return 2

def take_care(board, n, m):
	if n + 2 >= N:
		return
	if m + 2 >= M:
		return
	if board[n][m + 1] == 0 or board[n][m + 2] == 0 or board[n + 1][m] == 0 or (board[n + 1][m + 2] == 0) or (board[n + 2][m] == 0) or (board[n + 2][m + 1] == 0) or (board[n + 2][m + 2] == 0):
		return
	board[n][m] = 2
	board[n][m + 1] = 2
	board[n][m + 2] = 2
	board[n + 1][m] = 2
	board[n + 1][m + 2] = 2
	board[n + 2][m] = 2
	board[n + 2][m + 1] = 2
	board[n + 2][m + 2] = 2
	return (False, board)
(N, M) = [int(i) for i in input().strip().split()]
board = []
for n in range(N):
	row = input().strip()
	row = [transform(c) for c in row]
	board.append(row)
for n in range(N):
	for m in range(M):
		take_care(board, n, m)
for row in board:
	if 1 in row:
		print('NO')
		sys.exit()
print('YES')


from sys import stdin, stdout
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False

def mj(x, y):
	flg = False
	if a[x][y] == a[x + 1][y] == a[x + 2][y] == a[x][y + 1] == a[x][y + 2] == a[x + 1][y + 2] == a[x + 2][y + 2] == a[x + 2][y + 1] == '#':
		flg = True
	elif a[x][y] == a[x - 1][y] == a[x + 1][y] == a[x - 1][y + 1] == a[x - 1][y + 2] == a[x][y + 2] == a[x + 1][y + 2] == a[x + 1][y + 1] == '#':
		flg = True
	elif a[x][y] == a[x - 1][y] == a[x - 2][y] == a[x][y + 1] == a[x][y + 2] == a[x - 1][y + 2] == a[x - 2][y + 2] == a[x - 2][y + 1] == '#':
		flg = True
	elif a[x][y] == a[x][y + 1] == a[x][y - 1] == a[x + 1][y - 1] == a[x + 1][y + 1] == a[x + 2][y - 1] == a[x + 2][y] == a[x + 2][y + 1] == '#':
		flg = True
	elif a[x][y] == a[x][y + 1] == a[x][y - 1] == a[x - 1][y - 1] == a[x - 1][y + 1] == a[x - 2][y - 1] == a[x - 2][y] == a[x - 2][y + 1] == '#':
		flg = True
	elif a[x][y] == a[x][y - 1] == a[x][y - 2] == a[x - 1][y] == a[x - 1][y - 2] == a[x - 2][y] == a[x - 2][y - 1] == a[x - 2][y - 2] == '#':
		flg = True
	elif a[x][y] == a[x + 1][y] == a[x - 1][y] == a[x + 1][y - 1] == a[x + 1][y - 2] == a[x][y - 2] == a[x - 1][y - 1] == a[x - 1][y - 1] == '#':
		flg = True
	elif a[x][y] == a[x][y - 1] == a[x][y - 2] == a[x + 1][y] == a[x + 1][y - 2] == a[x + 2][y] == a[x + 2][y - 1] == a[x + 2][y - 2] == '#':
		flg = True
	return flg
(r, c) = R()
a = ['.' * (c + 4), '.' * (c + 4)]
for i in range(r):
	a.append('..' + S() + '..')
a.extend(['.' * (c + 4), '.' * (c + 4)])
for i in range(2, r + 2):
	for j in range(2, c + 2):
		if a[i][j] == '#' and (not mj(i, j)):
			exit(print('NO'))
print('YES')


def bidui():
	for i in range(n):
		for j in range(m):
			if mp[i][j] != v[i][j]:
				return 0
	return 1
(n, m) = map(int, input().strip().split())
mp = []
for i in range(n):
	tmp = input().strip().split()[0]
	mp.append(list(tmp))
v = [['.'] * m for i in range(n)]
dx = [0, 0, -1, -1, -1, 1, 1, 1]
dy = [-1, 1, -1, 0, 1, -1, 0, 1]
for i in range(n):
	for j in range(m):
		tag = 1
		for k in range(8):
			nx = i + dx[k]
			ny = j + dy[k]
			if nx < 0:
				tag = 0
				break
			if nx >= n:
				tag = 0
				break
			if ny < 0:
				tag = 0
				break
			if ny >= m:
				tag = 0
				break
			if mp[nx][ny] != '#':
				tag = 0
				break
		if tag == 0:
			continue
		for k in range(8):
			nx = i + dx[k]
			ny = j + dy[k]
			v[nx][ny] = '#'
if bidui() == 1:
	print('YES')
else:
	print('NO')


a = list(map(int, input().split()))
b = []
c = []
d = []
for i in range(a[0]):
	b.append(list(input()))
for i in range(a[0]):
	for j in range(a[1]):
		if b[i][j] == '#':
			c.append('b[' + str(i) + '][' + str(j) + ']')
for i in range(a[0] - 2):
	for j in range(a[1] - 2):
		if b[i][j] == '#':
			if b[i][j + 1] == '#':
				if b[i][j + 2] == '#':
					if b[i + 1][j] == '#':
						if b[i + 1][j + 2] == '#':
							if b[i + 2][j] == '#':
								if b[i + 2][j + 1] == '#':
									if b[i + 2][j + 2] == '#':
										d.append('b[' + str(i) + '][' + str(j) + ']')
										d.append('b[' + str(i) + '][' + str(j + 1) + ']')
										d.append('b[' + str(i) + '][' + str(j + 2) + ']')
										d.append('b[' + str(i + 1) + '][' + str(j) + ']')
										d.append('b[' + str(i + 1) + '][' + str(j + 2) + ']')
										d.append('b[' + str(i + 2) + '][' + str(j) + ']')
										d.append('b[' + str(i + 2) + '][' + str(j + 1) + ']')
										d.append('b[' + str(i + 2) + '][' + str(j + 2) + ']')
if set(c) == set(d):
	print('YES')
else:
	print('NO')


from copy import deepcopy
import itertools
from bisect import bisect_left
from bisect import bisect_right
import math
from collections import deque
from collections import Counter

def read():
	return int(input())

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

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

def is_valid(field, i, j):
	for k in range(3):
		for l in range(3):
			if k == 1 and l == 1:
				continue
			if field[i + k][j + l] == '.':
				return False
	return True

def fill_sgn(i, j):
	for k in range(3):
		for l in range(3):
			if k == 1 and l == 1:
				continue
			sgn[i + k][j + l] = '#'
(n, m) = readmap()
arr = []
sgn = []
for _ in range(n):
	arr.append(list(input()))
	sgn.append(['.'] * m)
for i in range(n - 2):
	for j in range(m - 2):
		if is_valid(arr, i, j):
			fill_sgn(i, j)
if arr == sgn:
	print('yes')
else:
	print('no')


(n, m) = map(int, input().split())
k = '#+'
a = []
p = False
for i in range(n):
	b = []
	for j in input():
		b.append(j)
	a.append(b)
for i in range(n):
	if p:
		break
	for j in range(m):
		if p:
			break
		if a[i][j] in k:
			if a[i][j] == '#' and (i > n - 3 or j > m - 3):
				print('NO')
				p = True
			elif not (i > n - 3 or j > m - 3):
				if a[i][j + 1] in k and a[i][j + 2] in k and (a[i + 1][j] in k) and (a[i + 1][j + 2] in k) and (a[i + 2][j] in k) and (a[i + 2][j + 1] in k) and (a[i + 2][j + 2] in k):
					a[i][j + 1] = '+'
					a[i][j + 2] = '+'
					a[i + 1][j] = '+'
					a[i + 1][j + 2] = '+'
					a[i + 2][j] = '+'
					a[i + 2][j + 1] = '+'
					a[i + 2][j + 2] = '+'
			elif a[i][j] == '#':
				p = True
				print('NO')
else:
	if not p:
		print('YES')


(n, m) = map(int, input().split())
(a, b) = ([], [['.' for j in range(m)] for i in range(n)])
for i in range(n):
	a.append(list(input()))
for i in range(n - 2):
	for j in range(m - 2):
		if a[i][j] == a[i + 1][j] == a[i + 2][j] == a[i][j + 1] == a[i + 2][j + 1] == a[i][j + 2] == a[i + 1][j + 2] == a[i + 2][j + 2] == '#':
			b[i][j] = b[i + 1][j] = b[i + 2][j] = b[i][j + 1] = b[i + 2][j + 1] = b[i][j + 2] = b[i + 1][j + 2] = b[i + 2][j + 2] = '#'
print('YNEOS'[a != b::2])


def inBound(i, n):
	return max(min(i, n - 1), 0)
(n, m) = map(int, input().split())
field = [list(input()) for i in range(n)]
ans = 1
field2 = [[0] * m for i in range(n)]
for i in range(n):
	for j in range(m):
		if i == 0 or i == n - 1 or j == 0 or (j == m - 1):
			field2[i][j] = 1
		if field[i][j] == '.':
			for i2 in range(-1, 2):
				for j2 in range(-1, 2):
					if i2 != 0 or j2 != 0:
						field2[inBound(i + i2, n)][inBound(j + j2, m)] = 1
for i in range(n):
	for j in range(m):
		if field[i][j] == '#':
			flag = 0
			for i2 in range(-1, 2):
				for j2 in range(-1, 2):
					if (i2 != 0 or j2 != 0) and field2[inBound(i + i2, n)][inBound(j + j2, m)] == 0:
						flag = 1
			if flag == 0:
				ans = 0
				break
	if ans == 0:
		break
print('YES' * ans + 'NO' * (1 - ans))


(n, m) = [int(t) for t in input().split()]
a = []
for i in range(n):
	s = list(input())
	a.append(s)
for i in range(n - 2):
	for j in range(m - 2):
		if (a[i][j] == '#' or a[i][j] == 'x') and (a[i + 1][j] == '#' or a[i + 1][j] == 'x') and (a[i + 2][j] == '#' or a[i + 2][j] == 'x') and (a[i][j + 1] == '#' or a[i][j + 1] == 'x') and (a[i][j + 2] == '#' or a[i][j + 2] == 'x') and (a[i + 1][j + 2] == '#' or a[i + 1][j + 2] == 'x') and (a[i + 2][j + 1] == '#' or a[i + 2][j + 1] == 'x') and (a[i + 2][j + 2] == '#' or a[i + 2][j + 2] == 'x'):
			a[i][j] = a[i + 1][j] = a[i + 2][j] = a[i][j + 1] = a[i][j + 2] = a[i + 1][j + 2] = a[i + 2][j + 1] = a[i + 2][j + 2] = 'x'
for i in range(n):
	for j in range(m):
		if a[i][j] == '#':
			print('NO')
			exit(0)
print('YES')


(n, k) = (int(i) for i in input().split())
a = list()
tu = {'#': True, '.': False}
for i in range(n):
	b = input()
	a.append([tu[r] for r in b])
c = list(([False for i in range(k)] for j in range(n)))
for i in range(n - 2):
	for j in range(k - 2):
		if a[i][j] & a[i + 1][j] & a[i + 2][j] & a[i][j + 1] & a[i + 2][j + 1] & a[i][j + 2] & a[i + 1][j + 2] & a[i + 2][j + 2]:
			(c[i][j], c[i + 1][j], c[i + 2][j], c[i][j + 1], c[i + 2][j + 1], c[i][j + 2], c[i + 1][j + 2], c[i + 2][j + 2]) = (True for z in range(8))
print(['YES', 'NO'][1 - (c == a)])


def main():
	nm = input('')
	n = 0
	m = 0
	l1 = nm.split()
	n = int(l1[0])
	nn = n
	m = int(l1[1])
	boo = False
	lista = []
	lista2 = []
	listaV = []
	baa = True
	while n > 0:
		st = input('')
		l1 = list(st)
		lista2 += l1
		n -= 1
	listaV.extend(lista2)
	for x in range(len(lista2)):
		listaV[x] = '.'
	for x in range(m - 2):
		for y in range(nn - 2):
			if check(lista2, x + y * m, m):
				listaV = draw(listaV, x + y * m, m)
	for x in range(len(lista2)):
		if lista2[x] != listaV[x]:
			print('NO')
			return
	print('YES')
	return

def check(lista, x, m):
	result = False
	if lista[x] == '#' and lista[x + 1] == '#' and (lista[x + 2] == '#') and (lista[x + m] == '#') and (lista[x + 2 + m] == '#') and (lista[x + 2 * m] == '#') and (lista[x + 1 + 2 * m] == '#') and (lista[x + 2 + 2 * m] == '#'):
		result = True
	else:
		result = False
	return result

def draw(lista, x, m):
	lista[x] = '#'
	lista[x + 1] = '#'
	lista[x + 2] = '#'
	lista[x + m] = '#'
	lista[x + 2 + m] = '#'
	lista[x + 2 * m] = '#'
	lista[x + 1 + 2 * m] = '#'
	lista[x + 2 + 2 * m] = '#'
	return lista
main()


(n, m) = map(int, input().split())
mp = []
is_filled = [[0] * 1003 for x in range(1003)]
for i in range(n):
	l = str(input())
	mp.append(l)

def ic(x, y):
	if x < 0 or y < 0 or x > n - 3 or (y > m - 3):
		return False
	for i in range(3):
		for j in range(3):
			if i == 1 and j == 1:
				continue
			if mp[x + i][y + j] == '.':
				return False
	return True

def mark(x, y):
	for i in range(3):
		for j in range(3):
			if i == 1 and j == 1:
				continue
			is_filled[x + i][y + j] = 1

def check(x, y):
	for i in range(3):
		for j in range(3):
			if i == 1 and j == 1:
				continue
			if x - i >= 0 and y - j >= 0 and ic(x - i, y - j):
				mark(x - i, y - j)
				return True
	return False
for i in range(n):
	for j in range(m):
		if mp[i][j] == '#' and is_filled[i][j] == 0:
			if not check(i, j):
				print('NO')
				exit(0)
print('YES')


def fill(x, y):
	for i in range(3):
		for j in range(3):
			if i == 1 and j == 1:
				continue
			r[x + i][y + j] = '#'

def ok(x, y):
	for i in range(3):
		for j in range(3):
			if i == 1 and j == 1:
				continue
			if l[x + i][y + j] == '.':
				return False
	return True
(n, m) = map(int, input().split())
st = ['.'] * m
l = []
r = []
for i in range(n):
	l += [list(input())]
	r += [['.'] * m]
for i in range(n - 2):
	for j in range(m - 2):
		if ok(i, j):
			fill(i, j)
if r == l:
	print('YES')
else:
	print('NO')


D = False

def hash(r, c):
	return str(r) + '-' + str(c)

def sol():
	(R, C) = [int(x) for x in input().split(' ')]
	m = []
	count = 0
	for _ in range(R):
		line = input()
		m.append(line)
		count += line.count('#')
	if D:
		print('Count:', count)
	lookup = {}
	for r in range(1, R - 1):
		for c in range(1, C - 1):
			if D:
				print('  row,col:', r, c)
			offset = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]
			lst = []
			fail = False
			for o in offset:
				cell = (r + o[0], c + o[1])
				if D:
					print('  cell:', cell, m[cell[0]][cell[1]])
				h = hash(cell[0], cell[1])
				if m[cell[0]][cell[1]] == '#':
					if not h in lookup:
						lst.append(h)
				else:
					fail = True
					break
			if not fail:
				for item in lst:
					lookup[item] = True
				count -= len(lst)
	return 'YES' if count == 0 else 'NO'
ans = sol()
print(ans)


def check(i, j, c_arr, n, m):
	if i != n - 1 and i != n - 2 and (j != m - 1) and (j != m - 2):
		if arr[i][j:j + 3] == '###' and arr[i + 2][j:j + 3] == '###' and (arr[i + 1][j] == '#') and (arr[i + 1][j + 2] == '#'):
			c_arr[i][j:j + 3] = [1, 1, 1]
			c_arr[i + 2][j:j + 3] = [1, 1, 1]
			c_arr[i + 1][j] = 1
			c_arr[i + 1][j + 2] = 1
			return True
	if c_arr[i][j] == 1:
		return True
	return False
(n, m) = map(int, input().split())
c_arr = [[0 for i in range(m)] for j in range(n)]
arr = []
k = True
for _ in range(n):
	arr.append(input())
for i in range(n):
	for j in range(m):
		if arr[i][j] == '#':
			k = check(i, j, c_arr, n, m)
			if not k:
				break
	if not k:
		print('NO')
		break
else:
	print('YES')


n = [int(i) for i in input().split()]
l = [[0 for i in range(n[1])] for j in range(n[0])]
for i in range(n[0]):
	x = input()
	for j in range(n[1]):
		if x[j] == '#':
			l[i][j] = 2
		else:
			l[i][j] = 0
m = 1
for i in range(n[0]):
	for j in range(n[1]):
		if l[i][j] != 0 and i + 3 <= n[0] and (j + 3 <= n[1]):
			c = 0
			for i1 in range(3):
				for j1 in range(3):
					if l[i + i1][j + j1] == 0 and (i1 != j1 or j1 != 1):
						c = 1
			if c == 0:
				for i1 in range(3):
					for j1 in range(3):
						if i1 != j1 or j1 != 1:
							l[i + i1][j + j1] = 1
		if l[i][j] == 2:
			m = 0
			break
	if m == 0:
		break
if m == 1:
	print('YES')
else:
	print('NO')


def int_list_from_line():
	return [int(num) for num in input().split()]

def bool_list_from_char_line():
	true_char = '#'
	return [char == true_char for char in input()]
(n, m) = int_list_from_line()
sign = []
for i in range(n):
	sign.append(bool_list_from_char_line())

def neighbours(i, j):
	yield (i, j + 1)
	yield (i, j - 1)
	yield (i + 1, j)
	yield (i - 1, j)
	yield (i + 1, j + 1)
	yield (i + 1, j - 1)
	yield (i - 1, j + 1)
	yield (i - 1, j - 1)

def all_around(sign, i, j):
	if i == 0 or j == 0:
		return False
	try:
		for (ni, nj) in neighbours(i, j):
			if not sign[ni][nj]:
				return False
		return True
	except IndexError:
		return False
for (i, line) in enumerate(sign):
	for (j, value) in enumerate(line):
		if not value:
			continue
		found = False
		for (ni, nj) in neighbours(i, j):
			if all_around(sign, ni, nj):
				found = True
		if not found:
			print('NO')
			exit()
print('YES')


(n, m) = tuple(map(int, input().split()))
grid = [list(input()) for _ in range(n)]
forbidden = [['N'] * m for _ in range(n)]

def getAdjacent(n, m, i, j):
	cells = list()
	if i - 1 != -1 and j - 1 != -1 and (i + 1 != n) and (j + 1 != m):
		return [(i - 1, j - 1), (i, j - 1), (i + 1, j - 1), (i - 1, j), (i + 1, j), (i - 1, j + 1), (i, j + 1), (i + 1, j + 1)]
	elif i - 1 == -1 and j - 1 == -1:
		return [(i + 1, j), (i + 1, j + 1), (i, j + 1)]
	elif i - 1 == -1 and j - 1 != -1 and (j + 1 != m):
		return [(i, j - 1), (i + 1, j - 1), (i + 1, j), (i + 1, j + 1), (i, j + 1)]
	elif i - 1 == -1 and j + 1 == m:
		return [(i, j - 1), (i + 1, j - 1), (i + 1, j)]
	elif i - 1 != -1 and i + 1 != n and (j - 1 == -1):
		return [(i - 1, j), (i - 1, j + 1), (i, j + 1), (i + 1, j), (i + 1, j + 1)]
	elif i - 1 != -1 and i + 1 != n and (j + 1 == m):
		return [(i - 1, j), (i - 1, j - 1), (i, j - 1), (i + 1, j - 1), (i + 1, j)]
	elif i + 1 == n and j - 1 == -1:
		return [(i - 1, j), (i - 1, j + 1), (i, j + 1)]
	elif i + 1 == n and j - 1 > -1 and (j + 1 != m):
		return [(i - 1, j - 1), (i - 1, j), (i - 1, j + 1), (i, j - 1), (i, j + 1)]
	else:
		return [(i - 1, j - 1), (i - 1, j), (i, j - 1)]
for i in range(0, n):
	for j in range(0, m):
		if i == 0 or j == 0 or i == n - 1 or (j == m - 1):
			forbidden[i][j] = 'Y'
		if grid[i][j] == '.':
			for (p, q) in getAdjacent(n, m, i, j):
				forbidden[p][q] = 'Y'
for i in range(0, n):
	for j in range(0, m):
		if grid[i][j] == '#':
			ok = False
			for (p, q) in getAdjacent(n, m, i, j):
				if forbidden[p][q] == 'N':
					ok = True
					break
			if not ok:
				print('NO')
				exit()
print('YES')


(n, m) = [int(x) for x in input().split()]
sign = []
bad = False
for _ in range(n):
	sign.append(input())
for i in range(n):
	if bad:
		break
	for j in range(m):
		if bad:
			break
		if sign[i][j] == '#':
			bad = True
			if 0 < i < n - 1 and sign[i - 1][j] == '#' and (sign[i + 1][j] == '#'):
				if j > 1 and sign[i - 1][j - 1] == '#' and (sign[i - 1][j - 2] == '#') and (sign[i + 1][j - 1] == '#') and (sign[i + 1][j - 2] == '#') and (sign[i][j - 2] == '#'):
					bad = False
					continue
				if j + 2 < m and sign[i - 1][j + 1] == '#' and (sign[i - 1][j + 2] == '#') and (sign[i + 1][j + 1] == '#') and (sign[i + 1][j + 2] == '#') and (sign[i][j + 2] == '#'):
					bad = False
					continue
			if i > 1 and sign[i - 2][j] == '#':
				if 0 < j < m - 1 and sign[i][j - 1] == '#' and (sign[i][j + 1] == '#') and (sign[i - 1][j - 1] == '#') and (sign[i - 1][j - 1] == '#') and (sign[i - 2][j - 1] == '#') and (sign[i - 2][j - 1] == '#'):
					bad = False
					continue
				if j > 1 and sign[i][j - 1] == '#' and (sign[i][j - 2] == '#') and (sign[i - 1][j - 2] == '#') and (sign[i - 1][j] == '#') and (sign[i - 2][j - 1] == '#') and (sign[i - 2][j - 2] == '#'):
					bad = False
					continue
				if j + 2 < m and sign[i][j + 1] == '#' and (sign[i][j + 2] == '#') and (sign[i - 1][j + 2] == '#') and (sign[i - 1][j] == '#') and (sign[i - 2][j + 1] == '#') and (sign[i - 2][j + 2] == '#'):
					bad = False
					continue
			if i + 2 < n and sign[i + 2][j] == '#':
				if 0 < j < m - 1 and sign[i][j - 1] == '#' and (sign[i][j + 1] == '#') and (sign[i + 1][j - 1] == '#') and (sign[i + 1][j - 1] == '#') and (sign[i + 2][j - 1] == '#') and (sign[i + 2][j - 1] == '#'):
					bad = False
					continue
				if j > 1 and sign[i][j - 1] == '#' and (sign[i][j - 2] == '#') and (sign[i + 1][j - 2] == '#') and (sign[i + 1][j] == '#') and (sign[i + 2][j - 1] == '#') and (sign[i + 2][j - 2] == '#'):
					bad = False
					continue
				if j + 2 < m and sign[i][j + 1] == '#' and (sign[i][j + 2] == '#') and (sign[i + 1][j + 2] == '#') and (sign[i + 1][j] == '#') and (sign[i + 2][j + 1] == '#') and (sign[i + 2][j + 2] == '#'):
					bad = False
					continue
if bad:
	print('NO')
else:
	print('YES')


from os import path
import sys, time
from math import ceil, floor, gcd, log, log2, factorial
from collections import defaultdict, Counter, deque
from itertools import permutations
maxx = float('inf')
I = lambda : int(sys.stdin.buffer.readline())
tup = lambda : map(int, sys.stdin.buffer.readline().split())
lint = lambda : [int(x) for x in sys.stdin.buffer.readline().split()]
S = lambda : sys.stdin.readline().replace('\n', '').strip()

def grid(r, c):
	return [lint() for i in range(r)]
stpr = lambda x: sys.stdout.write(f'{x}' + '\n')
star = lambda x: print(' '.join(map(str, x)))
localsys = 0
start_time = time.time()
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
(n, m) = tup()
ar = [[i for i in S()] for _ in range(n)]
c = [['.'] * m for _ in range(n)]
f = 0
for i in range(1, n - 1):
	for j in range(1, m - 1):
		if ar[i][j - 1] == ar[i][j + 1] == ar[i + 1][j] == ar[i + 1][j - 1] == ar[i + 1][j + 1] == ar[i - 1][j] == ar[i - 1][j - 1] == ar[i - 1][j + 1] == '#':
			(c[i][j - 1], c[i][j + 1], c[i + 1][j], c[i + 1][j - 1], c[i + 1][j + 1], c[i - 1][j], c[i - 1][j - 1], c[i - 1][j + 1]) = ('#', '#', '#', '#', '#', '#', '#', '#')
if c == ar:
	f = 1
print('YES') if f else print('NO')
if localsys:
	print('\n\nTime Elased :', time.time() - start_time, 'seconds')


(m, n) = input().split()
(m, n) = (int(m), int(n))
F = []
P = []
dx = [-1, 0, 1, -1, 1, -1, 0, 1]
dy = [-1, -1, -1, 0, 0, 1, 1, 1]
for i in range(m):
	F.append(input())
	P.append([0] * n)
for i in range(1, m - 1):
	for j in range(1, n - 1):
		flag = True
		for (x, y) in zip(dx, dy):
			(ii, jj) = (i + x, j + y)
			if F[ii][jj] == '.':
				flag = False
				break
		if flag:
			for (x, y) in zip(dx, dy):
				(ii, jj) = (i + x, j + y)
				P[ii][jj] = 1
flag = True
for i in range(m):
	for j in range(n):
		if F[i][j] == '#' and P[i][j] == 0:
			flag = False
			break
if flag:
	print('YES')
else:
	print('NO')


(n, m) = [int(i) for i in input().split()]
A = []
ct = []
for i in range(n):
	x = list(input())
	y = [0] * m
	A.append(x)
	ct.append(y)
ok = 1
for i in range(n - 2):
	for j in range(m - 2):
		if A[i][j] == '#' and A[i][j + 1] == '#' and (A[i][j + 2] == '#') and (A[i + 1][j] == '#') and (A[i + 2][j] == '#') and (A[i + 2][j + 1] == '#') and (A[i + 2][j + 2] == '#') and (A[i + 1][j + 2] == '#'):
			ct[i][j] = 1
			ct[i][j + 1] = 1
			ct[i][j + 2] = 1
			ct[i + 1][j] = 1
			ct[i + 1][j + 2] = 1
			ct[i + 2][j] = 1
			ct[i + 2][j + 1] = 1
			ct[i + 2][j + 2] = 1
xct = 0
xhs = 0
for i in range(len(ct)):
	for j in range(len(ct[i])):
		if ct[i][j] == 1:
			xct += 1
		if A[i][j] == '#':
			xhs += 1
if xhs == xct:
	print('YES')
else:
	print('NO')