Problem:
 Score: 300 points    Problem Statement  We have a canvas divided into a grid with H rows and W columns. The square at the i -th row from the top and the j -th column from the left is represented as (i, j) . Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}=  # , and to make Square (i, j) white when s_{i, j}=  . . However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black. Determine if square1001 can achieve his objective.      Constraints   H is an integer between 1 and 50 (inclusive).  W is an integer between 1 and 50 (inclusive).  For every (i, j)  (1 \leq i \leq H, 1 \leq j \leq W) , s_{i, j} is # or . .         Input  Input is given from Standard Input in the following format:  H  W  s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}  s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}  :  :  s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}       Output  If square1001 can achieve his objective, print Yes ; if he cannot, print No .        Sample Input 1 3 3
.#.
###
.#.      Sample Output 1 Yes  One possible way to achieve the objective is shown in the figure below. Here, the squares being painted are marked by stars.        Sample Input 2 5 5
#.#.#
.#.#.
#.#.#
.#.#.
#.#.#      Sample Output 2 No  square1001 cannot achieve his objective here.       Sample Input 3 11 11
...#####...
.##.....##.
#..##.##..#
#..##.##..#
#.........#
#...###...#
.#########.
.#.#.#.#.#.
##.#.#.#.##
..##.#.##..
.##..#..##.      Sample Output 3 Yes

Solution (Python):

import math
import sys


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



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



def instr():
    s = input()
    return(list(s[:len(s)]))



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


def valid(x, y):
    if x >= 0 and x < row and y >= 0 and y < col:
        return True
    return False


fx = [0, 0, 1, -1]
fy = [1, -1, 0, 0]
row, col = invr()

a = []

for _ in range(row):
    a.append(instr())

for i in range(row):
    for j in range(col):

        if a[i][j] == "
            can_paint = 0
            for k in range(4):
                nx = i + fx[k]
                ny = j + fy[k]
                if valid(nx, ny) and a[nx][ny] == "
                    can_paint = 1
                    break
            if can_paint == 0:
                print("No")
                sys.exit()
print("Yes")

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7

 
H, W = MAP()
s = [input() for _ in range(H)]

dy = (1, 0, -1, 0)
dx = (0, -1, 0, 1)

for x in range(W):
	for y in range(H):
		if s[y][x] =="
			for i in range(4):
				ny = y + dy[i]
				nx = x + dx[i]
				if 0 <= ny < H and 0 <= nx < W and s[ny][nx] == "
					break
			else:
				print("No")
				exit()

print("Yes")

Solution (Python):
h, w = map(int, input().split())
M = [input() for _ in range(h)]

ng = False
for i in range(h):
    for j in range(w):
        if M[i][j]  == '.':
            continue

        for mi, mj in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
            ni = i + mi; nj = j + mj
            if ni < 0 or h <= ni or nj < 0 or w <= nj:
                continue

            if M[ni][nj] == '
                break
        else:
            ng=True
    if ng:
        break

if ng:
    print('No')
else:
    print('Yes')

Solution (Python):
import sys
h,w = map(int,input().split())
ls = ["0"*(w+2)]
ls += ["0" + str(input()) + "0" for _ in range(h)]
ls += ["0"*(w+2)]
for i in range(1,h+1):
    for j in range(1,w+1):
        if ls[i][j] == "
            if ls[i-1][j] != "
                print("No")
                sys.exit()
print("Yes")

Solution (Python):
H,W=map(int,input().split())
hw=[['.']*(W+2)]+[['.']+list(input())+['.']for _ in range(H)]+[['.']*(W+2)]

ans='Yes'
h=1
while h<=H:
    w=1
    while w<=W:
        if hw[h][w]=='
            if all([hw[h-1][w]=='.',hw[h+1][w]=='.',hw[h][w-1]=='.',hw[h][w+1]=='.']):
                ans='No'
        w+=1
    h+=1

print(ans)

