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



H, W = map(int, input().split())
board = [[0]*W for i in range(H)]
for i in range(H):
    s_list = list(input())
    for j in range(W):
        board[i][j] = s_list[j]


is_ok = True


for i in range(H):
    for j in range(W):
        s = board[i][j]
        if s=='.':
            continue

        
        if j+1<W:
            if s=='
                continue

        
        if j-1>=0:
            if s=='
                continue

        
        if i-1>=0:
            if s=='
                continue

        
        if i+1<H:
            if s=='
                continue

        is_ok = False
        break


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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    def main():

        H, W = map(int, input().split())
        grid = [[_ for _ in input()] for _ in range(H)]
        for h in range(H):
            for w in range(W):
                if grid[h][w]=='
                    for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
                        nh, nw = h + j, w + k
                        
                        if nh < 0 or nh >= H or \
                                nw < 0 or nw >= W:
                            continue
                        else:
                            if grid[nh][nw] == '
                                break
                            else:
                                if [j, k] == [0, -1]:
                                    return 'No'
        return 'Yes'

    print(main())


resolve()

Solution (Python):
h,w = map(int,input().split())
s = [str(input()) for i in range(h)]
for i in range(h):
  for j in range(w):
    if s[i][j] == "
      key = 0
      if i > 0 and s[i-1][j] == "
      if i < h-1 and s[i+1][j] == "
      if j > 0 and s[i][j-1] == "
      if j < w-1 and s[i][j+1] == "
      if key == 0:
        print("No")
        exit()
print("Yes")

Solution (Python):
import numpy as np
H,W=map(int, input().split())

S=[]
for h in range(H):
    s=list(input())
    S.append(s)

S=np.array(S)

d=[(1,0),(0,-1),(-1,0),(0,1)]
for h in range(H):
    for w in range(W):
        now=S[h,w]
        if now=="
            count=0
            for t in d:
                dx,dy=t
                nx=h+dx
                ny=w+dy
                if 0<=nx<H and 0<=ny<W:
                    if S[nx,ny]=="
                        count+=1
            if count==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 = list(input() for _ in range(h))
dxy = [(1,0),(-1,0),(0,1),(0,-1)]
for y in range(h):
    for x in range(w):
        if s[y][x] == ".": continue
        else:
            for dx,dy in dxy:
                nx,ny = x+dx,y+dy
                if not 0<=nx<w: continue
                if not 0<=ny<h: continue
                if s[ny][nx]=="
            else:    
                print("No")
                exit()
print("Yes")

Solution (Python):
H, W = map(int,input().split())
G = ["."*(W+2)]
for k in range(H):
    G.append("."+input()+".")
G.append("."*(W+2))

for h in range(1,H+1):
    for w in range(1,W+1):
        if G[h][w] == "
            if G[h-1][w] == "
                pass
            else:
                print("No")
                exit(0)
print("Yes")

Solution (Python):
h,w = map(int, input().split())
a = [list(input()) for _ in range(h)]
dx = [1,0,-1,0]
dy = [0,1,0,-1]
for k in range(h):
    for j in range(w):
        x,y = k,j
        if a[x][y] == "
            for i in range(4):
                xi,yi = x+dx[i],y+dy[i]
                if 0 <= xi < h and 0 <= yi < w and a[xi][yi] == "
                    break
            else:
                print("No")
                exit()
print("Yes")

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]=='
            for ni,nj in ((i+1,j),(i-1,j),(i,j+1),(i,j-1)):
                if 0<=ni<H and 0<=nj<W and S[ni][nj]=='
                    break
            else:
                print('No')
                exit()
print('Yes')

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

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

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

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):
H,W = map(int,input().split())
S = [input() for i in range(H)]
dxy = [(0,1),(1,0),(0,-1),(-1,0)]
for y in range(H):
    for x in range(W):
        if S[y][x] == '.': continue
        for dx,dy in dxy:
            nx,ny = x+dx,y+dy
            if not 0 <= nx < W: continue
            if not 0 <= ny < H: continue
            if S[ny][nx] == '
        else:
            print('No')
            exit()
