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):
from collections import deque
H,W=map(int,input().split())
s=[list(input()) for i in range(H)]
def dfs(h,w):
    q=deque()
    q.append((h,w))
    s[h][w]='.'

    dx=[0,1,0,-1]
    dy=[1,0,-1,0]
    cnt=0
    while q:
        task=q[-1]
        for i in range(4):
            nx=task[0]+dx[i]
            ny=task[1]+dy[i]
            if not(0<=nx<H and 0<=ny<W):continue
            if s[nx][ny]!='
            q.append((nx,ny))
            s[nx][ny]='.'
            cnt+=1
            break
        else:
            if cnt==0:
                print('No')
                exit()
            q.pop()
    return s
for i in range(H):
    for j in range(W):
        if s[i][j]=='
            s=dfs(i,j)
"""
for i in s:
    for j in i:
        if j=='
            print('No')
            exit()
"""
print('Yes')

Solution (Python):
if __name__ == "__main__":
    h, w = map(int, input().split())
    s = list()
    s.append('.' * (w + 2))
    for i in range(h):
        s.append('.' + input() + '.')
    s.append('.' * (w + 2))

    for i in range(h):
        for j in range(w):
            tmp = s[i+1][j] + s[i][j+1] + s[i+1][j+2] + s[i+2][j+1]
            if tmp == '....' and s[i+1][j+1] == '
                print('No')
                exit()

    print('Yes')

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

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

for i in range(H):
    for j in range(W):
        if S[i][j] == "
            flag = False
            for x,y in [[i-1,j],[i+1,j],[i,j+1],[i,j-1]]:
                if 0 <= x < H and 0 <= y < W and S[x][y]=="
                    flag = True
            if not flag:
                print("No")
                exit()
print("Yes")

Solution (Python):
import sys
def main():
    input = sys.stdin.readline
    H,W = map(int, input().split())
    s = [list(input().rstrip()) for _ in range(H)]

    c = lambda i,j: i*W+j
    used = [False] * (H*W+1)
    def dfs(si, sj):
        depth = 0
        stack = [(si, sj, 0)]
        while stack:
            i, j, d = stack.pop()
            for di, dj in [(0,1),(0,-1),(1,0),(-1,0)]:
                ni, nj = i+di, j+dj
                if ni < 0 or ni >= H or nj < 0 or nj >= W: continue
                if s[ni][nj] != '
                if used[c(ni,nj)]: continue
                used[c(ni,nj)] = True
                stack.append((ni, nj, d+1))
                depth = max(depth, d+1)
        return depth

    for i in range(H):
        for j in range(W):
            if used[c(i,j)] == False and s[i][j] == '
                depth = dfs(i,j)
                if depth == 0: return False
    return True

if __name__ == '__main__':
    print('Yes' if main() else 'No')

Solution (Python):
def solve():
    H, W = map(int, input().split())
    S = []
    for h in range(H):
        s = input()
        S.append(s)

    for h in range(H):
        for w in range(W):
            if S[h][w] == '
                ok = False
                if h > 0 and S[h - 1][w] == '
                    ok = True
                if h < H - 1 and S[h + 1][w] == '
                    ok = True
                if w > 0 and S[h][w - 1] == '
                    ok = True
                if w < W - 1 and S[h][w + 1] == '
                    ok = True
                if not ok:
                    print('No')
                    return

    print('Yes')


if __name__ == "__main__":
    solve()

Solution (Python):
H, W = map(int, input().split())
DX = (-1, 0, 1, 0)
DY = (0, 1, 0, -1)

S = [[1] * (W + 2) for _ in range(H + 2)]
for i in range(1, H + 1):
    for j, x in enumerate(input(), start=1):
        if x == ".":
            S[i][j] = 0


for x in range(1, H + 1):
    for y in range(1, W + 1):
        if S[x][y] == 0:
            continue
        cnt = 0
        for dx, dy in zip(DX, DY):
            if S[x + dx][y + dy] == 0:
                cnt += 1
        if cnt == 4:
            print("No")
            exit()

print("Yes")

Solution (Python):

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

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

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