Solution (Python):
h,w=map(int,input().split())
s=[input() for _ in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j]=="
            if (i>0 and s[i-1][j]=="
                pass
            else:
                print("No")
                exit()
print("Yes")

Solution (Python):
def is_valid(s, i, j):
    if s[i][j] == '.':
        return True

    if i > 0 and s[i-1][j] == '
        return True

    if j > 0 and s[i][j-1] == '
        return True

    if i < len(s) - 1 and s[i+1][j] == '
        return True

    if j < len(s[i]) - 1 and s[i][j+1] == '
        return True

    return False


h, w = map(int, input().split())

s = []

for i in range(h):
    s.append(input())

for i in range(h):
    for j in range(w):
        if not is_valid(s, i, j):
            print('No')
            exit()

print('Yes')

Solution (Python):
H,W=map(int,input().split())
S=[0]*H
for i in range(H):
  S[i]=list(str(input()))

dx=[-1,0,1,0]
dy=[0,-1,0,1]

for i in range(H):
  for j in range(W):
    ok=0
    if S[i][j]=='
      for k in range(4):
        x=j+dx[k]
        y=i+dy[k]
        if 0<=x<W and 0<=y<H and S[y][x]=='
          ok=1
          break
      if ok==0:
        print('No')
        exit()
print('Yes')

Solution (Python):
def main():
    h, w = map(int, input().split())
    s = [list(input()) for _ in range(h)]
    
    def judge(y, x):
        if s[y][x] == '.':
            return True
        for dx, dy in [[-1, 0], [0, -1], [1, 0], [0, 1]]:
            ny = y + dy
            nx = x + dx
            if 0<= ny < h and 0<= nx < w:
                if s[ny][nx] == '
                    return True
        return False
            
        
    for y in range(h):
        for x in range(w):
            if judge(y, x) == False:
                print('No')
                return
    else:
        print('Yes')
        
        
if __name__ == '__main__':
    main()

Solution (Python):
H, W = map(int, input().split())
sheet = []
flame = ""
for i in range(W+ 2):
  flame+= "."

sheet.append(flame)  
for i in range(H):
  row = "."+ input()+ "."
  sheet.append(row)
  
sheet.append(flame)

flag = 1
for i in range(1, H+ 1):
  for j in range(1, W+ 1):
    if(sheet[i][j] == "
      if(sheet[i- 1][j] != "
        sheet[i+ 1][j] != "
        flag = 0
        print("No")
        break
  if(flag == 0):
    break

if(flag == 1):
  print("Yes")

Solution (Python):
h,w = map(int,input().split())
grid = list('.' + input() + '.' for _ in range(h))
grid = ['.'*(w+2)] + grid + ['.'*(w+2)]
for i in range(1,h+1):
    for j in range(1,w+1):
        if grid[i][j] == '
            if '
                continue
            else:
                print("No")
                quit()
print("Yes")

Solution (Python):
H, W = map(int, input().split())
field = [input() for _ in range(H)]
drawable = True
for i in range(H):
    for j in range(W):
        if field[i][j] == ".":
            continue
        for di, dj in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            ni, nj = i + di, j + dj
            if 0 <= ni < H and 0 <= nj < W and field[ni][nj] == "
                break
        else:
            drawable = False
print("Yes") if drawable else print("No")

Solution (Python):
H, W=map(int, input().split())
s=["."]*(W+2)
a=[s]
for i in range(H):
  tmp=input()
  tmp="."+tmp+"."
  a.append(list(tmp))
a.append(s)

ans="Yes"
dero=False
for i in range(1,H+1):
  for j in range(1,W+1):
    if a[i][j]==".":
      continue
    f1=a[i-1][j]=="."
    f2=a[i+1][j]=="."
    f3=a[i][j+1]=="."
    f4=a[i][j-1]=="."
    if f1 and f2 and f3 and f4:
      ans="No"
      dero=True
      break
  if dero:
    break
print(ans)

Solution (Python):
h,w = map(int, input().split())
original = [list(input()) for _ in range(h)]
for i in range(h-1):
  for j in range(w-1):
    if original[i][j]=='
      print('No')
      exit()
      
print('Yes')

Solution (Python):
h,w=map(int,input().split())
a=['.'*(w+2)]
for i in range(h):
  a.append('.'+input()+'.')
a.extend(['.'*(w+2)])
flg=0
for i in range(1,h+1):
  for j in range(1,w+1):
    if a[i][j] == '
      if a[i-1][j] == '.' and a[i][j-1] == '.' and a[i+1][j] == '.' and a[i][j+1] == '.':
        flg = 1
if flg == 0:
  print('Yes')
else:
  print('No')

Solution (Python):
h, w = map(int, input().split())
field = [input() for i in range(h)]
DXY = [(1, 0), (0, 1), (-1, 0), (0, -1)]
for y in range(h):
	for x in range(w):
		if field[y][x] == '
			flag = False
			for dy, dx in DXY:
				ny = y + dy
				nx = x + dx
				if not (0 <= ny < h and 0 <= nx < w):
					continue
				if field[ny][nx] == '
					flag = True
					break
			if flag == False:
				print("No")
				exit()
else:
	print("Yes")

Solution (Python):
H, W = map(int, input().split())
grid = [list(input()) for _ in range(H)]
direction = (-1, 1)
H -= 1
W -= 1
for h, line in enumerate(grid):
    for w, g in enumerate(line):
        if g == '.':
            continue
        pos = ((h - 1, w), (h + 1, w), (h, w - 1), (h, w + 1))
        for y, x in pos:
            if y < 0 or H < y:
                continue
            if x < 0 or W < x:
                continue
            if grid[y][x] == '
                break
        else:
            print('No')
            break
    else:
        continue
    break
else:
    print('Yes')

Solution (Python):
h,w=map(int,input().split())
s=[["."]*(w+2)]
for i in range(h):
  temp=list(map(str,input()))
  temp.insert(0,".")
  temp.append(".")
  s.append(temp)
s.append(["."]*(w+2))
count=0
for i in range(1,h+1):
  for j in range(1,w+1):
    if s[i][j]=="
      if s[i+1][j]=="." and s[i-1][j]=="." and s[i][j+1]=="." and s[i][j-1]==".":
        count=count+1
if count>0:
  print("No")
else:
  print("Yes")

Solution (Python):
H,W=map(int,input().split())
S=["."*(W+2)]+["."+input()+"." for i in range(H)]+["."*(W+2)]
for i in range(1,H+1):
    for j in range(1,W+1):
        if S[i][j]=="
            if S[i+1][j]=="." and S[i-1][j]=="." and S[i][j-1]=="." and S[i][j+1]==".":
                print("No")
                exit()
print("Yes")

Solution (Python):
h,w = [int(i)  for i in input().split()]

listHW = []
flag = False
for i in range(0, h):
  listHW.append(list(input()))

  
for i in range(0, len(listHW)):
  if flag:
    break
  listw = listHW[i]
  
  for ii in range(0, len(listw)):
    w = listw[ii]
    if w == "
      
    
      if i == 0:
        
        if ii == len(listw)-1:
          if w == listHW[i+1][ii] or w == listw[ii-1]:
            continue
        
        elif ii == 0:
          if w == listHW[i+1][ii] or w == listw[ii+1]:
            continue 
        
        elif w == listw[ii+1] or w == listw[ii-1] or w == listHW[i+1][ii]:
          continue

      elif i == len(listHW)-1:
        
        if ii == len(listw)-1:
          if w == listHW[i-1][ii] or w == listw[ii-1]:
            continue
        
        elif ii == 0:
          if w == listHW[i-1][ii] or w == listw[ii+1]:
            continue 
        
        elif w == listw[ii+1] or w == listw[ii-1] or w == listHW[i-1][ii]:
          continue
      
      
      elif ii == 0:
        if w == listw[ii+1]  or w == listHW[i-1][ii] or w == listHW[i+1][ii]:
          continue
      
      elif ii == len(listw)-1:
        if w == listw[ii-1]  or w == listHW[i-1][ii] or w == listHW[i+1][ii]:
          continue
              
      
      elif w == listw[ii-1] or w == listw[ii+1]or w == listHW[i-1][ii] or w == listHW[i+1][ii]:
        continue

      
      
      flag = True
      break
    
    
    else:
      continue
    



if flag:
  print("No")
else:
  print("Yes")

Solution (Python):

"""
Created on Thu May 28 22:59:47 2020

@author: naoki
"""
import sys

H,W = map(int,input().split()) 
square = [input() for i in range(H)] 
zero_input = [str(0) for i in range(W+2)] 
zero_row1 = "".join(zero_input) 
zero_row2 = [zero_row1]

for i in range(H):
    square[i] = "0" + square[i] + "0" 

square = zero_row2 + square + zero_row2 

dy = [-1,0,0,1] 
dx = [0,-1,1,0] 

for i in range(1,H+1):
    for j in range(1,W+1):
        if square[i][j] == "
            count = 0
            for k in range(4):
                if square[i+dx[k]][j+dy[k]] == "
                    count+=1
            if count ==0:
                print("No")
                sys.exit()
print("Yes")

Solution (Python):
H,W = map(int,input().split())

s=[list(str(input())) for _ in range(H)]

di=[1,-1,0,0]
dj=[0,0,1,-1]
for i in range(H):
    for j in range(W):
        if s[i][j]=='
            found=False
            for k in range(4):
                i2=i+di[k]
                j2=j+dj[k]
                if 0<=i2 and i2<H and 0<=j2 and j2<W:
                    if s[i2][j2]=='
                        found=True
            if not found:
                print('No')
                exit()

print('Yes')

Solution (Python):
n,m = map(int,input().split())

s=[list(str(input())) for _ in range(n)]

di=[1,-1,0,0]
dj=[0,0,1,-1]
for i in range(n):
    for j in range(m):
        if s[i][j]=='
            found=False
            for k in range(4):
                i2=i+di[k]
                j2=j+dj[k]
                if 0<=i2 and i2<n and 0<=j2 and j2<m:
                    if s[i2][j2]=='
                        found=True
            if not found:
                print('No')
                exit()

print('Yes')

Solution (Python):
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

for i in range(1, h-1):
    for j in range(1, w-1):
        if s[i][j] == '
            print('No')
            exit()
print('Yes')

Solution (Python):
h, w = map(int, input().split())

s = []
for _ in range(h):
    s.append(list(input()))
    
direction = [[0, 1], [0, -1], [1, 0], [-1, 0]]
for i in range(h):
    for j in range(w):
        if s[i][j] == "
            for dy, dx in direction:
                y = i + dy
                x = j + dx
                try:
                    if s[y][x] == "
                        break
                except IndexError:
                    pass
            else:
                print("No")
                exit()
print("Yes")

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

DX = [-1,0,1,0]
DY = [0,1,0,-1]
for h in range(H):
    for w in range(W):
        if S[h][w] == "
            count = 0
            for dx,dy in zip(DX, DY):
                if H-1>=h-dy >= 0 and W-1>=w-dx >= 0 and S[h-dy][w-dx] == ".":
                    count += 1
            if count == 4:
                print("No")
                exit()
print("Yes")

Solution (Python):
H, W = map(int, input().split())
grid = []
flag = 1
for h in range(H):
  S = input()
  tmp = []
  for s in S:
    tmp.append(s)
  grid.append(tmp)

for h in range(H):
  for w in range(W):
    mark = grid[h][w]
    if mark == ".": continue

    if h-1 >= 0:
      up = grid[h-1][w]
    else: up = "."

    if h+1 <= H-1:
      down = grid[h+1][w]
    else: down = "."

    if w-1 >= 0:
      left = grid[h][w-1]
    else: left = "."
    
    if w+1 <= W-1:
      right = grid[h][w+1]
    else: right = "."

    if (up != "
      flag = 0
      break

if flag == 1: print("Yes")
else:print("No")

Solution (Python):

import sys
input = sys.stdin.readline









H,W = map(int,input().split())
S = [input().rstrip() for _ in range(H)]

for h in range(H):
    for w in range(W):
        
        if S[h][w]==".":
            continue
        
        flg = False
        for dh,dw in [(1,0), (-1,0), (0,1), (0,-1)]:
            nh = h+dh
            nw = w+dw
            if 0 <= nh < H and 0 <= nw < W:
                if S[nh][nw] == "
                    flg = True
                    break
        if not flg:
            print("No")
            sys.exit()

print("Yes")

Solution (Python):
h,w = map(int,input().split())
table = [0]*h
for i in range(h):
    table[i] = list(input())

for i in range(h):
    for j in range(w):
        if table[i][j] == "
            if i - 1 >= 0 and table[i-1][j] == "
                ok = True
            elif i + 1 <= h-1 and table[i+1][j] == "
                ok = True
            elif j - 1 >= 0 and table[i][j-1] == "
                ok = True
            elif j + 1 <= w-1 and table[i][j+1] == "
                ok = True
            else:
                ok = False
            if ok == False:
                 print("No")
                 exit()
print("Yes")

Solution (Python):
import sys

a = sys.stdin.readline().split(' ')
data = sys.stdin.readlines()

S = int(a[0])
H = int(a[1])

dx = [0,1,0,-1]
dy = [1,0,-1,0]

for i in range(S):
    for j in range(H):
        count = 0
        if data[i][j] == '
            for k in range(4):
                x = j + dx[k]
                y = i + dy[k]
                if x < 0 or y < 0 or x >= H or y >= S:
                    continue
                else:
                    if data[y][x] == "
                        count = count+1
            if count == 0:
                print('No')
                sys.exit()


print('Yes')

Solution (Python):
def surrounded_by_pound(grid, i, j):
  return '


def paintable(grid):
  for i in range(1, H+1):
    for j in range(1, W+1):
      if grid[i][j] == '
        return False
  return True



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

grid = []
grid.append('.' * (W+2))
for _ in range(H):
  grid.append('.' + input() + '.')
grid.append('.' * (W+2))

print('Yes') if paintable(grid) else print('No')

Solution (Python):
H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]
flag = 1
dx = [1,-1,0,0]
dy = [0,0,1,-1]
for i in range(H):
  for j in range(W):
    if A[i][j] =="
        flag2 = 0
        for k in range(4):
            if 0<= i+dx[k] <= H-1 and 0<= j+dy[k] <= W-1:
                if A[i+dx[k]][j+dy[k]] == "
                    flag2 = 1
        if not flag2:
            flag = 0
print("Yes" if flag else "No")

Solution (Python):
H,W = map(int, input().split())

m = []
for _ in range(H):
    line = list(input())
    m.append(line)

for y in range(H):
    for x in range(W):
        if m[y][x]==".":
            continue
        if y+1<H and m[y+1][x]=="
            continue

        if y-1>-1 and m[y-1][x]=="
            continue

        if x+1<W and m[y][x+1]=="
            continue

        if x-1>-1 and m[y][x-1]=="
            continue
        print("No")
        exit()

print("Yes")

Solution (Python):
h, w = map(int, input().split())
s = [["." for j in range(w+2)] for i in range(h+2)]

for i in range(h):
    tmp = list(input())
    for j in range(1, w+1):
        s[i][j] = tmp.pop()

for i in range(1, h+1):
    for j in range(1, w+1):
        up = s[i-1][j]
        down = s[i+1][j]
        left = s[i][j-1]
        right = s[i][j+1]

        if  s[i][j] == "
            print("No")
            exit()

print("Yes")

Solution (Python):
h, w = map(int, input().split())
s = []
for i in range(h):
    s.append(list(input()))

for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            continue
        
        if 0 <= i-1:
            up = s[i-1][j]
        else:
            up = s[i][j]
        
        if i+1 < h:
            down = s[i+1][j]
        else:
            down = s[i][j]

        if 0 <= j-1:
            left = s[i][j-1]
        else:
            left = s[i][j]
        
        if j+1 < w:
            right = s[i][j+1]
        else:
            right = s[i][j]
        
        if s[i][j] != up and s[i][j] != down and s[i][j] !=left and s[i][j] != right:
            print("No")
            exit()

print("Yes")

Solution (Python):
H,W = map(int,input().split())
arr = []

for i in range(H):
  S = list(input())
  arr.append(S)
  
ck = 0
for i in range(H):
  for j in range(W):
    if arr[i][j] == "
      if i != 0:
        a = arr[i-1][j]
      else:
        a = "."
      if i != H-1:
        b = arr[i+1][j]
      else:
        b = "."
      if j != 0:
        c = arr[i][j-1]
      else:
        c = "."
      if j != W-1:
        d = arr[i][j+1]
      else:
        d = "."

      if a == "." and b == "." and c == "." and d == ".":
        ck = 1
      
if ck == 1:
  print("No")
else:
  print("Yes")

Solution (Python):
h,w = map(int,input().split())
s = ["."*(w+2) for _ in range(h+2)]
road = []
setroad = set([])

for i in range(1, h+1):
	s[i] = "." + input() + "."

for i in range(h+2):
	for j in range(w+2):
		if s[i][j] == "
			setroad.add((i,j))
			road.append((i,j))

def isnotland(n, m):
	if not (n, m) in setroad:
		return True
	else:
		return False

ans = 1

for x, y in road:
	if isnotland(x, y+1) and isnotland(x, y-1) and isnotland(x-1, y) and isnotland(x+1, y):
		ans = 0

print(["No","Yes"][ans])

Solution (Python):
from collections import deque
def make_wall(maze,h,w):
    maze=deque(maze)
    for i in range(h):
        maze[i]="."+maze[i]+"."
    maze.appendleft("."*(w+2))
    maze.append("."*(w+2))
    return list(maze)

h,w=map(int,input().split())
s=[input() for _ in range(h)]
s=make_wall(s,h,w)
ans="Yes"
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j]=="
            if "
                ans="No"
                break
    else:
        continue
    break
print(ans)

Solution (Python):
h, w=map(int, input().split())
s=['.'*(w+2)]+['.'+input()+'.' for _ in range(h)]+['.'*(w+2)]
for i in range(1, h+1):
  for j in range(1, w+1):
    if s[i][j]=='
      if '
        print('No')
        exit()
print('Yes')

Solution (Python):
h,w=map(int,input().split())
s=list(input()for _ in range(h))
if h==w==1:
    print('No')
    exit()
elif h==1:
        for i in range(w):
            if s[0][i]=='
                if i==0:
                    if s[0][i+1]=='.':
                        print('No')
                        exit()
                elif i==w-1:
                    if s[0][i-1]=='.':
                        print('No')
                        exit()
                else:
                    if s[0][i-1]=='.'and s[0][i+1]=='.':
                        print('No')
                        exit()
elif w==1:
        for i in range(h):
            if s[i][0]=='
                if i==0:
                    if s[i+1][0]=='.':
                        print('No')
                        exit()
                elif i==w-1:
                    if s[i-1][0]=='.':
                        print('No')
                        exit()
                else:
                    if s[i-1][0]=='.'and s[i+1][i-1]=='.':
                        print('No')
                        exit()
else:
    for i in range(h):
      for j in range(w):
        if s[i][j]=='
            if i==0:
                if j==0:
                    if s[i+1][j]=='.'and s[i][j+1]=='.':
                        print('No')
                        exit()
                if j==w-1:
                    if s[i+1][j]=='.'and s[i][j-1]=='.':
                        print('No')
                        exit()
                else:
                    if s[i+1][j]=='.'and s[i][j+1]=='.' and s[i][j-1]=='.':
                        print('No')
                        exit()
            if i==h-1:
                if j==0:
                    if s[i-1][j]=='.'and s[i][j+1]=='.':
                        print('No')
                        exit()
                if j==w-1:
                    if s[i-1][j]=='.'and s[i][j-1]=='.':
                        print('No')
                        exit()
                else:
                    if s[i-1][j]=='.'and s[i][j+1]=='.' and s[i][j-1]=='.':
                        print('No')
                        exit()
            else:
                if j==0:
                    if s[i-1][j]=='.' and s[i+1][j]=='.' and s[i][j+1]=='.':
                        print('No')
                        exit()
                if j==w-1:
                    if s[i-1][j]=='.' and s[i+1][j]=='.' and s[i][j-1]=='.':
                        print('No')
                        exit()
                else:
                    if s[i-1][j]=='.' and s[i+1][j]=='.' and s[i][j-1]=='.'and s[i][j+1]=='.':
                        print('No')
                        exit()
print('Yes')

Solution (Python):
H, W = map(int, input().split())

temp = ['.'] * (W + 2)
S = [temp]

for _ in range(H):
    S.append(list('.' + input() + '.'))

S.append(temp)

output = []

for i in range(1, H + 1):
    for j in range(1, W + 1):
        if S[i][j] == '.':
            continue
        if (S[i-1][j] + S[i+1][j] + S[i][j-1] + S[i][j+1]).count('
            print('No')
            exit()

print('Yes')

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





H,W = IL()
S = SLs(H)
dx = [-1,0,1,0,]
dy = [0,-1,0,1,]

for x in range(H):
  for y in range(W):
    if S[x][y] == "
      flag = 0
      for i in range(4):
        nx = dx[i]+x
        ny = dy[i]+y
        if 0<=nx<H and 0<=ny<W:
          if S[nx][ny] == "
            flag = 1
      if flag == 0:
        NE()
Y()

Solution (Python):
h, w = [int(x) for x in input().split()]
s_list = [input() for _ in range(h)]

iso_flag = [[True] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s_list[i][j] == ".":
            continue

        flag_r = True
        if j < w - 1 and s_list[i][j + 1] == "
            flag_r = False
            iso_flag[i][j + 1] = False
        
        flag_d = True
        if i < h - 1 and s_list[i + 1][j] == "
            flag_d = False
            iso_flag[i + 1][j] = False
        
        if iso_flag[i][j] and flag_r and flag_d:
            print("No")
            exit()
print("Yes")

Solution (Python):
import sys
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j]=='
            cnt=0
            for k,l in [(1,0),(0,1),(-1,0),(0,-1)]:
                ny,nx=i+k,j+l
                if nx>=0 and nx<w and ny>=0 and ny<h:
                    if s[ny][nx]=='
                        cnt+=1
            if cnt==0:
                print('No')
                sys.exit()
print('Yes')

Solution (Python):
h, w = map(int, input().split())
a = [["."] + list(input()) + ["."] for i in range(h)]
a = [["."] * (w + 2)] + a + [["."] * (w + 2)]
b = []
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if a[i][j - 1] == "." and a[i][j] == "
            b.append([i, j])
for i in b:
    x, y = i
    if a[x - 1][y] == "." and a[x + 1][y] == ".":
        print("No")
        break
else:
    print("Yes")

Solution (Python):
def resolve():
    
    
    
    h, w = map(int, input().split())
    
    S = [list(input()) for i in range(h)]
    
    
    
    

    flag = True
    for i in range(h):
        for j in range(w):
            if S[i][j] == ".":
                continue
            else:
                neighbor = False
                N = [[i-1, j], [i+1, j], [i, j-1], [i, j+1]]
                for s in N:
                    if s[0] >= 0 and s[0] <= h-1 and s[1] >= 0 and s[1] <= w-1:
                        if S[s[0]][s[1]] == "
                            neighbor = True
                            break

                if neighbor == False:
                    flag = False
                    break
        if flag == False:
            break

    if flag == False:
        print("No")
    else:
        print("Yes")


resolve()

Solution (Python):
h, w=map(int, input().split())
s=['.'*(w+2)]+['.'+input()+'.' for _ in range(h)]+['.'*(w+2)]
ans='Yes'
for i in range(1, h+1):
  for j in range(1, w+1):
    if s[i][j]=='
      if '
        ans='No'
        break
        break
print(ans)

Solution (Python):
h, w = list(map(int, input().split()))
maps = [list(input()) for i in range(h)]

def search(i, j):
  pts = set([ (max(0, i-1), j), (i, max(0, j-1)), 
        (min(h-1, i+1), j), (i, min(w-1, j+1))])
  
  for dh, dw in list(pts):
    if maps[dh][dw] == "
      return True
  return False

flag = True
for i in range(h):
  for j in range(w):
    if maps[i][j] == "
      if not search(i, j):
        flag = False
        break
        
print("Yes" if flag else "No")