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):
def examA():
    S = SI()
    T = SI()
    N = len(S)
    ans = "No"
    for i in range(N):
        cur = S[i:] + S[:i]
        
        if cur==T:
            ans = "Yes"
    print(ans)
    return

def examB():
    H, W = LI()
    S = [SI()for _ in range(H)]

    def judge(h, w, S):
        if h < H-1 and S[h+1][w]=="
            return True
        if h > 0 and S[h-1][w]=="
            return True
        if w < W-1 and S[h][w+1]=="
            return True
        if w > 0 and S[h][w-1]=="
            return True
        return False

    ans = "Yes"
    for h in range(H):
        for w in range(W):
            if S[h][w]=="
                if judge(h,w,S):
                    continue
                ans = "No"
    print(ans)
    return

def examC():
    L, R = LI()
    ans = inf
    if R-L>=3000:
        R = L+3000

    for l in range(L, R + 1):
        for r in range(l+1, R + 1):
            now = (l*r) %2019
            ans = min(ans,now)
    print(ans)
    return

def examD():
    T = {"dream", "dreamer", "erase", "eraser"}
    S = SI()
    ans = "NO"
    t = ""
    for s in S[::-1]:
        t += s
        if t[::-1] in T:
            t = ""
        if len(t)>10:
            print(ans)
            return
    if t=="":
        ans = "YES"
    print(ans)
    return

def examE():
    N = 50
    K = I()
    base = K//N
    A = [base+i for i in range(N)]
    rest = K%N
    for i in range(rest):
        A[-i-1] += 1
    print(N)
    print(" ".join(map(str,A)))
    return

def examF():
    N = 20
    C = [2**i for i in range(N)]
    L = I()
    cur = 1
    V = [[i+1, i+2, 0]for i in range(N-1)]
    now = 1
    while(now<N):
        if C[now]<=L:
            cur = C[now]
            V.append([now,now+1,C[now-1]])
            now += 1
        else:
            break
    

    for i in range(now)[::-1]:
        if C[i]<=L-cur:
            cost = cur
            V.append([i+1,N,cost])
            cur += C[i]

    print(N,len(V))
    for s,t,c in V:
        print(s,t,c)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examB()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

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


for i in range(H):
    for j in range(W - 1):
        if S[i][j] == '.':
            S_eval[i][j] = 0
        if S[i][j + 1] == '.':
            S_eval[i][j + 1] = 0
        if S[i][j] == S[i][j + 1] == '
            S_eval[i][j] = S_eval[i][j + 1] = 0
        

for i in range(H - 1):
    for j in range(W):
        if S[i][j] == S[i + 1][j] == '
            S_eval[i][j] = S_eval[i + 1][j] = 0

sum_value = 0
for i in range(H):
    sum_value += sum(S_eval[i])
ans = 'No'
if sum_value == 0:
    ans = 'Yes'

print(ans)

Solution (Python):


import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))

dxdy=[(1,0),(0,1),(-1,0),(0,-1)]
def resolve():
    H,W=pin()
    maze=[input() for h in range(H)]
    
    for i in range(H):
        for j in range(W):
            if maze[i][j]=="
                f=0
                for head in dxdy:
                    x,y=head
                    try:k=maze[i+x][j+y]
                    except IndexError:k=None
                    if k!=None and k=="
                        f=1
                if f==0:
                    print("No")
                    return
    print("Yes")
            

resolve()

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    


def read_map_as(H, replace={'
    '''
    文字列のmapを置換して読み込み。デフォでは
    '''
    
    ret = [[pad] * (W + 2)]
    for _ in range(H):
        ret.append([pad] + [replace[s] for s in read()[:-1]] + [pad])
        
        
    ret.append([pad] * (W + 2))
    return ret


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  




H, W = read_ints()
S = read_map_as(H)
for i, j in product(ra(1, H + 1), ra(1, W + 1)):
    if S[i][j] == 0:
        continue
    for di, dj in [(0, 1), (1, 0), (-1, 0), (0, -1)]:
        ni, nj = i + di, j + dj
        if S[ni][nj] == 1:
            break
    else:
        print('No')
        exit()

print('Yes')

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

for i, a in enumerate(s):
    for j, b in enumerate(a):
        flg = False
        if b == "
            if 0 <= i - 1:
                if s[i-1][j] == "
                    flg = True
            if 0 <= j - 1:
                if s[i][j-1] == "
                    flg = True
            if i + 1 <= h-1:
                if s[i+1][j] == "
                    flg = True
            if j + 1 <= w-1:
                if s[i][j+1] == "
                    flg = True
        else:
            continue
        if not flg:
            print("No")
            exit()
else:
    print("Yes")

Solution (Python):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")











H,W = map(int,input().split())
Map = [["."]*(W+2)]
for _ in range(H):
    Map.append(["."]+list(input())[:-1] + ["."])
Map.append(["."]*(W+2))
flag = 0
for i in range(1,H+1):
    if flag == 1:
        break
    for j in range(1,W+1):
        if Map[i][j] == ".":
            continue
        if Map[i][j+1] == "." and Map[i][j-1] == "." and Map[i+1][j] == "." and Map[i-1][j] == ".":
            
            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)]
