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):
Y,X=map(int,input().split())
info=[]
ans="Yes"
def search(y,x):
    c=0
    if not(0<=y<Y and 0<=x<X):
        return c
    if info[y][x]=="
        c=1
    return c
for i in range(Y):
    info.append(list(input()))
for i in range(Y):
    for j in range(X):
        if info[i][j]==".":
            continue
        if (search(i+1,j)+search(i-1,j)+search(i,j+1)+search(i,j-1))==0: 
            ans="No"
            break
print(ans)

Solution (Python):

import sys


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

S = []
for i in range(H):
    S.append(input())


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

for i in range(H):
    for j in range(W):
        
        if S[i][j] == ".":
            continue

        
        
        can = False

        for k in range(4):
            ni = i + dx[k]
            nj = j + dy[k]

            if ni < 0 or H <= ni:
                continue
            if nj < 0 or W <= nj:
                continue

            if S[ni][nj] == "
                can = True
                break

        
        if not can:
            print("No")
            sys.exit()

print("Yes")

Solution (Python):
h,w = map(int,input().split())
s = [input() for _ in range(h)]
f = True
for i in range(h):
  for j in range(w):
    if s[i][j] == "
      l = [(i+1,j),(i-1,j),(i,j+1),(i,j-1)]
      t = []
      g = False
      for p,q in l:
        if p >= 0 and p < h and q >= 0 and q < w:
          if s[p][q] == "
            g = True
      if g is False:
        f = False
        break
  if f is False:
    break
if f:
  print("Yes")
else:
  print("No")

Solution (Python):
H, W = map(int,input().split())
s = []*H
flag = 0
tmp = 0
for i in range(H):
    s.append(input())

for i in range(H):
    for j in range(W):
        tmp = 0
        if s[i][j] == '
            try:
                if s[i-1][j] == '
                    tmp += 1
            except IndexError:
                pass
            try:
                if s[i+1][j] == '
                    tmp += 1
            except IndexError:
                pass
            try:
                if s[i][j-1] == '
                    tmp += 1
            except IndexError:
                pass
            try:
                if s[i][j+1] == '
                    tmp += 1
            except IndexError:
                pass
            if tmp == 0:
                flag = 1

if flag == 0:
    print('Yes')
else:
    print('No')

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

s = [['.'] * (w+2)]
for i in range(h):
  tmp = list(input())
  tmp.insert(0, '.')
  tmp.append('.')
  s.append(tmp)

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

print(ans)

Solution (Python):
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
    adj=[]
    if 0<i:
      adj.append(S[i-1][j])
    if i<H-1:
      adj.append(S[i+1][j])
    if 0<j:
      adj.append(S[i][j-1])
    if j<W-1:
      adj.append(S[i][j+1])
    
    if all('.'==m for m in adj):
      flag=False
print('Yes' if flag else 'No')

Solution (Python):
h, w = map(int, input().split())
s = [[""]*(w+2)]
for _ in range(h):
    _s = list(input())
    _s.insert(0, "")
    _s.append("")
    s.append(_s)
s.append([""]*(w+2))

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

c = [["."]*(w+2) for _ in range(h+2)]

for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j] != "
            continue

        for _dx, _dy in zip(dx, dy):
            x = i + _dx
            y = j + _dy
            if s[x][y] == "
                c[i][j] = "
                c[x][y] = "

ans = "Yes"
for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j] != c[i][j]:
            ans = "No"
            break

print(ans)