flag = True
for i in range(1, h+1):
    for j in range(1, w+1):
        if M[i][j] == '
            for p, q in (-1, 0), (1, 0), (0, 1), (0, -1):
                ni = i+p
                nj = j+q
                if M[ni][nj] == '
                    break
            else:
                flag = False

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

Solution (Python):
import sys
def solve():
    H, W = map(int, input().split())
    S = [input() for _ in range(H)]
    search = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    possible = True
    for h in range(H):
        for w in range(W):
            if S[h][w] == "
                for dh, dw in search:
                    if 0 <= h + dh < H and 0 <= w + dw < W:
                        if S[h+dh][w+dw] == "
                            break
                else:
                    possible = False
                    break
        if not possible: break
    print("Yes" if possible else "No")

    
    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
h,w=map(int,input().split())
s=[]
for i in range(h):
    S=str(input())
    s.append(S)
ans=1
for i in range(1,h-1):
    for j in range(1,w-1):
        if s[i][j]=='
            if s[i-1][j]!='
                ans=0
if ans==1:
    print("Yes")
else:
    print("No")

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


if __name__ == '__main__':
    main()

Solution (Python):

H, W = map(int, input().split())
s = [input() for _ in range(H)]
d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
for i in range(H):
    for j in range(W):
        if s[i][j] == '.':
            continue
        for di, dj in d:
            ni, nj = i+di, j+dj
            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())
l=[list(list(input())) for _ in range(h)]

for i in range(h):
    for j in range(w):
        if i==0:
            if j==0:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j+1]=='
                        continue
                    else:
                        print('No')
                        exit()
            elif j==w-1:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j-1]=='
                        continue
                    else:
                        print('No')
                        exit()
            else:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j-1]=='
                        continue
                    else:
                        print('No')
                        exit()
        elif i==h-1:
            if j==0:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j+1]=='
                        continue
                    else:
                        print('No')
                        exit()
            elif j==w-1:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j-1]=='
                        continue
                    else:
                        print('No')
                        exit()
            else:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j-1]=='
                        continue
                    else:
                        print('No')
                        exit()
        else:
            if j==0:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j+1]=='
                        continue
                    else:
                        print('No')
                        exit()
            elif j==w-1:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j-1]=='
                        continue
                    else:
                        print('No')
                        exit()
            else:
                if l[i][j]=='.':
                    continue
                else:
                    if l[i][j-1]=='
                        continue
                    else:
                        print('No')
                        exit()

print('Yes')

Solution (Python):

h,w=map(int,input().split())
maze=[]
move=[[1,0],[0,1],[-1,0],[0,-1]]
for i in range(h):
    line=input()
    maze.append(line)

def no_conf(y,x):
    flag=False
    for i in move:
        my,mx=[a+b for a,b in zip(i,[y,x])]
        if 0<=my<h and 0<=mx<w:
            if maze[my][mx]=="
                flag=True
    return flag
ans=True
for i in range(h):
    for j in range(w):
        if maze[i][j]=="
            if no_conf(i,j)==False:
                ans=False
                break
if ans:
    print("Yes")
else:
    print("No")

Solution (Python):



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

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

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



ans = True

for i in range(H):
    for j in range(W):
        if grid[i][j] == '
            cnt = 0
            
            for k in range(4):
                y = i + dy[k]
                x = j + dx[k]
                if x >= 0 and y >= 0 and x < W and y < H:
                    
                    if grid[y][x] == '
                        cnt += 1
            
            if cnt == 0:
                ans = False
                break
    else:
        continue
    break

if ans is True:
    print('Yes')
else:
    print('No')

Solution (Python):
import sys
input = sys.stdin.readline
import copy

H, W = map(int, input().split(' '))
S = [list(input().rstrip('\r\n')) for _ in range(H)]

def judge(h, w):
    ok = False
    if h-1 >= 0 and S[h-1][w] == '
        ok = True
    if w-1 >= 0 and S[h][w-1] == '
        ok = True
    if w+1 < W and S[h][w+1] == '
        ok = True
    if h+1 < H and S[h+1][w] == '
        ok = True
    return ok