ans = "Yes"
for i in range(h):
    for j in range(w):
        if s[i][j]=="
            a = ""
            b = ""
            if i==h-1:
                a = s[i-1][j]
            elif i==0:
                a = s[i+1][j]
            else:
                a = s[i+1][j]+s[i-1][j]
            if j==0:
                b = s[i][j+1]
            elif j==w-1:
                b = s[i][j-1]
            else:
                b = s[i][j-1]+s[i][j+1]
            if not "
                ans="No"
            
print(ans)

Solution (Python):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

h,w = iim()
l = []
l.append(['.']*(w+2))
for _ in range(h):
    l.append(['.']+list(input())+['.'])
l.append(['.']*(w+2))

flag = True
for i in range(1,h+1,):
    for j in range(1,w+1):
        if l[i][j] == '
            tmp = [l[i-1][j],l[i+1][j],l[i][j-1],l[i][j+1]]
            if '
                flag = False
print('Yes' if flag else 'No')

Solution (Python):
def resolve():
    '''
    code here
    '''
    H, W = [int(item) for item in input().split()]
    grid = [[item for item in input()] for _ in range(H)]

    def chk(i,j):
        if grid[i][j] == '
            if 0 <= i-1:
                if grid[i-1][j] == '
                    return True
            if i +1 < H:
                if grid[i+1][j] == '
                    return True
            if 0 <= j -1:
                if grid[i][j-1] == '
                    return True
            
            if j + 1 < W:
                if grid[i][j+1] == '
                    return True
            
            return False
        else:
            return False

    for i in range(H):
        end_flag = False
        for j in range(W):
            
            if grid[i][j] == '
                if chk(i,j) == True:
                    pass
                else:
                    print('No')
                    end_flag = True
                    break
        if end_flag:
            break
    else:
        print('Yes')

if __name__ == "__main__":
    resolve()

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] == "
      ok = False
      for x,y in [(0,1), (0,-1), (1,0), (-1,0)]:
        new_i, new_j = i+x, j+y
        if new_i < 0 or new_i >= h or new_j < 0 or new_j >= w: continue
        if s[new_i][new_j] == "
          ok = True
          break
      if not ok:
        print("No")
        exit()
print("Yes")

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

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

Solution (Python):
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
flag=False
count=0
for i in range(h):
  if flag==True:
    break
  for j in range(w):
    if s[i][j]=="
      count=0
      if i+1<=h-1 and s[i+1][j]==".":
        count+=1
      if 0<=i-1 and s[i-1][j]==".":
        count+=1
      if j+1<=w-1 and s[i][j+1]==".":
        count+=1
      if 0<=j-1 and s[i][j-1]==".":
        count+=1
    if count==4:
      flag=True
      break
if flag:
  print("No")
else:
  print("Yes")

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

h,w=MI()
lis=[[0 for i in range(w+2)] for j in range(h+2)]
for i in range(h):
    u=list(input().rstrip())
    
    for j in range(w):
        if u[j]=="
            lis[i+1][j+1]=1
step=[[1,0],[-1,0],[0,1],[0,-1]]

for i in range(1,h+1):
    for j in range(1,w+1):
        if lis[i][j]==1:
            count=0
            for x,y in step:
                if lis[i+x][j+y]==1:
                    count+=1
            if count==0:
                print("No")
                sys.exit()
print("Yes")

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

h,w = inpl()
s = [input() for _ in range(h)]
di = [[1,0],[0,-1],[-1,0],[0,1]]
for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            continue
        ok = False
        for y,x in di:
            ny = i + y
            nx = j + x
            if 0 <= ny < h and 0 <= nx < w:
                if s[ny][nx] == '
                    ok = True
        if not ok:
            print('No')
            quit()