print('Yes')

Solution (Python):
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
ok = True
for i in range(H):
  for j in range(W):
    if s[i][j] == "
      if i < H-1:
        if s[i+1][j] == "
      if i > 0:
        if s[i-1][j] == "
      if j < W-1:
        if s[i][j+1] == "
      if j > 0:
        if s[i][j-1] == "
      ok = False
      break
print("Yes" if ok else "No")

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

for i in range(h):
    for j in range(w):
        if S[i][j] == '
            flag = False
            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:
                    if S[ni][nj] == '
                        flag = True
            if not flag:
                print('No')
                exit()
else:
    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])
    delta = [[0, 1], [1, 0], [0, -1], [-1, 0]]
    count_black = 0
    count_possible = 0
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if s[i][j] == "
                count_black += 1
                if any(s[dy + i][dx + j] == "
                    count_possible += 1
    print("Yes" if count_possible == count_black else "No")


if __name__ == '__main__':
    main()

Solution (Python):
h,w=map(int,input().split())
s=[input()for _ in range(h)]
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+1][j]+s[i][j-1]+s[i][j+1]=="....":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]=="." and i-1>=0 and S[i-1][j]=="." and j-1>=0 and S[i][j-1]=="." \
            and i+1<H and S[i+1][j]==".":
                flag = 1
                break
    if flag==1:break
if flag==0:
    print("Yes")
else:
    print("No")

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

flag = 1
for i in range(1, h+1):
    for j in range(1, w+1):
        f = 0
        if s[i][j] == "
            for x, y in [(0, 1), (1, 0), (-1, 0), (0, -1)]:
                if s[i+x][j+y] == "
                    f = 1
            if f == 0:
                flag = 0

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

Solution (Python):
import sys
H, W = [int(x) for x in input().split()]
s = ['.' * (W + 2)] + ['.' + input() + '.' for _ in range(H)] + ['.' * (W + 2)]

for i in range(H):
    for j in range(W):
        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")
                sys.exit()
print("Yes")

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

dir = [(-1, 0), (0, -1), (1, 0), (0, 1)]

grid = [input() for _ in range(h)]

def ok(y, x):
    for d, r in dir:
        if d + y < 0 or d + y >= h or r + x < 0 or r + x >= w:
            continue
        yield grid[d+y][r+x] == "

for y in range(h):
    for x in range(w):
        if grid[y][x] == ".":
            continue

        if not any(ok(y, x)):
            print("No")
            exit()

print("Yes")

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

s = []
s.append("."*(w+2))
for i in range(h):
    s.append("."+input()+".")