Solution (Python):
H,W=map(int, input().split())
S = [input() for _ in range(H)]
d = [-1,0,1,0,-1]
b = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == ".": continue
        if any(S[h+x][w+y]=="
            continue
        b = 1
print("YNeos"[b::2])

Solution (Python):


H,W=map(int,input().split())
L=[]
for i in range(H):
    L.append([i for i in input()])
flg=0
cnt=0

for i in range(H):
    for j in range(1,W-1):
        if L[i][j]=='
            if L[i-1][j]!='
                print('No')
                flg=1
                break
    cnt+=1
    if flg==1:
        break


if cnt==H:
    print('Yes')

Solution (Python):
h, w = [int(i) for i in input().split(' ')]
tg = [input() for i in range(h)]
og = [['.']*w]*h

fail = False
for i in range(h):
    for j in range(w):
        
        if tg[i][j] == ".":
            continue

        
        if i > 0 and tg[i-1][j] == '
            og[i][j] = '
            og[i-1][j] = '
            continue

        
        if i < h-1 and tg[i+1][j] == '
            og[i][j] = '
            og[i+1][j] = '
            continue

        
        if j > 0 and tg[i][j-1] == '
            og[i][j] = '
            og[i][j-1] = '
            continue

        
        if j < w-1 and tg[i][j+1] == '
            og[i][j] = '
            og[i][j+1] = '
            continue

        fail = True
        break

    if fail:
        print("No")
        break

if not fail:
    print("Yes")

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

def is_move(i,j):
    if j < 0 or j > w - 1 or i < 0 or i > h - 1:
        return False
    return True

di=[0,1,0,-1]
dj=[1,0,-1,0]
flag = False
for i in range(h):
    for j in range(w):
        if s[i][j] == "
            flag_4 = False
            for k in range(4):
                I = i + di[k]
                J = j + dj[k]
                if is_move(I, J):
                    if s[I][J] == "
                        flag_4 = True
            if not flag_4:
                flag = True

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

Solution (Python):

import sys

sys.setrecursionlimit(200000)

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

canvas=[]

flg=True

def bfs(y,x):
    cnt[0]+=1
    canvas[y][x]="."
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    for i in range(4):
        ny=y+dy[i]
        nx=x+dx[i]
        
        if 0<=nx<=W-1 and 0<=ny<=H-1:
            if canvas[ny][nx]=="
                bfs(ny,nx)

for i in range(H):
    row=list(input())
    canvas.append(row)


for i in range(H):
    for j in range(W):
        if canvas[i][j]=="
            cnt=[0]
            bfs(i,j)
            if cnt[0]==1:
                flg=False

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

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


a="Yes"

for i in range(h):
    if a=="No":
        break
    for j in range(w):
        a="No"
        if s[i][j]==".":
            a="Yes"
        else:
            if i-1>=0 and s[i-1][j]=="
                a="Yes"
            elif j-1>=0 and s[i][j-1]=="
                a="Yes"
            elif j+1<w and s[i][j+1]=="
                a="Yes"
            elif i+1<h and s[i+1][j]=="
                a="Yes"
        if a=="No":
            break


print(a)

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

for i in range(h):
    s[i].insert(0, ".")
    s[i].append(".")

s1 = []
for i in range(w+2):
    s1.append(".")

s.insert(0, s1)
s.append(s1)

ans = "Yes"

for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j] == "
            if s[i-1][j] == s[i][j-1] == s[i][j+1] == s[i+1][j] == ".":
                ans = "No"

print(ans)

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

for h in range(H):
  li.append(list(input()))

dxy = [(0, -1), (1, 0), (0, 1), (-1, 0)]
ans = 'Yes'

for y in range(H):
  for x in range(W):
    if li[y][x] == '.':
      continue

    a = 0
    for dx, dy in dxy:
      if x+dx < 0 or x+dx > W-1 or y+dy < 0 or y+dy > H-1:
        continue
      if li[y+dy][x+dx] == '
        a = 1
    
    if a == 0:
      ans = 'No'

print(ans)

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


