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())
s = [input() for i in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == "
            st = 0
            if i != 0:
                if s[i-1][j] == "
                    st = 1
            if j != 0:
                if s[i][j-1] == "
                    st = 1
            if i != h-1:
                if s[i+1][j] == "
                    st = 1
            if j != w-1:
                if s[i][j+1] == "
                    st = 1
            if st == 0:
                print("No")
                exit()

print("Yes")

Solution (Python):
h,w = map(int,input().split())
data = [input() for _ in range(h)]
t = True
for i in range(h):
    for j in range(w):
        if data[i][j] == '
            if i >= 0 and data[i-1][j] == '
            elif h-1 > i  and data[i + 1][j] == '
            elif j >= 0 and data[i][j - 1] == '
            elif w-1 > j and data[i][j + 1] == '
            else:
                t = False
                break

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

Solution (Python):
import sys

h, w = map(int, sys.stdin.readline().split())
canvas = ['.' * (w + 2)]
canvas += ['.' + sys.stdin.readline().rstrip() + '.' for _ in range(h)]
canvas += ['.' * (w + 2)]

def main():
    d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    for i in range(1, h+1):
        for j in range(1, w+1):
            if canvas[i][j] == '
                for di, dj in d:
                    y = i + di
                    x = j + dj
                    if canvas[y][x] == '
                        break
                else:
                    return 'No'
    return 'Yes'

if __name__ == '__main__':
    ans = main()
    print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    s = []
    H, W = LI()
    for i in range(H):
        _s = S()
        s.append(_s)
    for r in range(H):
        for c in range(W):
            if s[r][c] == '.':
                continue
            any_tonari_black = False
            for dr, dc in zip(DR, DC):
                new_r = r + dr
                new_c = c + dc
                if not (0 <= new_r < H and 0 <= new_c < W):
                    continue
                if s[new_r][new_c] == '
                    any_tonari_black = True
            if not any_tonari_black:
                print('No')
                return
    print('Yes')
main()

Solution (Python):

def main()->None:
    H, W = map(int, input().split())
    range_H = range(H)
    range_W = range(W)
    src = [input() for _ in range_H]
    
    ans = [["." for _ in range_W] for _ in range_H]
    
    dxdy = [(-1,0),(0,-1),(0,1),(1,0)]
    
    for y in range_H:
        for x in range_W:
            c = "."
            if src[y][x] == ".":continue
            for dx, dy in dxdy: 
                if x+dx < 0 or x+dx > W-1 or y+dy < 0 or y+dy > H-1 :continue
                if src[y+dy][x+dx] == "
                    c = "
            ans[y][x] = c
    
    flag = True
    counter = 0
    for i in ans:
        res = "".join(i)
        if res == src[counter]:
            counter += 1
        else:
            flag = False
    if flag: 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+=['.'*(w+2)]
for i in range(h):
    for j in range(w):
        if s[i+1][j+1]=='
            if (s[i][j+1]+s[i+1][j]+s[i+1][j+2]+s[i+2][j+1]).count('.')==4:
                print('No')
                quit()
print('Yes')

Solution (Python):
import sys
h, w = [int(i) for i in sys.stdin.readline().split()]
s_ls = []
for i in range(h):
    s = [i for i in sys.stdin.readline().strip()]
    s_ls.append(s)

def check(y, x):
    flg = False
    for move_y, move_x in [(0,1), (0,-1), (1,0), (-1,0)]:
        next_y = max(0, min(h-1, y + move_y))
        next_x = max(0, min(w-1, x + move_x))
        flg |= s_ls[next_y][next_x] == "
    return flg

flg = True
for i in range(h):
    for j in range(w):
        if s_ls[i][j] == "
            flg &= check(i, j)
print("Yes" if flg else "No")

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

ans = "Yes"

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

for h in range(1, H + 1):
    for w in range(1, W + 1):
        if s[h][w] == "
            t = [s[h + 1][w], s[h - 1][w], s[h][w + 1], s[h][w - 1]]
            if "
                ans = "No"
                break
    else:
        continue
    break

print(ans)

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

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

grid = ["."*(w+2)]
for _ in range(h):
    grid.append("." + input() + ".")
grid += ["."*(w+2)]

for i in range(1,h+1):
    for j in range(1,w+1):
        if grid[i][j]=="
            if not (grid[i][j-1]=="
                grid[i-1][j]=="
                    print("No")
                    exit()
print("Yes")

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

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

S = []
for i in range(0, h):
	temp = [x == '
	temp.insert(0, False)
	temp.append(False)
	S.append(temp)


S.insert(0, [False]*(w+2))
S.append([False]*(w+2))



def sol():
	for i in range(1, h+1):
		for j in range(1, w+1):
			if S[i][j]:
				if S[i-1][j] or S[i+1][j] or S[i][j-1] or S[i][j+1]:
					pass
				else:
					return('No')
	else:
		return('Yes')

print(sol())

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

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


def canAchive(m):
    for i in range(h):
        for j in range(w):
            around = [m[i-1][j],
                      m[i+1][j],
                      m[i][j-1],
                      m[i][j+1]]
            if m[i][j] == '
                return False
    return True


print('Yes' if canAchive(m) else 'No')

Solution (Python):
H,W = map(int,input().split())
black_count = 0
board = []
got_start = False
ans = "Yes"
start_point = None
for h in range(H):
  row = tuple(input())
  if "
    index = row.index("
    if got_start == False:
      start_point = (h,index)
      got_start = True
  board.append(row)

def check(y,x):
  if y >= H or y < 0 or x >= W or x < 0:
    return 0
  if board[y][x] == "
    return 1

for i in range(H):
  for j in range(W):
    y,x = i,j
    if board[i][j] == ".":
      continue
    is_adjacent = False
    if check(y + 1,x):
      is_adjacent = True
    if check(y - 1,x):
      is_adjacent = True
    if check(y, x + 1):
      is_adjacent = True
    if check(y,x - 1):
      is_adjacent = True
    if is_adjacent == False:
      ans = "No"
print(ans)

Solution (Python):

import sys
def resolve():
    input = sys.stdin.readline
    H,W=map(int,input().rstrip().split())
    S=[input().rstrip() for _ in range(H)]

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

    for i in range(H):
        for j in range(W):
            if(S[i][j]=="
                for dir in range(4):
                    nx=j+dx[dir]
                    ny=i+dy[dir]

                    if(nx<0 or nx>=W):
                        continue
                    if(ny<0 or ny>=H):
                        continue

                    if(S[i][j]==S[ny][nx]):
                        break
                else:
                    print("No")
                    return
    print("Yes")




from io import StringIO
import unittest

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):
h,w=map(int,input().split())
s=[input() for i in range(h)]
v=[(-1,0),(1,0),(0,-1),(0,1)]
for i in range(h):
    for j in range(w):
        if s[i][j]=="
            ans=True
            for k in v:
                if 0<=i+k[0]<h and 0<=j+k[1]<w and s[i+k[0]][j+k[1]]=="
                    ans=False
                    break
            if ans:
                
                print("No")
                exit()
print("Yes")

Solution (Python):
import sys
h, w = map(int, input().split())
grid = [['.' for i in range(w + 2)]]
for i in range(h):
    row = input()
    grid.append('.' + row + '.')
grid.append(['.' for i in range(w + 2)])

for i in range(1,h+1):
    for j in range(1, w+1):
        if grid[i][j] == '
            if '
                print('No')
                sys.exit()
print('Yes')

Solution (Python):
h,w = map(int,input().split())
s = [input() for _ in range(h)]
count = [[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if j>0   and s[i][j-1] == '
        if j<w-1 and s[i][j+1] == '
        if i>0   and s[i-1][j] == '
        if i<h-1 and s[i+1][j] == '

ans='Yes'
for row1,row2 in zip(s,count):
    for c1,c2 in zip(row1,row2):
        if c1 == '
            ans = 'No'
print(ans)

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

ans = 'Yes'

for h, s in enumerate(S):
	for w, c in enumerate(s):
		if c == '
			if w-1 >= 0 and S[h][w-1] == '
				continue
			if w+1 < W and S[h][w+1] == '
				continue
			if h-1 >= 0 and S[h-1][w] == '
				continue
			if h+1 < H and S[h+1][w] == '
				continue
			ans = 'No'
			break
	else:
		continue
	break
	
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(3000)
h, w = map(int, raw_input().split())
s = [[c for c in raw_input()] for i in range(h)]
def isValid(i, j):
    if i < 0 or i >= h or j < 0 or j >= w:
        return False
    return True
    
def dfs(s, i, j):
    if not isValid(i, j) or s[i][j] == "0" or s[i][j] == ".":
        return 0
    if s[i][j] == "
        s[i][j] = "0"
        a = dfs(s, i+1, j)
        b = dfs(s, i-1, j)
        c = dfs(s, i, j+1)
        d = dfs(s, i, j-1)
        return 1 + a + b + c + d

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

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

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

Solution (Python):

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

cmbs = [["."] + list(input()) + ["."]  for _ in range(h)]
cmbs.insert(0,["."] * (w+2))
cmbs.append(["."] * (w+2))



ret = "Yes"
for i in range(1,h+1):
    for j in range(1,w+1):
        if cmbs[i][j] == "
            if cmbs[i-1][j] =="." and cmbs[i+1][j] =="." and cmbs[i][j-1] =="." and cmbs[i][j+1] ==".":
                ret ="No"
print(ret)

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

H,W = map(int, input().split())
vP = ["." * (W+2),]
mM = vP+["."+input()+"." for _ in [0,]*H]+vP
mD = [(-1,0),(1,0),(0,-1),(0,1)]

for i in range(1,H+1):
  for j in range(1,W+1):
    if (mM[i][j]=="
        all(mM[i+x][j+y]=="."
            for x,y in mD)):
      print("No")
      exit(0)

print("Yes")

Solution (Python):
h, w = map(int, input().split())
grid = ['.'*(w+2)]
for _ in range(h):
    line = '.' + input() + '.'
    grid.append(line)
grid.append('.'*(w+2))

for i in range(1, h+1):
    for j in range(1, w+1):
        if grid[i][j] == '.':
            continue
        else:
            up = grid[i-1][j]
            right = grid[i][j+1]
            left = grid[i][j-1]
            down = grid[i+1][j]

            if up + right + left + down == '....':
                print('No')
                exit()

print('Yes')

Solution (Python):
h,w=map(int,input().split())
L=[list(input()) for i in range(h)]
dx=[1,0,-1,0]
dy=[0,1,0,-1]
flag=0
for i in range(h):
    for j in range(w):
        c=0
        d=0
        if L[i][j]=='
            for k in range(4):
                if (j+dx[k] in range(w)) and (i+dy[k] in range(h)):
                    d+=1
                    if L[i+dy[k]][j+dx[k]]=='.':
                        c+=1
            if c!=0 and c==d:
                flag=1
print('Yes' if flag==0 else 'No')

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

grid = []

grid.append(['.']*(w+2))
for row in grid_t:
	grid.append(row)
grid.append(['.']*(w+2))

ok = 1
for i in range(h+2):
    for j in range(w+2):
        if grid[i][j] == '
            if grid[i+1][j] != '
                ok = 0

print("Yes" if ok == 1 else "No")

Solution (Python):
H, W = map(int, input().split())
s = [input() for i in range(H)]
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
ans = "Yes"
for i in range(H):
        for j in range(W):
                if s[i][j] == "
                        flag = 1 
                        for k in range(4):
                                y = i + dy[k]
                                x = j + dx[k]
                                if 0 <= x < W and 0 <= y < H:
                                        if s[y][x] == "
                                                flag = 0 
                        if flag:
                                ans = "No"
                                break
        else:
                continue
        break
print(ans)

Solution (Python):
H, W = map(int, input().split())
s = [[True]*(W+2)]
for i in range(H):
    st = input()
    l = [False]
    for t in st:
        l.append(t == "
    l.append(False)
    s.append(l)
s.append([True]*(W+2))

flag = True
for i in range(1, H+1):
    for j in range(1, W+1):
        if s[i][j] and not s[i][j-1] and not s[i][j+1] and not s[i+1][j] and not s[i-1][j]:
            flag = False
            break

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

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

flag = True
for i in range(H):
    for j in range(W):
        if S[i][j] == '
            
            if (i-1 >= 0 and S[i-1][j] == '
                continue
            else:
                flag = False

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

Solution (Python):
import sys
input = sys.stdin.readline
H, W = [int(x) for x in input().split()]
s = []
for _ in range(H):
    temp = list(input().rstrip())
    s.append(temp)
def A(i,j,s):
    next_point = [[i+1,j],[i-1,j],[i,j-1],[i,j+1]]
    for n in next_point:
        x, y = n[0], n[1]
        if 0 <= x <= H-1 and 0 <= y <= W-1:
            if s[x][y] == "
                return 0
    return 1
for k in range(H):
    for l in range(W):
        flag = 0
        if s[k][l] == "
            flag = A(k,l,s)
        if flag:
            print("No")
            sys.exit()
print("Yes")

Solution (Python):
import numpy as np
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

H,W = map(int,readline().split())
grid = np.frombuffer(read(),'S1').reshape(H,-1)[:,:W]

white = (grid == b'.')

U = np.ones((H + 2, W + 2), np.int32)
U[:H, :W] = white
for i in range(H):
  for j in range(W):
    if U[i, j] == 0:
      if U[i - 1, j] * U[i + 1, j] * U[i, j - 1] * U[i, j + 1] != 0:
        print('No')
        quit()
print('Yes')

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

def search(y,x):
    if mat[y][x] == '
        y2 = [0,0,1,-1]
        x2 = [1,-1,0,0]
        for i in range(4):
            if 0<=y+y2[i]<=H-1 and 0<=x+x2[i]<=W-1:
                if mat[y+y2[i]][x+x2[i]] == '
                    return True
        return False
    
    return True
ans = 'Yes'
for i in range(H):
    for j in range(W):
        if ans == 'No':
            break
        if search(i,j):
            continue
        else:
            ans = 'No'
            break
print(ans)

Solution (Python):
import sys
H, W = map(int, sys.stdin.readline().split())
L = ['.' + sys.stdin.readline().rstrip() +'.' for _ in range(H)]
L.insert(0, '.'*(W+2))
L.append('.'*(W+2))

f = 'Yes'
for i in range(1, H+1):
    for j in range(1, W+1):
        if L[i][j] =='
            if not '
                f = 'No'
                break

print(f)

Solution (Python):
h,w=map(int,input().split())
a=[]
for i in range(h):
  a.append(list("."+(input())+"."))
a.insert(0,["."]*(w+2))
a.append(["."]*(w+2))
flg = True
for i in range(h+2):
  for j in range(w+2):
    if a[i][j] == "
      for (k,l) in ((i,j+1),(i,j-1),(i+1,j),(i-1,j)):
        if a[k][l] != "
          cnt+=1
          if cnt == 4:
            flg = False
    cnt=0
if flg:
  print("Yes")
else:
  print("No")

Solution (Python):

import sys
import numpy as np

YES = "Yes"  
NO = "No"  


def solve(H: int, W: int, s: "List[str]"):
    ans = YES
    for i in range(1, H-1):
        for j in range(1, W-1):
            if s[i][j] == "
                ans = NO
    print(ans)


def main():
    H, W = map(int,input().split())  
    s = [input() for _ in range(H)]  
    solve(H, W, s)

if __name__ == '__main__':
    main()

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

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


def four_next(i,j):
    global s
    if i>0 :
        if s[i-1][j]=="
            return True
    if i<h-1 :
        if s[i+1][j]=="
            return True
    if j>0 :
        if s[i][j-1]=="
            return True
    if j<w-1 :
        if s[i][j+1]=="
            return True
    return False

f=0
for i in range(h):
    for j in range(w):
        if s[i][j]=="
            f=1
            break
    if f==1:
        break
if f==0:
    print("Yes")
else:
    print("No")

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

Solution (Python):
H, W = map(int, input().split())
s = []
for i in range(H):
    s_i = input()
    s.append([s_i[i] for i in range(len(s_i))])
direction = [[1, 0], [-1, 0], [0, -1], [0, 1]]
for i in range(H):
    for j in range(W):
        if s[i][j] == "
            
            is_isolated = True
            for arrow in direction:
                neigh = [i + arrow[0], j + arrow[1]]
                if neigh[0] == -1 or neigh[0] == H or neigh[1] == -1 or neigh[1] == W:
                    continue
                if s[neigh[0]][neigh[1]] == "
                    is_isolated = False
                    break
            if is_isolated:
                print("No")
                exit()
print("Yes")

Solution (Python):
import queue as q

direction = [[1, 0], [-1, 0], [0, -1], [0, 1]]

H, W = map(int, input().split())
s = []
for i in range(H):
    s_i = input()
    s.append([s_i[i] for i in range(len(s_i))])


def do_bfs(s, que):
    while True:
        if que.empty():
            break
        pos = que.get()
        for arrow in direction:
            next = [pos[0] + arrow[0], pos[1] + arrow[1]]
            if next[0] == -1 or next[0] == H or next[1] == -1 or next[1] == W:
                continue
            if s[next[0]][next[1]] == "
                que.put(next)
                s[next[0]][next[1]] = "."


for i in range(H):
    for j in range(W):
        if s[i][j] == "
            
            is_conneted = False
            for arrow in direction:
                neighbor = [i + arrow[0], j + arrow[1]]
                if (
                    neighbor[0] == -1
                    or neighbor[0] == H
                    or neighbor[1] == -1
                    or neighbor[1] == W
                ):
                    continue
                if s[neighbor[0]][neighbor[1]] == "
                    is_conneted = True
                    break
            if is_conneted:
                s[i][j] = "."
                que = q.Queue()
                que.put([i, j])
                do_bfs(s, que)

for i in range(H):
    for j in range(W):
        if s[i][j] == "
            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-1):
    for j in range(W-1):
        if s[i][j] == "
            if s[i-1][j] == "." and s[i+1][j] == "." and s[i][j-1] == "." and s[i][j+1] == ".":
                print("No")
                exit()

print("Yes")

Solution (Python):
h, w = map(int, input().split())
a=[[j for j in input()] for i in range(h)]
ans = 'Yes'
for i in range(h):
    for j in range(w):
        if a[i][j] == "
            if 1<=i<=h-2 and 1<=j<=w-2:
                if a[i-1][j] == "." and a[i+1][j] == "." and a[i][j-1] == "." and a[i][j+1] == ".":
                    ans = 'No'
                    break
            elif i == 0 and 1<=j<=w-2:
                if a[i][j-1] == "." and a[i][j+1] == "." and a[i+1][j] == ".":
                    ans = 'No'
                    break
            elif  i == h and 1<=j<=w-2:
                if a[i][j-1] == "." and a[i][j+1] == "." and a[i-1][j] == ".":
                    ans = 'No'
                    break
            elif 1<=i<=h-2 and j == 0 :
                if a[i-1][j] == "." and a[i+1][j] == "." and a[i][j+1] == "." :
                    ans = 'No'
                    break
            elif 1<=i<=h-2 and j == w:
                if a[i-1][j] == "." and a[i+1][j] == "." and a[i][j-1] == "." :
                    ans = 'No'
                    break
            elif i==0 and j==0:
                if a[i][j+1]=="." and a[i+1][j]==".":
                    ans = 'No'
                    break 
            elif i==h-1 and j==0:
                if a[i-1][j]=="." and a[i][j+1]==".":
                    ans = 'No'
                    break 
            elif i==0 and j==w-1:
                if a[i][j-1]=="." and a[i+1][j]==".":
                    ans = 'No'
                    break 
            elif i==h-1 and j==w-1:
                if a[i][j-1]=="." and a[i-1][j]==".":
                    ans = 'No'
                    break 
print(ans)

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

def check(h,w):
    dx = [0,0,-1,1]
    dy = [1,-1,0,0]
    for k in range(len(dx)):
        if 0 <= h+dy[k] <= (H-1) and 0 <= w+dx[k] <= (W-1):
            if s[h+dy[k]][w+dx[k]] == "
                break
            elif k == 3:
                return True
    return False

ans = "Yes"
for i in range(H):
    for j in range(W):
        if s[i][j] == "
            if check(i,j):
                ans = "No"
                break
print(ans)

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

area = []
for i in range(h):
    array = input()
    area.append(array)


def check(i, j):
    x_1 = max(0, j-1)
    x_2 = min(j+1, w-1)
    y_1 = max(0, i-1)
    y_2 = min(i+1, h-1)
    if area[y_1][j] == '
        a = 0
    else:
        print('No')
        exit()

for i in range(h):
    for j in range(w):
        if area[i][j] == '
            check(i, j)

print('Yes')

Solution (Python):
H, W=map(int, input().split())
m=[[-1 for i in range(W+2)]]
mm=[[-1]+[0 for i in range(W)]+[-1] for j in range(H)]
m=m+mm+m

for i in range(1, H+1):
  s=input()
  for j in range(1, W+1):
    if s[j-1]=='
      m[i][j]=1
      
out='Yes'
for i in range(1, H+1):
  for j in range(1, W+1):
    if m[i][j]==1:
      if m[i-1][j]<1 and m[i+1][j]<1 and m[i][j-1]<1 and m[i][j+1]<1:
        out='No'
        
print(out)

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

s = [input() for _ 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):
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

H, W = MAP()
M = [input().rstrip() for _ in range(H)]

for h in range(H):
	for w in range(W):
		if M[h][w] == '
			
			cnt = 0
			for dh, dw in [[-1,0],[0,1],[1,0],[0,-1]]:
				nh = h+dh
				nw = w+dw
				if nh < H and nh >= 0 and nw < W and nw >= 0:
					cnt += 1
					if M[nh][nw] == '.':
						cnt -= 1
			if cnt == 0:
				print('No')
				sys.exit()

print('Yes')

Solution (Python):

import sys
if sys.platform =='ios':
	sys.stdin=open('input_file.txt')

h,w = map(int,input().split())
s = [str('

test = ''
for i in range(w+2):
	test = test + '


s.insert(0,test)


s.insert(len(s),test)




check = 0

for i in range(1,h+1):
	for j in range(1,w+1):
		if s[i][j]=='
			if s[i-1][j]=='.' and s[i+1][j]=='.' and s[i][j+1]=='.' and s[i][j-1]=='.':
				check = check + 1

print('Yes' if check ==0 else 'No')

Solution (Python):

import sys


sys_input = sys.stdin.readline

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

areamap = []
areamap.append(['.']*(W+2))
for h in enumerate(range(H)):
    row = list(sys_input().replace('\n', ''))
    row = ['.'] + row + ['.']
    areamap.append(row)
areamap.append(['.']*(W+2))

for h in range(1, H+1):
    for w in range(1, W+1):
        if areamap[h][w] == '
                areamap[h][w+1] == '.' and \
                areamap[h][w-1] == '.' and \
                areamap[h+1][w] == '.' and \
                areamap[h-1][w] == '.':
            print('No')
            exit()

print('Yes')

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

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

for i in range(H):
    for j in range(W):
        if canvas[i][j] == '
            up_cell = canvas[i - 1][j] if i > 0 else '.'
            down_cell = canvas[i + 1][j] if i < H - 1 else '.'
            right_cell = canvas[i][j + 1] if j < W - 1 else '.'
            left_cell = canvas[i][j - 1] if j > 0 else '.'
            if up_cell == '.' and down_cell == '.' and right_cell == '.' and left_cell == '.':
                print('No')
                exit()
print('Yes')