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

Starter code:

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


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

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

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 = list(map(int, input().split()))

mp = []

for i in range(n):
    line = input().strip()
    
    mp.append(list([c == '#' for c in 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 = 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
##        print(ok)
        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 u:
##    print(i)
##for i in u1:
##    print(i)
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')


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

3

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


def __starting_point():
    main()

__starting_point()

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):
        # print('Attempting on i=%d,j=%d'%(i,j))
        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 mi():
	return list(map(int, input().split()))

'''
5 7
.......
.#####.
.#.#.#.
.#####.
.......
'''
n,m = mi()
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')
			return
print ('YES')


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



N, M = list(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")
                return

print("YES")


from math import ceil, sqrt
#from sys import stdout
#from collections import deque

t = 1#int(input())
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=[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):
    nonlocal 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 = 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')
        return
print('YES')

#!/usr/bin/env python3
import sys

def rint():
    return list(map(int, sys.stdin.readline().split()))
#lines = stdin.readlines()

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

#for i in range(n):
#    for j in range(m):
#        print(cells[i][j], end='')
#    print()

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")
            return

print("YES")


"""n,L,a=map(int,input().split())
#s=[int(x) for x in input().split()]
ed=0
ct=0
for j in range(0,n):
    t,l=map(int,input().split())
    ct=ct+((t-ed)//a)
    ed=t+l
t=L
ct=ct+((t-ed)//a)
print(ct)"""

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)]
#dp=[]
#dp2=[]
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):
        #print(i,j)
        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]='#'


                        
#print(dp)
#print(dp2)
if(dp==dp2):
    print('YES')
else:
    print('NO')

                            


n,m=list(map(int,input().split()))
s=[]
for i in range(n):
	s.append(list(map(str,input().strip())))
#print(s)
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
#print(t)
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 = [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")
                return
print("YES")

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)]
#print(op)
b=0
for i in range(n):
    ip.append(str(input()))
#print(ip,ip[1][1])
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]=='#')
                    #print(temp)
                    if temp==True:
                        color8(i,j,op)
            except:
                pass
#print(ip,op)
for i in range(n):
    if ''.join(op[i])!=ip[i]:
        print('NO')
        b=1
        break
if b==0:
    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);
#print('board = ');
#print(board);
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');
		return;
print('YES');


#!/usr/bin/env python
    
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")


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=list(map(int,input().split()))
a=[list('') for x in range(n)]
b=[list('.'*m) for x in range(n)]
start=0
#end=n-2
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)
#print(start)
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]!='#':
                            #print('lel')
                            #print(x,y)
                            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]='#'
                        
#for i in a:
#    print(i)
#print()
#for i in b:
#    print(i)
    
if a==b:
    print('YES')
else:
    print('NO')


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