print('Yes')

Solution (Python):
H,W = map(int, input().split())
s = [input() for _ in range(H)]
ans = 'Yes'
dx = [0,0,1,-1]
dy = [1,-1,0,0]
for i in range(H):
    for j in range(W):
        if s[i][j] == '
            flag = False
            for k in range(4):
                nx = j+dx[k]
                ny = i+dy[k]
                if nx < 0 or ny < 0 or nx >= W or ny >= H:
                    continue
                if s[ny][nx] == '
                    flag = True
            if not flag:
                ans = 'No'
                break
print(ans)

Solution (Python):
h,w=map(int,input().split())
l = [input() for i in range(h)]
a = "."*(w+2)
ans="Yes"
for _ in range(h):
  l[_]="."+l[_]+"."
l.append(a)
l.insert(0,a)
for i in range(1,h+1):
  for j in range(1,w+1):
    if l[i][j]=="
      ans="No"
print(ans)

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

Map = [list(str(input())) for _ in range(H)]
dirc = ((0, 1), (1, 0), (-1, 0), (0, -1))
ans = 'Yes'
for h in range(H):
    for w in range(W):
        if Map[h][w]=='
            for y, x in dirc:
                if h+y<0 or h+y>=H or w+x<0 or w+x>=W:
                    continue
                if Map[h+y][w+x]=='
                    break
            else:
                ans='No'

print(ans)

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

for i in range(h):
  for j in range(w):
    if lst[i][j] == "
      if lst[max(0, i-1)][j] == lst[min(h-1, i+1)][j] == lst[i][max(0, j-1)] == lst[i][min(w-1, j+1)] == ".":
        print("No")
        exit()
        
print("Yes")

Solution (Python):
def resolve():
  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] == '
        flag = False
        if j > 0 and s[i][j-1] == '
          flag = True
        if j < w-1 and s[i][j+1] == '
          flag = True
        if i > 0 and s[i-1][j] == '
          flag = True
        if i < h-1 and s[i+1][j] == '
          flag = True
        if flag == False:
          print('No')
          return
  print('Yes')
  return

if __name__ == "__main__":
  resolve()

Solution (Python):
h, w = map(int, input().split())
s = []
for _ in range(h):
    s.append(input())
li = [(0,-1),(-1,0),(1,0),(0,1)]
for y in range(h):
    for x in range(w):
        if s[y][x]=='.':
            continue
        for dx, dy in li:
            if not (0<=x+dx<w and 0<=y+dy<h):
                continue
            if s[y+dy][x+dx]=='
                break
        else:
            print('No')
            break
    else:
        continue
    break
else:
    print('Yes')

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

ans = 'Yes'

for i in range(H):
    for j in range(W):
        if s[i][j] == '
            a = 0
            for dy,dx in [(1,0), (-1,0), (0,1), (0,-1)]:
                if 0 <= i+dy < H and 0 <= j+dx < W and s[i+dy][j+dx] == '
                    a = 1
            if a:
                continue
            ans = 'No'
print(ans)

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

Solution (Python):
h,w=map(int,input().split())
s=[['カス'for i in range(w+2)]]
for i in range(h):
    s.append(['カス']+list(input())+['カス'])
s.append(['カス'for i in range(w+2)])
p=0
pp=0
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j]=='
            p+=1
            if s[i+1][j]=='
                pp+=1
print('Yes' if p==pp else 'No')

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

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

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

G.append(['.'] * (W + 2))

move = [[1, 0], [-1, 0], [0, 1], [0, -1]]

for i in range(1, H + 1):
    for j in range(1, W + 1):
        if G[i][j] == '
            flag = False
            for dx, dy in move:
                if G[i + dx][j + dy] == '
                    flag = True
                    break
            if not flag:
                print ('No')
                exit()

print ('Yes')

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    for h in range(H):
        for w in range(W):
            if S[h][w] == "
                for dh, dw in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    next_h, next_w = h + dh, w + dw
                    if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
                        continue
                    elif S[next_h][next_w] == "
                        break
                else:
                    print("No")
                    exit()

    print("Yes")


if __name__ == '__main__':
    resolve()

Solution (Python):
h,w=map(int,input().split())
b=[list("."*(w+2))]
for i in range(h):
  b.append(list("."+input()+"."))