s.append("."*(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][j+1] == "." and s[i+1][j] == ".":
                print("No")
                exit()

print("Yes")

Solution (Python):
def main():
    h, w = list(map(int, input().split()))
    canvas = []
    for i in range(h):
        canvas.append(list(input()))
    can_draw = True
    for i in range(h):
        for j in range(w):
            if canvas[i][j] == '.':
                continue
            s = []
            
            if i != 0:
                s.append(canvas[i - 1][j])
            if i != h - 1:
                s.append(canvas[i + 1][j])
            
            if j != 0:
                s.append(canvas[i][j - 1])
            if j != w - 1:
                s.append(canvas[i][j + 1])
            if s.count('
                can_draw = False
    print('Yes') if can_draw else print('No')



if __name__ == '__main__':
    main()

Solution (Python):
H, W = map(int, input().split())
s = ["." + input() + "." for _ in range(H)]
s = ["." * (W + 2)] + s + ["." * (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] == "
                pass
            else:
                print("No")
                exit()
print("Yes")

Solution (Python):
h, w = map(int,input().split())
s_l = []
s_l.append(['.']*(w+2))
for i in range(1,h+1):
    s_l.append(['.'])
    s_l[i] += list(input())
    s_l[i] += ['.']
s_l.append(['.']*(w+2))

ans = 'Yes'
for i in range(1,h+1):
    for j in range(1,w+1):
        if s_l[i][j] == '
            if '
                continue
            else:
                ans = 'No'
                break
    if ans == 'No':
        break

print(ans)

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

def check(x,y):
    global flag
    for dx,dy in ((-1,0),(1,0),(0,-1),(0,1)):
        sx = x + dx
        sy = y + dy
        if sx < 0 or sx >= W or sy < 0 or sy >= H:
            continue
        if s[sy][sx] == '
            break
    else:
        flag = False
    return flag

for y in range(H):
    for x in range(W):
        if s[y][x] == '.':
            continue
        flag = check(x,y)
print('Yes' if flag else 'No')

Solution (Python):
h,w=map(int,input().split())
s=[[0]*(w+2) for i in range(h+2)]
for i in range(h):
    s[i+1]=[0]+list(input())+[0]
    
yn=""
for i in range(1,h+2):
    for j in range(1,w+2):
        if s[i][j]=="
            if s[i-1][j]=="
                continue
            elif s[i+1][j]=="
                continue
            elif s[i][j-1]=="
                continue
            elif s[i][j+1]=="
                continue
            else:
                yn="No"
                break
    if yn=="No":
         break
     
if yn=="No":
    print("No")
else:
    print("Yes")

Solution (Python):
def main():
    H, W = map(int, input().split())
    canvas = [ list(input()) for i in range(H)]
    possible = True

    for i in range(H):
        for j in range(W):
            if canvas[i][j] == "
                if j - 1 >= 0 and canvas[i][j-1] == "
                    pass
                elif j + 1 < W and canvas[i][j+1] == "
                    pass
                elif i - 1 >= 0 and canvas[i-1][j] == "
                    pass
                elif i + 1 < H and canvas[i+1][j] == "
                    pass
                else:
                    possible = False
                    
    if possible:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Solution (Python):
h,w = map(int,input().split())
S = ["."*(w+2)]

for i in range(h):
    S.append("."+input()+".")
    
S.append("."*(w+2))

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] != "
                if S[i][j-1]!="
                    if S[i+1][j] != "
                        ans = "No"
                        break
                    
print(ans)

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):
        next_node_list = [
            [max(0, i-1), j],
            [min(H-1, i+1), j],
            [i, max(0, j-1)],
            [i, min(W-1, j+1)]
        ]


        if grid[i][j] == '
            for next_node in next_node_list:
                if next_node == [i, j]:
                    pass
                else:
                    if grid[next_node[0]][next_node[1]] == '
                        return True
            else:
                return False
        else:
            return True


    def loop_chk(H, W):
        for i in range(H):
            for j in range(W):
                
                if chk(i,j):
                    pass
                else:
                    return False
        else:
            return True

    if loop_chk(H, W):
        print('Yes')
    else:
        print('No')
    

if __name__ == "__main__":
    resolve()

Solution (Python):
h,w=map(int,input().split())
a=[[str(i) for i in input()] for j in range(h)]
ef=True
for y in range(h):
    for x in range(w):
        f=False
        if a[y][x]=="
            if y>0:
                if a[y-1][x]=="
            if x>0:
                if a[y][x-1]=="
            if y+1!=h:
                if a[y+1][x]=="
            if x+1!=w:
                if a[y][x+1]=="
            if not f:
                ef=False
                break
print("Yes" if ef else "No")

Solution (Python):
def func(x,y):
    global s,h,w,seen
    d = [1,-1]
    flag = False
    for i in d:
        if x+i < h and x+i >= 0:
            if s[x+i][y] == "
                seen[(x+i)*w+y] = 1
                seen[x*w+y] = 1
                flag = True
        if y+i < w and y+i >= 0:
            if s[x][y+i] == "
                seen[x*w+y+i] = 1
                seen[x*w+y] = 1
                flag = True
    return flag


h,w = map(int,input().split())
s = [input() for _ in range(h)]
seen = [0 for _ in range(h*w)]
ans = False
for i in range(h):
    for j in range(w):
        if s[i][j] == "
            if not func(i,j):
                ans = True
if ans:
    print("No")
else:
    print("Yes")

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



for j in range(len(s) - 1):
    for i in range(len(s[j]) - 1):
        if s[j][i] == "
            if s[j][i] != s[j+1][i] and (s[j][i] != s[j-1][i] or j == 0):
                print("No")
                exit()

print("Yes")

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

A = []

B = ['.'] * (w + 2)
A.append(B)
for i in range(h):
    C = list(input())
    C = ['.'] + C + ['.']
    A.append(C)
A.append(B)

ans = 1
for i in range(1, h+1):
    for j in range(1, w+1):
        if A[i][j] == '
            D = [A[i - 1][j], A[i][j - 1], A[i][j + 1], A[i + 1][j]]
            if '
                continue
            else:
                ans = 0
                break

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

Solution (Python):
import sys

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

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



H, W = map(int, sys.stdin.readline().split())
S = [list(sys.stdin.readline().rstrip()) for i in range(H)]
T = [[0] * W for i in range(H)]

for i in range(H):
    for j in range(W):
        repaint(i, j)
        if T[i][j] == 0:
            print("No")
            exit()
print("Yes")

Solution (Python):
H,W=map(int,input().split())
endmap=[list(s for s in input()) for _ in range(H)]
exlarge=[[0]*(W+2) for _ in range(H+2)]
ans='Yes'
for i in range(H):
  for j in range(W):
    if endmap[i][j]=='
      exlarge[i+1][j+1]=1
 
for k in range(H+2):
  for l in range(W+2):
    if exlarge[k][l]==1 and exlarge[k][l-1]== exlarge[k][l+1]==exlarge[k-1][l]==exlarge[k+1][l]==0:
          ans='No'
 
print(ans)

Solution (Python):
H, W = map(int, input().split())
G = [list('.'*(W+2)) for _ in range(H+2)]
for i in range(H):
  G[i+1][1:W+1] = input()
ans = 'Yes'
for i in range(1,H):
  for j in range(1,W):
    if G[i][j]=='
      if G[i-1][j]=='.' and G[i+1][j]=='.' and G[i][j-1]=='.' and G[i][j+1]=='.':
        ans = 'No'
        break
print(ans)

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

        
        
        if S[i][j] == ".": continue

        
        

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

        
        
        
        
        
        
        
        
        


        for dir in range(4):
            x = i + dx[dir] 
            y = j + dy[dir] 

            
            if x < 0 or y < 0 or H <= x or W <= y: continue
            if S[x][y] == "
        
        
        if is_exist == False:
            print("No")
            exit(0) 
print("Yes")

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

s = [["."] * (W+2) for _ in range(H+1)]
for i in range(H):
  s[1+i][1:1+W] = input()

ans = "Yes"
for i in range(1, H):
  for j in range(1, W):
    if s[i][j] != "
      continue
    if s[i-1][j] == "." and s[i+1][j] == "." and s[i][j-1] == "." and s[i][j+1] == ".":
      ans = "No"
  
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
import numpy as np
 
def main():
  
  row, col = map(int, input().split())
  ls2 = [['.']*(col+2)]
  for i in range(row):
    ls2.append(['.'] + list(input().rstrip()) + ['.'])
  ls2.append(['.']*(col+2))
  nda = np.array(ls2)
  
  rslt = 'Yes'
  for i in range(row):
    for j in range(col):
      if nda[i,j] == '
        if nda[i-1,j] != '
          if nda[i+1,j] != '
            if nda[i,j-1] != '
              if nda[i,j+1] != '
                rslt = 'No'
  print(rslt)
  
if __name__ == "__main__":
  main()

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    H,W=map(int,input().split())
    s=[['.']*(W+2) for _ in range(H+2)]
    for i in range(1,H+1):
        s[i][1:W+1]=list(input())
    dy=[1,0,-1,0]
    dx=[0,1,0,-1]
    for i in range(1,H+1):
        for j in range(1,W+1):
            if s[i][j]=='
                for k in range(4):
                    if s[i+dy[k]][j+dx[k]]=='
                        break
                else:
                    print('No')
                    exit()
    print('Yes')

if __name__ == '__main__':
    main()

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

e=[]
for i in range(h):
    a=list(input())
    e.append(a)

def check(i,j,e):
    global h
    global w
    top=[i-1,j]
    bottom=[i+1,j]
    right=[i,j+1]
    left=[i,j-1]
    checkpoints=[top,bottom,left,right]
    if i==0:
        checkpoints.remove(top)
    if i==h-1:
        checkpoints.remove(bottom)
    if j==0:
        checkpoints.remove(left)
    if j==w-1:
        checkpoints.remove(right)
        
    if e[i][j]==".":
        return True
    else:
        kouho=[]
        for checkpoint in checkpoints:
            kouho.append(e[checkpoint[0]][checkpoint[1]])
        if "
            return True
        else:
            return False
ans=0        
for i in range(h):
    for j in range(w):
        if not check(i,j,e):
            ans+=1
        
if ans==0:
    print("Yes")
else:
    print("No")

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

Solution (Python):

















H,W = map(int,input().split())
board = [[] for _ in range(H)]
for i in range(H):
    board[i] = list(input())
moves = [(-1, 0), (0, -1), (0, 1),(1, 0)]

def check(h,w):
    for mh,mw in moves:
        x,y = h+mh,w+mw
        
        if 0<=x<H and 0<=y<W and board[x][y]=="
            
            return True
    return False
        
ans = "Yes"
for h in range(H):
    for w in range(W):
        if board[h][w]=="
            flg = check(h,w)
            if not flg:
                print("No")
                exit()

print(ans)

Solution (Python):
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
ans = "Yes"
for i in range(1, h - 1):
    for j in range(1, w - 1):
        if s[i][j] == "
            ans = "No"
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):
import sys
sys.setrecursionlimit(10 ** 7)