ans = 'Yes'
for h in range(H):
    for w in range(W):
        if S[h][w] == '
            if judge(h, w) == False:
                ans = 'No'
print(ans)

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

dxy = [(-1,0), (0,-1),(1,0),(0,1)]
for y in range(h):
    for x in range(w):
        if src[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 src[ny][nx] == '
                break
        else:
            print('No')
            exit()
print('Yes')

Solution (Python):
H,W = map(int,input().split())
grid = [None for _ in range(H)]
for i in range(H):
  s = input()
  grid[i] = s
dire = [[0,-1],[-1,0],[1,0],[0,1]]
for r in range(H):
  for c in range(W):
    if grid[r][c] == "
      ok = False
      for d in dire:
        if 0 <= r+d[0] and r+d[0] < H and 0 <= c+d[1] and c+d[1] < W and grid[r+d[0]][c+d[1]] == "
          ok = True
          break
      if not ok:
        print("No")
        exit()
print("Yes")

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

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

DX = [-1, 0, 1, 0]
DY = [0, -1, 0, 1]

ans = True

for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            continue
        flag = 0
        for k in range(4):    
            if not(0<=j+DX[k]<=w-1 and 0<=i+DY[k]<=h-1):
                continue
            if s[i + DY[k]][j + DX[k]] == "
                flag = 1
                break
        if flag == 0:
          ans = False
          break
print("Yes" if ans else "No")

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


def check(mtrx, n, m):
    if mtrx[n][m] == '
        return True
    else:
        return False
if __name__ == '__main__':
    main()

Solution (Python):
H,W = map(int,input().split())
HW = []
for i in range(H+2):
    if i == 0 or i == H+1:
        HW.append(["."]*(W+1))
    else:
        HW.append(["."]+list(input())+["."])

for i in range(1,H):
    for j in range(1,W):
        if HW[i][j] == "
            if HW[i-1][j] == "
                continue
            else:
                print("No")
                exit()
print("Yes")

Solution (Python):
h,w = [int(x) for x in input().split()]
l = []
for _ in range(h):
    l.append(list(input()))
possible = True
tmplst = []

for i in range(h):
    for y in range(1,w-1):
        if l[i][y-1] == l[i][y+1] == '.' and l[i][y] == '
            tmplst.append([i,y])

for x in tmplst:
    if x[0] == 0:
        if l[0][x[1]] == '.':
            possible = False
    elif x[0] == h-1:
        if l[h-1][x[1]] == '.':
            possible = False
    else:
        if l[x[0]-1][x[1]] == l[x[0]+1][x[1]] == '.':
            possible = False

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

Solution (Python):
H,W=map(int, input().split())
s = []
dx = [  0, 0, 1, -1]
dy = [ -1, 1, 0, 0]
ans = "Yes"
for i in range(H):
  s.append( input())
for y in range(H):
  for x in range(W):
    if s[y][x] == '
      ng = 1
      for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if (ny < 0) or (ny >= H) or (nx<0) or (nx>=W):
          continue
        if s[ny][nx] == '
          ng = 0
      if ng == 1:
        ans = "No"
print(ans)

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

s = [0]*(H+2)

s[0] = ["."]*(W+2)

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

s[H+1] = ["."]*(W+2)



det = 0
for i in range(1,H+1):
    for j in range(1,W+1):
        
        if s[i][j] == "
            det = -1

if det == -1:
    print("No")
else:
    print("Yes")

Solution (Python):
H,W=map(int,input().split())
field=[["
for i in range(H):
    field.append(["
    field[-1].extend(list(input()))
    field[-1].append("
field.append(["
for i in range(1,H+1):
    for j in range(1,W+1):
        cnt=0
        for dy,dx in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            if field[i][j]=="
                cnt+=1
        if cnt==4:
            print("No")
            exit()
print("Yes")

Solution (Python):
h,w = (int(x) for x in input().split())
ab = []
count = 0
for _ in range(h):
    a = input()
    a = a+'.'
    ab.append(list(a))
ab.append(list('.'*w))

for i in range(h):
    for j in range(w):
        if ab[i][j] == '
            if ab[i+1][j] == '
                continue
            elif ab[i][j+1] == '
                continue
            elif ab[i-1][j] == '
                continue
            elif ab[i][j-1] == '
                continue
            else:
                print('No')
                exit()
print('Yes')

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

s=[]
t=[]
for hh in range(h):
    s.append(list(input()))
    t.append([1]*w)

for hh in range(h):
    for ww in range(w):
        if s[hh][ww]==".":
            t[hh][ww]=0
        else:
            if hh==0:
                if s[hh+1][ww]=="
                    t[hh][ww]=0
            elif hh==h-1:
                if s[hh-1][ww]=="
                    t[hh][ww]=0
            else:
                if s[hh+1][ww]=="
                    t[hh][ww]=0
                if s[hh-1][ww]=="
                    t[hh][ww]=0
            if ww==0:
                if s[hh][ww+1]=="
                    t[hh][ww]=0
            elif ww==w-1:
                if s[hh][ww-1]=="
                    t[hh][ww]=0
            else:
                if s[hh][ww+1]=="
                    t[hh][ww]=0
                if s[hh][ww-1]=="
                    t[hh][ww]=0
tmax=0
for hh in range(h):
    if max(t[hh])>0:
        tmax=1

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

Solution (Python):
h, w = map(int, input().split())
cv = [input() for _ in range(h)]
for y in range(h):
    for x in range(w):
        if cv[y][x] == '
            if (y > 0 and cv[y - 1][x] == '
                    or (x > 0 and cv[y][x - 1] == '
                continue
            print('No')
            exit()
print('Yes')

Solution (Python):
h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
s.insert(0,["." for i in range(w)])
s.append(["." for i in range(w)])
for i in range(h+2):
  s[i].insert(0,".")
  s[i].append(".")
ans = True
for i in range(1,h+1):
  for j in range(1,w+1):
    if "
      ans = False
print("Yes" if ans else "No")

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

board = [input() for i in range(h)]

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

ans = 'Yes'

for i in range(h):
  for j in range(w):
    if board[i][j] == '
      T_F = False
      for d in range(4):
        ni = i + dx[d]
        nj = j + dy[d]
        if 0 <= ni < h and 0 <= nj < w and board[ni][nj] == '
          T_F = True
      if not T_F :
        ans = 'No'
        break
print(ans)

Solution (Python):

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

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

field = []

for i in range(H):
    field.append(list(input()))

for y in range(H):
    for x in range(W):
        
        if field[y][x] == "

            cnt = 0

            for k in range(4):

                ny = y + dy[k]
                nx = x + dx[k]

                if ny < 0 or H <= ny or nx < 0 or W <= nx:
                    continue

                if field[ny][nx] == "
                    cnt += 1

            if cnt == 0:
                print("No")
                exit()

print("Yes")

Solution (Python):
h,w = map(int,input().split())
canbas = []
for _ in range(h):
    canbas.append(input())
x = 0
for i in range(h):
    for j in range(w):
        if canbas[i][j] == '.':
            continue
        else:
            if i ==0:
                a = '.'
            else:
                a = canbas[i-1][j]
            if j ==0:
                b = '.'
            else:
                b = canbas[i][j-1]
            if i == h-1:
                c = '.'
            else:
                c = canbas[i+1][j]
            if j == w-1:
                d = '.'
            else:
                d = canbas[i][j+1]
            if a==b==c==d=='.':
                x = 1
                break
    if x == 1:
        break

if x == 1:
    print('No')
else:
    print('Yes')

Solution (Python):

h,w=map(int,input().split())
s=['.'+input()+'.' for _ in range(h)]
s=['.'*(w+2)]+s+['.'*(w+2)]
flg=True
for i in range(1,h+1):
    for  j in range(1,w+1):
        if s[i][j]=='
            if all(s[i+_i][j+_j]=='.' for _i,_j in [(1,0),(0,1),(-1,0),(0,-1)]):
                flg=False
                break

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

Solution (Python):


def get_ans():
    (h, w) = [int(i) for i in input().rstrip().split(" ")]
    map = [input().rstrip() for i in range(h)]

    for i in range(h):
        for j in range(w):
            if map[i][j] != "
                continue

            nearBlack = False
            for k in range(i - 1, i + 2):
                if k < 0 or k >= h:
                    continue
                for l in range(j - 1, j + 2):
                    if (l < 0) or (l >= w):
                        continue
                    if k == i and l == j:
                        continue
                    if k != i and l != j:
                        continue
                    if map[k][l] == "
                        nearBlack = True
                        break
                if nearBlack:
                    break

            if not nearBlack:
                return False
    return True


print("Yes" if get_ans() else "No")

Solution (Python):
h,w = map(int,input().split())
s = [input() for i in range(h)]
def judge(i,j,s):
    
    for k in range(-1,2):
        for l in range(-1,2):
            if abs(k-l) == 1:
                temp_i = i+k
                temp_j = j+l
                if temp_i < 0 or temp_i-1 > h or temp_j < 0 or temp_j > w-1:
                    
                    pass
                else:
                    
                    
                    if s[temp_i][temp_j] == '
                        return True
    return False

flag = True
for i in range(h):
    for j in range(w):
        
        if s[i][j] == '
            flag = judge(i,j,s)
            if flag == False:
                print('No')
                exit()
print('Yes')

Solution (Python):
h, w = map(int, input().split())
A = []
A.append("."*(w+2))
for i in range(h):
  A.append(list("." + input() + "."))
A.append("."*(w+2))
f = True
for i in range(1, h+1):
  for j in range(1, w+1):
    if A[i][j] == "
      f = False
if f:print("Yes")
else: print("No")

Solution (Python):
h, w = map(int, input().split())
s = [input() for _ in range(h)]
idx = [[-1, 0], [0, -1], [0, 1], [1, 0]]
a = "Yes"
for i in range(h):
    for j in range(w):
        if s[i][j] != "
        else:
            t = False
            for h_, w_ in idx:
                i_, j_ = i + h_, j + w_
                if (i_ == -1 or i_ == h) or (j_ == -1 or j_ == w): continue
                elif s[i_][j_] == "
                    t = True
                    break
            if t == False: a = "No"
    if a == "No": break
print(a)

Solution (Python):
n, m = map(int, input().split())
mat = [input() for _ in range(n)]


for i in range(n):
    for j in range(m):
        target = mat[i][j]
        if target == "
            if not i == 0:
                if mat[i-1][j] == "
                    continue
            if not i == n-1:
                if mat[i+1][j] == "
                    continue
            if not j == 0:
                if mat[i][j-1] == "
                    continue
            if not j == m-1:
                if mat[i][j+1] == "
                    continue
            print("No")
            exit()
                
print("Yes")

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

grid = [list('.'+input()+'.') for i in range(H)]

grid.insert(0, list('.' * (W + 2)))
grid.append(list('.' * (W + 2)))

tmp = 0
for i in range(1, H + 1):
  for j in range(1, W + 1):
    if grid[i][j] == '
        tmp += 1

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

Solution (Python):
import sys
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
hantei = [[0 for _ in range(w)] for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == "
            if i < h-1:
                if s[i+1][j] == "
                    hantei[i][j] = 1
                    hantei[i+1][j] = 1
            if j < w-1:
                if s[i][j+1] == "
                    hantei[i][j] = 1
                    hantei[i][j+1] = 1

for i in range(h):
    for j in range(w):
        if s[i][j] == "
            if hantei[i][j] == 0:
                print("No")
                sys.exit()

print("Yes")

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

for i in range(H):
    for j in range(W):
        if s[i][j]=="
            if (i==0):
                if (j==0):
                    if not((s[i][j+1]=="
                        flag=0
                elif (j==W-1):
                    if not((s[i][j-1]=="
                        flag=0
                else:
                    if not((s[i][j-1]=="
                        flag = 0

            elif (i==H-1):
                if (j==0):
                    if not((s[i-1][j]=="
                        flag=0
                elif (j==W-1):
                    if not((s[i-1][j]=="
                        flag=0
                else:
                    if not((s[i][j+1]=="
                        flag=0
            else:
                if (j==0):
                    if not ((s[i + 1][j] == "
                        flag = 0
                elif (j==W-1):
                    if not ((s[i + 1][j] == "
                        flag = 0
                else:
                    if not((s[i+1][j]=="
                        flag=0
if flag==1:
    print("Yes")
else:
    print("No")

Solution (Python):

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

trout = []

for i in range(H):
    trout.append(list(input()))


h = H-1
w = W-1

reslut = "Yes"
for i in range(H):
    for j in range(W):
        
        c = -1
        
        if trout[i][j] == ".":
            pass
        
        else:
             
            if i>=1 and trout[i-1][j] == "
                c = 1
             
            if j>=1 and trout[i][j-1] == "
                c = 1
            
            if j<w and trout[i][j+1] == "
                c = 1
            
            if i<h and trout[i+1][j] == "
                c = 1
            
            if c == -1:
                reslut = "No"
                break
    else:
        continue
    break
    
print(reslut)

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

for i in range(H):
  c = list(input())
  grid[i] = c
  
black = "
white = "."

ans = "Yes"

for i in range(H):
  for j in range(W):
    if grid[i][j] == black:
      around = ""
      
      for t in range(max(0,j - 1),min(W,j + 2)):
        if t != j:
          around += grid[i][t]
      
      for k in range(max(0,i - 1),min(H,i + 2)):
        if k != i:
          around += grid[k][j]
      
      if all([s == white for s in around]):
        ans = "No"
        break
  if ans == "No":
    break
      
print(ans)

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

ans = "Yes"
for i in range(1, h+1):
    for j in range(1, w+1):
        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):
H, W = map(int, input().split())
S = [list(input()) for i in range(H)]

check_pat = [(1, 0), (-1, 0), (0, -1), (0, 1)]
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            continue

        if H == 1:
            if W == 1:
                check_pat = []
            elif j == W-1:
                check_pat = [(0, -1)]
            else:
                check_pat = [(0, -1), (0, 1)]
        elif i == 0:
            if W == 1:
                check_pat = [(1, 0)]
            elif j == W-1:
                check_pat = [(1, 0), (0, -1)]
            else:
                check_pat = [(1, 0), (0, -1), (0, 1)]
        elif i == H-1:
            if W == 1:
                check_pat = [(-1, 0)]
            elif j == W-1:
                check_pat = [(-1, 0), (0, -1)]
            else:
                check_pat = [(-1, 0), (0, -1), (0, 1)]
        else:
            if W == 1:
                check_pat = [(-1, 0), (1, 0)]
            elif j == W-1:
                check_pat = [(-1, 0), (1, 0), (0, -1)]
            else:
                check_pat = [(-1, 0), (1, 0), (0, -1), (0, 1)]

        ng_flg = 1
        for pat in check_pat:
            if S[i+pat[0]][j+pat[1]] == "
                ng_flg = 0
                break
        if ng_flg == 1:
            print("No")
            exit()

print("Yes")

Solution (Python):
H, W = map(int, input().split())
pic = [list(input()) for _ in range(H)]
ans = 'Yes'
for i in range(H):
    for j in range(W):
        if pic[i][j] == '
            if j != 0 and pic[i][j-1] == '
                continue
            if j != W-1 and pic[i][j+1] == '
                continue
            if i != 0 and pic[i-1][j] == '
                continue
            if i != H-1 and pic[i+1][j] == '
                continue
            ans = 'No'
            print(ans)
            exit()
print(ans)

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

src = [input() for i in range(H)]

ans = []
for row in src:
    ans.append(list(row))

answer = "Yes"
for i in range(H):
    for j in range(W):
        if ans[i][j]== "
            if i-1>= 0 and ans[i-1][j]=="
                continue
            elif i+1<= H-1 and ans[i+1][j]=="
                continue
            elif j-1 >= 0 and ans[i][j-1]=="
                continue
            elif j+1 <= W-1 and ans[i][j+1]=="
                continue
            else:
                answer = "No"
                break
print(answer)