S1 = [list(map(str,input())) for i in range(H)]
for i in range(H):
    S1[i].insert(0,'
    S1[i].append('
S = S = [['

cnt = 0

for i in range(1,H):
    for j in range(1,W):
        if S[i][j] == '
            if S[i-1][j] == S[i][j-1] == S[i][j+1] == S[i+1][j] == '.':
                cnt += 1
if cnt == 0:
    print('Yes')
else:
    print('No')

Solution (Python):

def GridRepainting():
    H, W = map(int, input().split())
    strlist = []
    for _ in range(0, H):
        strlist.append(list(input()))
    for i in range(0, H):
        for j in range(0, W):
            if strlist[i][j] == '
                if i > 0:
                    if strlist[i - 1][j] == '
                if i != H - 1:
                    if strlist[i + 1][j] == '
                if j > 0:
                    if strlist[i][j - 1] == '
                if j != W - 1:
                    if strlist[i][j + 1] == '
                print('No')
                return()

    print('Yes')
    return()

GridRepainting()

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] == ".":
      continue
    if grid[i][j-1] == grid[i][j+1] == grid[i+1][j] == grid[i-1][j] == ".":
      print("No")
      exit()
print("Yes")

Solution (Python):
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 s[i][j] == '

            l, u, r, d = 0, 0, 0, 0

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

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

            if j < W-1 and s[i][j+1] == '
                u = 1

            if i < H-1 and s[i+1][j] == '
                d = 1


            if l+u+r+d == 0:
                print('No')
                exit()

print('Yes')

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

bre = False
for h in range(H):
    for w in range(W):
        if s[h][w] == "
            if h>0 and s[h-1][w]=="
                continue
            elif h<H-1 and s[h+1][w]=="
                continue
            elif w>0 and s[h][w-1]=="
                continue
            elif w<W-1 and s[h][w+1]=="
                continue
            else:
                
                print("No")
                bre = True
                break
    if bre:
        break
else:
    print("Yes")

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

flg = True
for i in range(h):
    for j in range(w):
        if mat[i][j] == "
            check = False
            if i != 0 and mat[i-1][j] == "
                check = True
            elif i != h-1 and mat[i+1][j] == "
                check = True
            elif j != 0 and mat[i][j-1] == "
                check = True
            elif j != w-1 and mat[i][j+1] == "
                check = True

            if not check:
                flg = False
                break

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

Solution (Python):
H,W = map(int,input().split())
s = [["."]*(W+2)]+[["."]+list(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 s[i-1][j]=="." and s[i][j-1]=="." and s[i+1][j]=="." and s[i][j+1]==".":
                print("No")
                exit()
print("Yes")

Solution (Python):
HW = input().split()
H, W = int(HW[0]), int(HW[1])
S = [input() for _ in range(H)] 
result = [[0 for _ in range(W)] for _ in range(H)]

ans = 'Yes'
for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      continue
    else:
      if (i-1 >= 0 and j-1 >= 0 and S[i-1][j] == '.') and (j-1 >= 0 and S[i][j-1] == '.') and ( j+1 < W and S[i][j+1] == '.') and (i+1 < H and S[i+1][j] == '.'):
        ans = 'No'
print(ans)

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

for i in range(H):
    for j in range(W):
        if lst[i][j] == "
            if (
                (j > 0 and lst[i][j - 1] != "
                and (j < W - 2 and lst[i][j + 1] != "
                and (i > 0 and lst[i - 1][j] != "
                and (i < H - 2 and lst[i + 1][j] != "
            ):
                print("No")
                exit()
print("Yes")

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

for i in range(h):
    ls[i] = ["."] + ls[i] + ["."]

ls_s = [["."] * len(ls[0])]
ls_s.extend(ls)
ls_s.extend([["."] * len(ls[0])])

for i in range(1, h+1):
    for j in range(1, w+1):
        if ls_s[i][j] == "
            if ls_s[i-1][j] == ls_s[i+1][j] == ls_s[i][j-1] == ls_s[i][j+1] == ".":
                print("No")
                break
            elif i == h and j == w:
                print("Yes")
        elif i == h and j == w:
            print("Yes")
    else:
        continue
    break

Solution (Python):
h,w = map(int, input().split())
wb = {'
wall = 0
edges = [wall for i in range(w+2) ]

grid = [edges]
for i in range(1,h+1):
    S = [wall]+list(map(wb.get, input()))+[wall]
    grid.append(S)
grid.append(edges)

dxy = [(1,0), (-1,0), (0,1), (0,-1)]
for y in range(1,h+1):
    for x in range(1,w+1):
        if grid[y][x] == 0:
            continue
        for dy, dx in dxy:
            y_,x_ = y+dy,x+dx
            
            if grid[y_][x_]:
                break
        else:
            
            print('No')
            exit()
print('Yes')

Solution (Python):
import sys
H, W = map(int, input().split())
s = [input() + "." for _ in range(H)]
s.append("." * W)
d = ((0, 1), (1, 0), (0, -1), (-1, 0))

for h in range(H):
    for w in range(W):
        if s[h][w] == "
            if all([s[h + dh][w + dw] == "." for dh, dw in d]):
                print("No")
                sys.exit()
print("Yes")

Solution (Python):
h,w = map(int,input().split())
x = ["." for i in range(w+2)]
z = [x]
for i in range(h):
    t = ["."]
    y = list(input())
    t = t + y + t
    z.append(t)
z.append(x)
ans = 0
for i in range(1,w+1):
    for j in range(1,h+1):
        if z[j][i] == "
            if (z[j+1][i] ==
                z[j-1][i] ==
                z[j][i+1] ==
                z[j][i-1] == "."):
                ans = 1
if ans == 0:
    print('Yes')
else:
    print('No')

Solution (Python):
H,W=map(int,input().split())
s=[list(input()) for _ in range(H)]
cnt=0
for i in range(H):
    for j in range(W):
        if s[i][j]=='
            l=[[i-1,j],[i+1,j],[i,j-1],[i,j+1]]
            OK=0
            for v in l:
                if H>v[0]>=0 and W>v[1]>=0:
                    if s[v[0]][v[1]]=='
                        OK=1
            if OK==0:
                print('No')
                exit()
print('Yes')

Solution (Python):
import sys
input = sys.stdin.readline
H,W=map(int,input().split())
s=[]
s0=""
for i in range(W+2):
    s0+="."
s.append(s0)
for i in range(H):
    ss="."
    ss+=input().strip()+"."
    s.append(ss)
s.append(s0)

flg=True
for h in range(H+1):
    for w in range(W+1):
        if s[h][w]=="
            flg=False
            for i in [1,-1]:
                if s[h+i][w]=="
                    flg=True
                if s[h][w+i]=="
                    flg=True
            if flg==False:
                print("No")
                exit()
print("Yes")

Solution (Python):
import sys

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

rows = []
for i in range(H):
    chars = list(input())
    rows.append([1 if c == '


def is_possible(rows):
    for h in range(H):
        for w in range(W):
            if rows[h][w] == 0:
                continue

            pair_candidates = []
            if w - 1 >= 0:
                pair_candidates.append((h, w - 1))
            if w + 1 < W:
                pair_candidates.append((h, w + 1))
            if h - 1 >= 0:
                pair_candidates.append((h - 1, w))
            if h + 1 < H:
                pair_candidates.append((h + 1, w))
            pair_candidates_sum = sum([
                rows[_h][_w] for _h, _w in pair_candidates
            ])

            if pair_candidates_sum == 0:
                return False

    return True


if is_possible(rows):
    print('Yes')
else:
    print('No')

Solution (Python):
H, W = map(int,input().split())
A=[list(input()) for _ in range(H)]
def cnt_(h,w):
  ret=0
  if 0<=h<H and 0<=w<W and A[h][w]=='
    ret=1
  return ret
def cnt(h,w):
  ret=0
  ret+=cnt_(h+1,w)+cnt_(h-1,w)
  ret+=cnt_(h,w+1)+cnt_(h,w-1)
  return ret
ans = "Yes"
for i in range(H):
  for j in range(W):
    if A[i][j]=='
      if cnt(i,j)==0:
        ans = "No"
        break
print(ans)

Solution (Python):
from collections import deque
h,w = map(int,input().split())
lst1 = [list(list(input())) for i in range(h)]
    


def dfs(maze,sh, sw):
    for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]): 
        new_h, new_w = sh+j, sw+k
        if new_h < 0 or new_h >= h or \
            new_w < 0 or new_w >= w: 
            continue
        elif maze[new_h][new_w] == "
            return True
    return False

for i in range(h):
    for j in range(w):
        if lst1[i][j] == "
            if not dfs(lst1,i,j):
                print("No")
                exit()
print("Yes")

Solution (Python):

import numpy as np
H, W = map(int, input().split())
S = []
cnt = 0
for i in range(H):
    s = input()
    cnt += s.count("
    S.append(s[:])
t_cnt = 0
T = [[False] * W] * H
T = np.array(T)
for i in range(H):
    for j in range(W):
        if S[i][j] == "
            if 0 < i < H-1:
                if 0 < j < W-1:
                    T[i-1][j] = True
                    T[i+1][j] = True
                    T[i][j-1] = True
                    T[i][j+1] = True
                elif j == 0:
                    T[i-1][j] = True
                    T[i+1][j] = True
                    T[i][j+1] = True
                else:
                    T[i-1][j] = True
                    T[i+1][j] = True
                    T[i][j-1] = True
            elif i == 0:
                if 0 < j < W-1:
                    T[i][j-1] = True
                    T[i][j+1] = True
                    T[i+1][j] = True
                elif j == 0:
                    T[i][j+1] = True
                    T[i+1][j] = True
                else:
                    T[i+1][j] = True
                    T[i][j-1] = True
            else:
                if 0 < j < W-1:
                    T[i][j-1] = True
                    T[i][j+1] = True
                    T[i-1][j] = True
                elif j == 0:
                    T[i][j+1] = True
                    T[i-1][j] = True
                else:
                    T[i-1][j] = True
                    T[i][j-1] = True
for i in range(H):
    for j in range(W):
        if T[i][j] and S[i][j] == "
            t_cnt += 1
print("Yes" if cnt == t_cnt else "No")

Solution (Python):
hw=list(map(int,input().split()))
s=[]
for i in range(hw[0]):
    s.append(input())
ans="Yes"
for i in range(hw[0]):
    if ans=="Yes":
        for j in range(hw[1]):
            if s[i][j]=="
                flag=0
                if i!=0 and s[i-1][j]=="
                    flag=1
                if flag==0 and i!=hw[0]-1 and s[i+1][j]=="
                    flag=1
                if flag==0 and j!=0 and s[i][j-1]=="
                    flag=1
                if flag==0 and j!=hw[1]-1 and s[i][j+1]=="
                    flag=1
                if flag==0:
                    ans="No"
                    break
    else:
        break
print(ans)

Solution (Python):
H,W = map(int,input().split())
base = []
for _ in range(H):
  base.append(list(input()))
counter = 0
for i in range(H):
  for j in range(W):
    if base[i][j] == '
      counter += 1
      break
if counter == 0:
  print('Yes')
  exit()
TB = ['.']*(W+1)
WIDE = []
WIDE.append(TB)
for i in range(H):
  WIDE.append(['.'] + base[i] + ['.'])
WIDE.append(TB)
Answer = 'Yes'
for i in range(1,H+1):
  for j in range(1,W+1):
    if WIDE[i][j] == '
      Answer = 'No'
      break
print(Answer)

Solution (Python):
H, W = map(int, input().split())
ls = []
for i in range(H):
    ls.append([i for i in input().split()[0]])

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

def dfs(x, y):
    flg = 0
    for ii in range(4):
        nx = x + dx[ii]
        ny = y + dy[ii]
        if nx < 0 or nx >= H or ny < 0 or ny >= W:
            continue
        if ls[nx][ny] == '
            flg = 1
    return flg

for i in range(H):
    for j in range(W):
        if ls[i][j] == '
            if dfs(i, j) == 0:
                print('No')
                exit()
print('Yes')

Solution (Python):
H,W = map(int,input().split())
S = [input().strip() for _ in range(H)]
flag = 0
for i in range(H):
    for j in range(W):
        if S[i][j]=="
            if (j+1<W and S[i][j+1]=="
                continue
            else:
                flag = 1
                break
    if flag==1:break
if flag==0:
    print("Yes")
else:
    print("No")

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

def black(i,j):
    if s[i][j]=='
        flag=False
        for m in range(-1,2):
            for n in range(-1,2):
                if (m==0 and n!=0) or (m!=0 and n==0):
                    if 0<=i+m<=h-1 and 0<=j+n<=w-1:
                        if s[i+m][j+n]=='
                            flag=True
                            break
            if flag:
                break
        return flag
    else:
        return True

flag=True
for i in range(h):
    for j in range(w):
        if black(i,j):
            flag=True
        else:
            flag=False
            print('No')
            break
    if not flag:
        break
if flag:
    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())
edges = [[ None for i in range(W) ] for j in range(H)]

for h in range(H):
  v = input()
  for w in range(W):
    edges[h][w] = v[w]

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

    flag = False
    flag = flag or (w + 1 != W and edges[h][w+1] == "
    flag = flag or (w != 0 and edges[h][w-1] == "
    flag = flag or (h + 1 != H and edges[h+1][w] == "
    flag = flag or (h != 0 and edges[h-1][w] == "

    if not flag:
      print("No")
      exit()

print("Yes")

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

flg = False
for i in range(H):
    ls = list(input())
    fields.append(ls)

mvs = [(0,1),(0,-1),(1,0),(-1,0)]
for h in range(H):
    for w in range(W):
        if fields[h][w] == "
            flg = False 
            for dh,dw in mvs:
                h_new = h + dh
                w_new = w + dw
                if 0 <= h_new < H and 0 <= w_new < W:
                    if fields[h_new][w_new] == "
                        flg = True
            if not flg:
                print("No")
                exit()
print("Yes")

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

flag=True
if H==W==1:
    if s[0][0]=='
        flag=False
elif H>=2 and W==1:
    for i in range(H):
        if s[i][0] == '
            if i==0:
                if s[i+1][0]=='.':
                    flag=False
                    break
                else:
                    continue
            elif i==H-1:
                if s[i-1][0]=='.':
                    flag=False
                    break
                else:
                    continue
            else:
                if s[i+1][0]==s[i-1][0]=='.':
                    flag=False
                    break
                else:
                    continue
        else:
            continue
elif H==1 and W>=2:
    for i in range(W):
        if s[0][i]=='
            if i==0:
                if s[0][i+1]=='.':
                    flag=False
                    break
                else:
                    continue
            elif i==W-1:
                if s[0][i-1]=='.':
                    flag=False
                    break
                else:
                    continue
            else:
                if s[0][i+1]==s[0][i-1]=='.':
                    flag=False
                    break
                else:
                    continue
        else:
            continue
else:
    for i in range(H):
        if i==0:
            for j in range(W):
                if s[i][j]=='
                    if j==0:
                        if s[i][j+1]==s[i+1][j]=='.':
                            flag=False
                            break
                        else:
                            continue
                    elif j==W-1:
                        if s[i][j-1]==s[i+1][j]=='.':
                            flag=False
                            break
                        else:
                            continue
                    else:
                        if s[i][j+1]==s[i][j-1]==s[i+1][j]=='.':
                            flag=False
                            break
                        else:
                            continue
                else:
                    continue
            if flag==False:
                break
        elif i==H-1:
            for j in range(W):
                if s[i][j]=='
                    if j==0:
                        if s[i][j+1]==s[i-1][j]=='.':
                            flag=False
                            break
                        else:
                            continue
                    elif j==W-1:
                        if s[i][j-1]==s[i-1][j]=='.':
                            flag=False
                            break
                        else:
                            continue
                    else:
                        if s[i][j+1]==s[i][j-1]==s[i-1][j]=='.':
                            flag=False
                            break
                        else:
                            continue
                else:
                    continue
            if flag==False:
                break
        else:
            for j in range(W):
                if s[i][j]=='
                    if j==0:
                        if s[i-1][j]==s[i+1][j]==s[i][j+1]=='.':
                            flag=False
                            break
                        else:
                            continue
                    elif j==W-1:
                        if s[i-1][j]==s[i+1][j]==s[i][j-1]=='.':
                            flag=False
                            break
                        else:
                            continue
                    else:
                        if s[i-1][j]==s[i+1][j]==s[i][j-1]==s[i][j+1]=='.':
                            flag=False
                            break
                        else:
                            continue
                else:
                    continue
            if flag==False:
                break

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

Solution (Python):
a,b = map(int,input().split())
art = [list(str(input())) for _ in range(a)]

def check(x,y):
    if x > 0:
        if art[x-1][y] == "
            return
    if x < a-1:
        if art[x + 1][y] == "
            return

    if y > 0:
        if art[x][y-1] == "
            return
    if y < b-1:
        if art[x][y+1] == "
            return
    print('No')
    exit(0)

for i in range(a):
    for j in range(b):
        if art[i][j] == "
            check(i,j)

print('Yes')

Solution (Python):

import sys

YES = "Yes"  
NO = "No"  

def solve(H: int, W: int, s: "List[str]"):
    s = ["."*(W+2)]+["."+ss+"." for ss in s]+["."*(W+2)]
    
    direction = ((0,1),(1,0),(0,-1),(-1,0))

    
    for i in range(H+2):
        for j in range(W+2):
            if s[i][j] == ".":
                continue
            
            for x,y in direction:
                if s[i+x][j+y] == "
                    break
            else:
                print(NO)
                return 
    
    print(YES)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  
    W = int(next(tokens))  
    s = [next(tokens) for _ in range(H)]  
    solve(H, W, s)

if __name__ == '__main__':
    main()

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

A = [['.']*(W+2) for i in range(H+2)]
for i in range(1,H+1):
    for j in range(1,W+1):
        A[i][j] = S[i-1][j-1]
        
ans = 'Yes'
for i in range(W+2):
    if(ans == 'No'):
        break
    for j in range(H+2):
         if(A[j][i] == '
            if (A[j-1][i] != '
                ans = 'No'
                break

if(H == 1 and W ==1 and S[0][0] == '
    ans = 'Yes'

print(ans)

Solution (Python):
H, W = map(int, input().split())
S = [input() for _ in range(H)]
for h in range(H):
    for w in range(W):
        f = False
        if S[h][w] == '.':
            continue
        if h > 0 and S[h-1][w] == '
            f = True
        elif h < H-1 and S[h+1][w] == '
            f = True
        elif w > 0 and S[h][w-1] == '
            f = True
        elif w < W-1 and S[h][w+1] == '
            f = True
        if not f:
            break
    else:
        continue
    break
else:
    print('Yes')
    exit()
print('No')