b.append(list("."*(w+2)))
ans="Yes"
dx=[0,1,0,-1]
dy=[1,0,-1,0]
for i in range(1,h+1):
  for j in range(1,w+1):
    if b[i][j]==".":continue
    flag=True
    for x,y in zip(dx,dy):
      if b[i][j]==b[i+x][j+y]:flag=False
    if flag:ans="No"
print(ans)

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

for i in range(h):
  for j in range(w):
    if s[i][j]=='
      check=0
      for x,y in [1,0],[-1,0],[0,1],[0,-1]:
        ny=i+y
        nx=j+x
        if 0<=ny<=h-1 and 0<=nx<=w-1:
          if s[ny][nx]=='
            check=1
      if check==0:
        print('No')
        exit()
print('Yes')

Solution (Python):
def main():
    H, W = (int(i) for i in input().split())
    A = [input() for i in range(H)]
    dhw = ((0, -1), (0, 1), (-1, 0), (1, 0))
    for h in range(H):
        for w in range(W):
            if A[h][w] == "
                for dh, dw in dhw:
                    if h + dh < 0 or H <= h + dh or \
                            w + dw < 0 or W <= w + dw:
                        continue
                    if A[h+dh][w+dw] == "
                        break
                else:
                    return print("No")
    print("Yes")


if __name__ == '__main__':
    main()

Solution (Python):
H, W = map(int, input().split())
s = [input() for i 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] == '
                continue
            elif i < H-1 and s[i+1][j] == '
                continue
            elif j > 0 and s[i][j-1] == '
                continue
            elif j < W-1 and s[i][j+1] == '
                continue
            else:
                print("No")
                exit(0)
print("Yes")

Solution (Python):
def check():
    H, W = map(int, input().split())
    S = [0]*(H+2)
    S[0] = '.'*(W+2)
    S[H+1] = '.'*(W+2)
    dh = [0,1,0,-1]
    dw = [1,0,-1,0]
    for h in range(1,H+1):
        S[h] = '.' + input() + '.'
    for h in range(H):
        for w in range(W):
            if S[h][w]=='
                for i in range(4):
                    if S[h+dh[i]][w+dw[i]]=='
                        break
                else:
                    return 'No'
    return 'Yes'
print(check())

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

for i in range(h):
    for j in range(w):
        if board[i][j] == '.': continue
        ok = False
        for k in (-1, 0, 1):
            for l in (-1, 0, 1):
                if k == 0 and l == 0:
                    continue
                if k != 0 and l != 0:
                    continue
                
                ni = i + k
                nj = j + l
                if ni < 0 or ni >= h or nj < 0 or nj >= w: continue
                
                if board[ni][nj] == '
                    ok |= True
        if not ok:
            print('No')
            exit(0)

print('Yes')