h, w = map(int, input().split())
maze = [[-1 for i in range(w)] for j in range(h)]

ans = 0
for i in range(h):
    maze[i] = input()

INF = 1000
ans = 0

for sy in range(h):
    for sx in range(w):
        if maze[sy][sx] == '.':
            continue

        flg = 0
        for i in range(0, 4):
            nx, ny = sx + [1, 0, -1, 0][i], sy + [0, 1, 0, -1][i]
            if 0 <= nx < w and 0 <= ny < h:
                if maze[ny][nx] == '
                    flg = 1
        if flg == 0:
            print('No')
            exit()

print('Yes')

Solution (Python):
from itertools import product

H,W=map(int,input().split())
S=[list(input()) for _ in range(H)]
P=[(0,1),(0,-1),(1,0),(-1,0)]

for x,y in product(range(W),range(H)):
    if S[y][x]!="
        continue

    b_flg=False
    for p in P:
        c_y=y+p[0]
        c_x=x+p[1]
        if c_x <0 or c_x>=W or c_y<0 or c_y>=H: 
            continue
        if S[c_y][c_x]=="
            b_flg=True

    if b_flg==False:
        print("No")
        break
else:
    print("Yes")

Solution (Python):






def main():
    H, W = map(int, input().split())
    s = [None] * (H+2)
    s[0] = [-1] * (W+2)
    s[-1] = [-1] * (W+2)
    for i in range(1, H+1):
        s[i] = [None] * (W+2)
        s[i][0] = -1
        s[i][-1] = -1
        for j, bw in enumerate(input()):
            s[i][j+1] = 1 if bw == "

    if H == 1 and W == 1 and s[1][1] == 1:
        return "Yes"

    for i in range(1, H+1):
        for j in range(1, W+1):
            if s[i][j] == 1:
                if sum(s[i][j-1:j+2]) + s[i-1][j] + s[i+1][j] == -3:
                    return "No"
    
    return "Yes"