Solution (Python):
def main():
    h, w = map(int, input().split())
    s = [["" for _ in range(w + 2)]]
    for _ in range(h):
        s.append([""] + list(input()) + [""])
    s.append(s[0])
    f = False
    for i in range(1, h + 1):
        if f:
            break
        for j in range(1, w + 1):
            if s[i][j] == "
                if not any(s[i + di][j + dj] == "
                    print("No")
                    f = True
                    break
    if not f:
        print("Yes")


if __name__ == '__main__':
    main()

Solution (Python):
import sys

H, W = map(int, input().split())
S = [list(sys.stdin.readline().strip()) for _ in range(H)]

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

if len(S) == len(S[0]) == 1:
    if S[0][0] == "
        print("Yes")
    else:
        print("No")
    exit()

for i in range(H):
    for j in range(W):
        if S[i][j] == "
            ok = False
            for k in range(4):
                ny = i + dy[k]
                nx = j + dx[k]
                if not (0 <= ny <= H - 1 and 0 <= nx <= W - 1):
                    continue
                if S[ny][nx] == "
                    ok = True
                    break
            if ok is False:
                print("No")
                exit()
print("Yes")

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

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


for i in range(H):
    for j in range(W):
        if M[i][j] == '
            flag = False
            for k in range(4):
                nx = j + dy[k]
                ny = i + dx[k]
                if (nx < 0) or (ny < 0) or (nx >= W) or (ny >= H):
                    continue
                elif M[ny][nx] == '
                    flag = True
                    break
            if not flag:
                print('No')
                exit()
print('Yes')

Solution (Python):
import sys
from io import StringIO
import unittest


def resolve():
    h, w = map(int, input().split())
    sw = [list(input()) for _ in range(h)]

    for i in range(h):
        for j in range(w):
            np_sharp = False
            if sw[i][j] == '
                for add_i, add_j in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    next_i = i + add_i
                    next_j = j + add_j

                    if next_i < 0 or next_j < 0 or h <= next_i or w <= next_j:
                        continue
                    else:
                        
                        
                        if sw[next_i][next_j] == '
                            np_sharp = True

                if not np_sharp:
                    print('No')
                    return
            else:
                continue

    print('Yes')



class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 3
.

.
        output = """Yes"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """5 5

.

.

        output = """No"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """11 11
...
.




.
.

..
.
        output = """Yes"""
        self.assertIO(input, output)


if __name__ == "__main__":
    
    resolve()

Solution (Python):
import itertools
h, w = map(int, input().split())
s = [input() for i in range(h)]
for i, j in itertools.product(range(h), range(w)):
  if s[i][j] == '
    print('No')
    break
else:
  print('Yes')

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

ans = 'Yes'
for i in range(H):
    for j in range(W):
        if G[i][j] == '
            if i == 0:
                if j == 0:
                    if G[i+1][j] == '
                        continue
                    else:
                        ans = 'No'
                        break
                elif j == W-1:
                    if G[i+1][j] == '
                        continue
                    else:
                        ans = 'No'
                        break
                else:
                    if G[i+1][j] == '
                        continue
                    else:
                        ans = 'No'
                        break
            elif i == H-1:
                if j == 0:
                    if G[i-1][j] == '
                        continue
                    else:
                        ans = 'No'
                        break
                elif j == W-1:
                    if G[i][j-1] == '
                        continue
                    else:
                        ans = 'No'
                        break
                else:
                    if G[i-1][j] == '
                        continue
                    else:
                        ans = 'No'
                        break
            else:
                if j == 0:
                    if G[i+1][j] == '
                                continue
                    else:
                        ans = 'No'
                        break
                elif j == W-1:
                    if G[i+1][j] == '
                        continue
                    else:
                        ans = 'No'
                        break
                else:
                    if G[i+1][j] == '
                        continue
                    else:
                        ans = 'No'
                        break
    if ans == 'No':
        break

print(ans)

Solution (Python):
H, W = map(int, input().split())
grid = [input() for _ in range(H)]
UDLR = [[-1, 0], [1, 0], [0, -1], [0, 1]]

for i in range(H):
    for j in range(W):
        here = grid[i][j]
        if here == '.':
            continue
        ng = True
        for direction in UDLR:
            side_h = i + direction[0]
            side_w = j + direction[1]
            if 0 <= side_h < H and 0 <= side_w < W:
                side = grid[side_h][side_w]
                if side == '
                    ng = False
        if ng:
            print('No')
            exit()

print('Yes')

Solution (Python):

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

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

for y in range(H):
    for x in range(W):

        if S[y][x] == ".":
            continue

        cnt = 0

        for k in range(4):
            ny = y + dy[k]
            nx = x + dx[k]

            if ny < 0 or ny >= H or nx < 0 or nx >= W:
                continue
            
            flg = False

            if S[ny][nx] == "
                flg = True
                break
        if flg:
            continue
        else:
            print("No")
            exit()

print("Yes")

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

Solution (Python):
import sys
H, W = map(int, input().split())
s = []
s.append('.' * (W + 2))
for i in range(1, H + 1):
    a = input()
    a = '.' + a + '.'
    s.append(a)
s.append('.' * (W + 2))
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if s[i][j] == '
            OK = False
            if s[i - 1][j] == '
                OK = True
            if OK == False:
                print('No')
                sys.exit()
print('Yes')

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

for i in range(h):
    for j in range(w):
        if s[i][j] == '
            flag = 0
            for d_x in dx:
                for d_y in dy:
                    if (d_x == 0 and d_y == 0) or (d_x == -1 and d_y == -1) or (d_x == 1 and d_y == 1)\
                            or (d_x == 1 and d_y == -1) or (d_x == -1 and d_y == 1):
                        continue
                    if not (d_x == 0 and d_y == 0) and 0 <= i + d_x < h and 0 <= j + d_y < w \
                            and s[i + d_x][j + d_y] == '
                        flag = 1

            if flag == 0:
                print('No')
                exit(0)

print('Yes')