print(main())

Solution (Python):
import sys
H,W = map(int,input().split())
grid = []
for i in range(H):
    grid.append([el for el in input()])
move_x = [-1,1,0,0]
move_y = [0,0,1,-1]
for i in range(H):
    for j in range(W):
        if grid[i][j] == '
            counter = 0
            for k in range(4):
                i += move_x[k]
                j += move_y[k]
                if i < H and j < W and -1 < H and -1 < W:
                    if grid[i][j] == '
                        counter += 1
                i -= move_x[k]
                j -= move_y[k]
            if counter == 0:
                print('No')
                sys.exit(0)
print('Yes')

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

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(".")
S.insert(0, ["."]*(W+2))
S.append(["."]*(W+2))

filled = True
for i in range(1, H+2):
    for j in range(1, W+2):
        if (S[i][j] == "
            filled = False

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

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

S = [list(input()) for i in range(H)]

for i in range(H):
    for j in range(W):
        b = 0
        if S[i][j] == "
            bottomi = i-1 if i > 0 else 0
            bottomj = j-1 if j > 0 else 0
            topi = i+1 if i < H-1 else H-1
            topj = j+1 if j < W-1 else W-1
            for k in range(bottomi,topi+1):
                for l in range(bottomj,topj+1):
                    if (k == i and l != j) or (k != i and l == j) :
                        if S[k][l] == "
                            b = 1
            else:
                if b == 0:
                    break
        else:
            b = -1
    if b == 0:
        print("No")
        break
else:
    print("Yes")

Solution (Python):
def myAnswer(H:int,W:int,S:list) -> int:
   for h in range(H):
      for w in range(W):
         target = S[h][w]
         if(target == "
            if(h != 0 and S[h-1][w] == "
               continue
            elif(w != 0 and S[h][w - 1] == "
               continue
            elif(h != H-1 and S[h + 1][w] == "
               continue
            elif(w != W -1 and S[h][w+1] == "
               continue
            else:
               return "No"
   return "Yes"

def modelAnswer():
   return
def main():
   H,W = map(int,input().split())
   S = []
   for _ in range(H):
      S.append(list(input()))
   print(myAnswer(H,W,S[:]))
if __name__ == '__main__':
   main()

Solution (Python):
h, w = map(int, input().split())
s_list = [list(input()) for i in range(h)]
for i in range(h):
    for j in range(w):
        if s_list[i][j] == "
            flg = False
            if i != 0:
                if s_list[i - 1][j] == "
                    flg = True
            if i != h - 1:
                if s_list[i + 1][j] == "
                    flg = True
            if j != 0:
                if s_list[i][j - 1] == "
                    flg = True
            if j != w - 1:
                if s_list[i][j + 1] == "
                    flg = True
            if not flg:
                print("No")
                exit()
print("Yes")

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

flag = True

l = []
dx = [0,0,1,-1]
dy = [1,-1,0,0]
for i in range(h):
    l.append(list(input()))

for i in range(h):
    for j in range(w):
        if l[i][j] == '
            check = False
            for k in range(4):
                if i+dx[k] < 0 or i+dx[k] >= h:
                    continue
                if j+dy[k] < 0 or j+dy[k] >= w:
                    continue
                if l[i+dx[k]][j+dy[k]] == '
                    check = True
            if not check:
                flag = False

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

Solution (Python):
h,w=map(int,input().split())
l=list()
l.append(['.']*(w+2))
for i in range(h):
    l.append(['.']+list(input())+['.'])
l.append(['.']*(w+2))
p,pp=0,0
for i in range(1,h+1):
    for j in range(1,w+1):
        if l[i][j]=='
            p+=1
            pp+=int(l[i-1][j]=='
print('NYoe s'[p==pp::2])

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


s = []
for h in range(H):
    s.append(input())

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

        above = s[h - 1][w] if h >= 1 else '.'
        if above == '
            continue

        below = s[h + 1][w] if h < len(s) - 1 else '.'
        if below == '
            continue

        left = s[h][w - 1] if w >= 1 else '.'
        if left == '
            continue

        right = s[h][w + 1] if w < len(s[h]) - 1 else '.'
        if right == '
            continue

        print('No')
        exit(0)

print('Yes')