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())
count=0
S=["."]*(w+2)
T=[list(input()) for i in range(h)]
for i in range(h):
  T[i].insert(0,".")
  T[i].append(".")
T.insert(0,S)
T.append(S)
for i in range(1,h+1):
  for j in range(1,w+1):
    if T[i][j]=="
      count+=1
print("Yes" if count==0 else "No")

Solution (Python):



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

ans = "Yes"

for i in range(h):
    for j in range(w):
        if s[i][j] == "
            if i == 0:
                if j == 0:
                    if s[i][j+1] != "
                        ans = "No"
                        break
                elif j == w-1:
                    if s[i][j-1] != "
                        ans = "No"
                        break
                else:
                    if s[i][j-1] != "
                        ans = "No"
                        break
            elif i == h - 1:
                if j == 0:
                    if s[i][j+1] != "
                        ans = "No"
                        break
                elif j == w-1:
                    if s[i][j-1] != "
                        ans = "No"
                        break
                else:
                    if s[i][j-1] != "
                        ans = "No"
                        break
            else:
                if j == 0:
                    if s[i][j+1] != "
                        ans = "No"
                        break
                elif j == w-1:
                    if s[i][j-1] != "
                        ans = "No"
                        break
                else:
                    if s[i][j-1] != "
                        ans = "No"
                        break
    if ans == "No":
        break

print(ans)

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

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

def f(sss, i, j):
    if sss[i][j] == '.':
        return True
    for v in (-1, 1):
        if i+v < 0 or h <= i+v:
            continue
        if sss[i+v][j] == '
            return True
    for u in (-1, 1):
        if j+u < 0 or w <= j+u:
            continue
        if sss[i][j+u] == '
            return True
    return False

def solve(sss):
    for i in range(h):
        for j in range(w):
            if not f(sss, i, j):
                return False
    return True

print("Yes" if solve(sss) else "No")

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

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

print("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] == "
      top = max(0, i-1)
      bottom = min(h-1, i+1)
      right = min(w-1, j+1)
      left = max(0, j-1)
      if s[i][right] == s[i][left] == s[top][j] == s[bottom][j] == ".":
        print("No")
        exit()

print("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] == "
      top = max(0, i-1)
      bottom = min(h-1, i+1)
      right = min(w-1, j+1)
      left = max(0, j-1)
      if s[i][right] != "
        print("No")
        exit()

print("Yes")

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

for i in range(h):
  for j in range(w):
    if s[i][j] == "
      top = max(0, i-1)
      bottom = min(h-1, i+1)
      right = min(w-1, j+1)
      left = max(0, j-1)
      if s[i][right] != "
        flag = False
        break
  if flag == False:
    break

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

Solution (Python):

import sys

YES = "Yes"  
NO = "No"  


def inRange(h: int, w: int, H: int, W: int):
    return h >= 0 and w >= 0 and h < H and w < W


def solve(H: int, W: int, s: "List[str]"):
    failed = False
    for h in range(H):
        for w in range(W):
            cur = s[h][w]
            if cur == "
                if inRange(h-1, w, H, W) and s[h-1][w] == "
                    continue
                if inRange(h+1, w, H, W) and s[h+1][w] == "
                    continue
                if inRange(h, w-1, H, W) and s[h][w-1] == "
                    continue
                if inRange(h, w+1, H, W) and s[h][w+1] == "
                    continue
                failed = True
                break
        if failed:
            break
    print("No") if failed else print("Yes")
    return



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


if __name__ == '__main__':
    main()

Solution (Python):
import sys

def chk(i,j):
    if a[i][j]==".": return 0
    if i>0 and a[i-1][j]=="
    if i<H-1 and a[i+1][j]=="
    if j>0 and a[i][j-1]=="
    if j<W-1 and a[i][j+1]=="
    return 1

H,W=map(int,input().split())
a=[input() for i in range(H)]

for i in range(H):
    for j in range(W):
        if chk(i,j): print("No"),sys.exit()

print("Yes")

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

smap = [''.join('.' for _ in range(w+2))]
for _ in range(h):
  smap.append('.' + input().strip() + '.')
smap.append(''.join('.' for _ in range(w+2)))

is_black = True
for i, sline in enumerate(smap):
  for j, s in enumerate(sline):
    if s == '
      if smap[i][j-1] == '.' and smap[i][j+1] == '.' and smap[i-1][j] == '.' and smap[i+1][j] == '.':
        is_black = False

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

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

around = [[-1,0],[0,-1],[0,1],[1,0]]
clear = True
for i in range(1,H+1):
    for j in range(1,W+1):
        if s[i][j] == '
            if all((s[i+k[0]][j+k[1]] == '.' for k in around)):
                clear = False
                break
    else:
        continue
    break

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

Solution (Python):
def main():
    input = sys.stdin.readline
    try:
        H,W = map(int,input().split())
        s = [list(input()) for _ in range(H)]
        dir4 = ((0, 1), (0, -1), (1, 0), (-1, 0))
        for i in range(H):
            for j in range(W):
                if s[i][j] == ".": continue
                cnt = 0
                for d in dir4:
                    nx = i + d[0]
                    ny = j + d[1]
                    if not (0 <= nx < H): continue
                    if not (0 <= ny < W): continue
                    if s[nx][ny] == "
                if cnt == 0:
                    print("No")
                    exit()
        print("Yes")
        
    finally:
        input = None

import sys; sys.setrecursionlimit(50000)
if __name__ == "__main__":
    main()

Solution (Python):
H, W = [int(i) for i in input().split()]
list = [list(input()) for i in range(H)]
dxy = [(-1,0), (1, 0), (0, 1), (0, -1)]
flg = True
for i in range(H):
    for j in range(W):
        count = 0
        if list[i][j] == ".":
            continue
        if list[i][j] == "
            for l, m in dxy:
                if (i + l < 0) or (i + l > H -1) or (j + m < 0) or (j + m > W -1):
                    continue
                if list[i + l][j + m] == "
                    count += 1
        if count == 0:
            flg = False
if flg:
    print("Yes")
else:
    print("No")

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

out = "Yes"
for i in range(1,H+1):
    for j in range(1,W+1):
        if s[i][j] == "." :
            continue
        for k,l in ((1,0),(-1,0),(0,1),(0,-1)):
            if s[i+k][j+l] == "
                break
        else:
            out = "No"
            break
    if out=="No":
        break
print(out)

Solution (Python):
def count(i,j):
  count = 0
  if list[i][j-1]=='
    count +=1
  if list[i][j+1]=='
    count +=1
  if list[i-1][j]=='
    count +=1
  if list[i+1][j]=='
    count +=1
  if count >= 1:
    return True
  else:
    return False

h,w = map(int, input().split())
s_init='0'*(w+2)
flag=True
list=[]
list.append(s_init)
for i in range(h):
  s=str(input())
  list.append('0'+s+'0')
list.append(s_init)
for i in range(1,h+1):
  for j in range(1,w+1):
    if list[i][j]=='
      if not(count(i,j)):
        flag=False
if flag:
  print('Yes')
else:
  print('No')

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

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
  
flg = False
for i in range(H):
  for j in range(W):
    if S[i][j] == "
      flg = False
      for k in range(4):
        if i+dy[k]>=0 and i+dy[k]<H and j+dx[k]>=0 and j+dx[k]<W:
          if S[i+dy[k]][j+dx[k]]=='
            flg = True
      if flg == False:
        print("No")
        exit()
print("Yes")

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

glid = [0] * ( h+ 2)

h_index = [-1, 0, 0,  1]
w_index = [ 0, -1, 1, 0]



glid[0]=["."] * ( w + 2 )
glid[h + 1 ] = ["."] * ( w + 2 )

for i in range(h):
	temp1 = ["."]
	temp2 = list(input())
	temp1.extend(temp2)
	temp1.append(".")
	glid[ i + 1 ] = temp1



cnt = 0

for j in range(h):
	for k in range(w):
		if glid[ j + 1 ][ k + 1 ] == "
			cnt += 1

if cnt > 0 :
	print("No")
else:
	print("Yes")

Solution (Python):
H, W = map(int, input().split())
s = [list(input()) for i in range(H)]
check = [[False]*W]*H
dx = -1,0,1,0
dy = 0,-1,0,1

for h in range(H):
  for w in range(W):
    bcount = 0 
    if s[h][w] == "
      for i in range(4):
        if 0 <= h+dx[i] <= H-1 and 0 <= w+dy[i] <= W-1 and s[h+dx[i]][w+dy[i]] == "
            bcount += 1
      if bcount == 0:
        print("No")
        exit()
print("Yes")

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

S = [[0 for j in range(W)] for i in range(H)]
for i in range(H):
    for j, sij in enumerate(input()):
        S[i][j] = sij

flag = True

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

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

Solution (Python):
H, W = map(int, input().split())
s = []
for i in range(H):
    s.append(input())
for i in range(H):
    for j in range(W):
        if s[i][j] == "
            bool1 = i > 0 and s[i - 1][j] == "
            bool2 = i < H-1 and s[i+1][j] == "
            bool3 = j > 0 and s[i][j - 1] == "
            bool4 = j < W-1 and s[i][j + 1] == "
            if bool1 or bool2 or bool3 or bool4:
                continue
            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] == "
      if (i + 1 < h and s[i + 1][j] == "
        continue
      else:
        print("No")
        exit()
    else:
      continue
print("Yes")

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

def check_border(x, y):
  return 0<=x and x<W and 0<=y and y<H

def can_draw(x, y):
  a = 1 if check_border(x-1,y) and canvas[y][x-1]=='
  b = 1 if check_border(x+1,y) and canvas[y][x+1]=='
  c = 1 if check_border(x,y-1) and canvas[y-1][x]=='
  d = 1 if check_border(x,y+1) and canvas[y+1][x]=='
  return 0 < a+b+c+d
        

def solve():
  for y in range(H):
    for x in range(W):
      if  ((canvas[y][x]=='
  return True

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

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

H, W = map(int, input().split())
maps = [['.']*(W+2)] + [(['.'] + list(input()) + ['.']) for _ in range(H)] + [['.']*(W+2)]
dxy = ((0, -1), (0, 1), (-1, 0), (1, 0))

for i, j in product(range(1, H+1), range(1, W+1)):
    if maps[i][j] == '
        for k, l in dxy:
            if maps[i+k][j+l] == '
                break
        else:
            print("No")
            exit()

print("Yes")

Solution (Python):
H, W = map(int, input().split())
s = [input() for i 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
        else:
            check = True
            for k in range(len(dx)):
                y = i+dy[k]
                x = j+dx[k]
                if x<0 or x>(W-1) or y<0 or y>(H-1):
                    continue
                else:
                    if s[y][x]=='
                        check = False
            if check:
                ans = False
                break
    if not ans:
        break

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

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

for y in range(H):
    for x in range(W):
        if f[y][x] == '
            flag = 0
            for dy, dx in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
                ny, nx = y + dy, x + dx
                if 0 <= nx < W and 0 <= ny < H:
                    if f[ny][nx] == '
                        flag = 1
            if flag == 0:
                print('No')
                exit()
print('Yes')

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

for y in range(H):
    for x in range(W):
        if field[y][x] == '
            flag = False
            for dy, dx in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
                ny, nx = y + dy, x + dx
                if 0 <= nx < W and 0 <= ny < H:
                    if field[ny][nx] == '
                        flag = True
                else:
                    continue
            if flag is False:
                print('No')
                exit()
print('Yes')

Solution (Python):
h,w=map(int,input().split());a=[input()for i in range(h)]
def che(i,j):
  global h,w,a
  if i==0:
    if a[i+1][j]=="
  elif i==h-1:
    if a[i-1][j]=="
  else:
    if a[i-1][j]=="
  print("No");exit()
for i in range(h):
  s=a[i]
  if s[:2]=="
  if s[-2:]==".
  for j in range(w-2):
    if s[j]+s[j+1]+s[j+2]==".
print("Yes")

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

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

S.append(list('@'*(W+2)))
for i in range(H):
  s = list(input())
  s.insert(0,'@')
  s.append('@')
  S.append(s)
S.append(list('@'*(W+2)))

judge = 1 
count = 0
vy = [0,0,1,-1]
vx = [1,-1,0,0]
for i in range(H+2):
  if(count == 4): break  
  if((i != 0)and(i != H+1)):    
   for j in range(W+2):
    if(count == 4): break  
    if((j != 0)and(j != W+1)):
      if(S[i][j] == '
        count = 0
        for k in range(4):
          if(S[i+vy[k]][j+vx[k]] == '
          count += 1
        if(count == 4):
          judge = 0
          break

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

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

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

    for y in range(H):
        for x in range(W):
            flag = True
            if G[y][x] == ".":
                continue

            flag = False

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

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

                if G[ny][nx] == "
                    flag = True
                    break

            if not flag:
                print("No")
                return

    print("Yes")

main()

Solution (Python):


h,w = map(int,input().split())
s = [0]*(h+2)
s[0]= ["."]*(w+2)
for i in range(h):
    s[i+1] = ["."] + list(input()) + ["."]

ans = True
for i in range(1,h):
    for j in range(1,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] == ".":
                ans = False
                break

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

Solution (Python):
H,W=map(int,input().split())
S=["."*(W+2)]
for i in range(H):
  S.append("."+input()+".")
S.append("."*(W+2))
print("Yes" if all(S[i][j]=="." or (S[i+1][j]=="

Solution (Python):



import sys



H, W = map(int, input().rstrip().split(' '))
field = [[0] * W for _ in range(H)]

for i in range(H):
    for j, c in enumerate(input()):
        if c == '
            field[i][j] = 1
       
for h in range(H):
    for w in range(W):
        if field[h][w] == 1:
            if h + 1 < H:
                if field[h + 1][w] == 1:
                    continue
            if h - 1 >= 0:
                if field[h - 1][w] == 1:
                    continue
            if w + 1 < W:
                if field[h][w + 1] == 1:
                    continue
            if w - 1 >= 0:
                if field[h][w - 1] == 1:
                    continue
                    
            print('No')
            sys.exit()
            
print('Yes')

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

l = [['P' for _ in range(W + 2)] for _ in range(H + 2)]

for i in range(H) :
    s = list(input())
    for j in range(W) :
        l[i+1][j+1] = s[j]

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

ans = True

for i in range(1, H + 1) :
    for j in range(1, W + 1) :
        if l[i][j] != "
            continue
        flag = False
        for k in range(len(dx)) :
            if l[i + dx[k]][j + dy[k]] == "
                flag = True
                break
        if flag == False :
            ans = False

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

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

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]
for h in range(H):
    for w in range(W):
        if S[h][w] == '
            for i in range(4):
                nh, nw = h+dx[i], w+dy[i]
                if 0 <= nh < H and 0 <= nw < W:
                    if S[nh][nw] == '
                        S[nh][nw] = 'b'
                        S[h][w] = 'b'

counter = 0
for i in range(H):
    for l in range(W):
        if S[i][l] == "
            counter += 1


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

Solution (Python):
H, W = map(int, input().split())
S = [['.' for _ in range(W+2)]]+[['.'] + list(input())+ ['.'] for _ in range(H)]+[['.' for _ in range(W+2)]]
S
Flag = True
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] == '.':
            Flag = False
if Flag:
    print('Yes')
else:
    print('No')

Solution (Python):
import sys
H, W = map(int, input().split())
s = ['.'*(W+2)]
for i in range(H):
    s.append('.' + input() + '.')
s.append('.'*(W+2))
for i, x in enumerate(s):
    for j, y in enumerate(x):
        if s[i][j] == '
            if s[i+1][j] == '
                continue
            else:
                print('No')
                sys.exit()
print('Yes')

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

def canPaint(h,w):
  if '
    return True
  else:
    return False

for h in range(1, H+1):
  for w in range(1, W+1):
    if S[h][w]=='
      print('No')
      exit()
else:
  print('Yes')

Solution (Python):
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')



H, W = 0, 0
S = []


def set_inputs():
    global H, W, S
    H, W = get_li()
    for _ in range(H):
        row = get_lc()
        S.append(row)
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    
    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 < W - 1 and S[i+1][j] == "
                continue
            if j > 0 and S[i][j-1] == "
                continue
            if j < H - 1 and S[i][j+1] == "
                continue
            print("No")
            return
    print("Yes")
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()

Solution (Python):
import sys
 
a = list(map(int,input().split()))
H = a[0]
W = a[1]
board = [["d" for j in range(W+2)] for i in range(H+2)]
for i in range(H):
    temp = input()
    for j in range(W):
        board[i+1][j+1] = temp[j]
 
 
for i in range(1, H+1):
    for j in range(1, W+1):
        if board[i][j] == "
            print("No")
            sys.exit()
print("Yes")

Solution (Python):
h,w =map(int,input().split())
D = [[0]*(w+2) for _ in range(h+2)]
for _ in range(1,h+1):
    for inp,i in zip(input(),range(1,w+1)):
        if inp == ".":
            D[_][i] = 0
        else:
            D[_][i] = 1
Ans = True
for i in range(1,h+1):
    for j in range(1,w+1):
        if D[i][j] == 1:
            if D[i+1][j]+D[i-1][j]+D[i][j+1]+D[i][j-1] == 0:
                Ans = False
    if not(Ans):
        break
if Ans:
    print("Yes")
else:
    print("No")

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

def check(h, w):
    b1 = False
    b2 = False
    b3 = False
    b4 = False
    if h > 0:
        b1 = Sh[h-1][w] == '
    if w > 0:
        b2 = Sh[h][w-1] == '
    if h < H-1:
        b3 = Sh[h+1][w] == '
    if w < W-1:
        b4 = Sh[h][w+1] == '
    return b1 or b2 or b3 or b4

for h in range(H):
    for w in range(W):
        if Sh[h][w] == '
            if not check(h, w):
                print("No")
                break
    else:
        continue
    break
else:
    print("Yes")

Solution (Python):
h,w=map(int, input().split())
lst = [input() for i in range(h)] 
for i in range(h):
  for j in range(w): 
    if(lst[i][j]=="
      u=1
      l=1
      r=1
      d=1
      if(i==0):
        u=0
      if(i==h-1):
        d=0
      if(j==0):
        l=0
      if(j==w-1):
        r=0
      if not(lst[i-u][j]=="
         lst[i][j-l]=="
        print("No")
        quit()
else:
    print("Yes")

Solution (Python):
h, w = map(int, input().split())
pict = [[0]*(w+2) for _ in range(h+2)]

for y in range(1, h+1):
    pict[y][1:w+1] = list(input())
ans = "Yes"
for y in range(h):
    for x in range(w):
        if pict[y][x] == "
            if pict[y-1][x] == "." and pict[y+1][x] == "." and pict[y][x-1] == "." and pict[y][x+1] == ".":
                ans = "No"
print(ans)

Solution (Python):
def makegrid(target=False):
    H,W = map(int,input().split())
    S = [["" for i in range(W+2)]for j in range(H+2)]
    target_xy = []
    for y in range(H):
        line = input()
        for x in range(W):
            S[y+1][x+1] = line[x]
            if line[x] == target:
                target_xy.append([y+1,x+1])
    return H,W,S,target_xy

def getvalue_9(S,y,x): 
    around9 = [None for i in range(9)]      
    idx = 0 
    for h in range(-1,2):
        for w in range(-1,2):
            around9[idx] = S[y+h][x+w]
            idx +=1
    return around9

def getvalue_4(S,y,x):
    around4 = [S[y+1][x],S[y][x-1],S[y][x+1],S[y-1][x]]
    return around4

H,W,S,targets_xy = makegrid(target="
ans = "Yes"
for xy in targets_xy:
    around4 = getvalue_4(S,xy[0],xy[1])
    if not ("
        ans = "No"

print(ans)

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):
    for k in range(1, W):
        if S[i][k] == '
            print('No')
            exit()
print('Yes')

Solution (Python):
H, W = map(int, input().split())
s = ["".join(["0"]*(W+2))] + ["0"+input()+"0" for _ in range(H)] + ["".join(["0"]*(W+2))]
failed = False
for i in range(1, H+1):
    for j in range(1, W+1):
        if '
            continue
        if '
            continue
        else:
            failed = True
            break
    if failed:
        print("No")
        break
else:
    print("Yes")

Solution (Python):
H,W=map(int,input().split(' '))
F=[input() for i in range(H)]
ans='Yes'
for y in range(H):
    for x in range(W):
        if ans=='No':
            break
        else:
            a = F[y][x]=='
            b = x==0 or (x>0 and F[y][x-1]=='.')
            c = x==W-1 or (x<W-1 and F[y][x+1]=='.')
            d = y==0 or (y>0 and F[y-1][x]=='.')
            e = y==H-1 or (y<H-1 and F[y+1][x]=='.')
            if a and b and c and d and e:
                ans='No'
print(ans)

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

Solution (Python):
h, w = [int(item) for item in input().split()]
shw = ["." * (w+2)] + ["." + input() + "." for _ in range(h)] + ["." * (w+2)]

ans = True
for i in range(1,w+1):
  for j in range(1,h+1):
    if shw[j][i] == ".":
      continue
    if shw[j][i+1] == "." and shw[j][i-1] == "." and shw[j+1][i] == "." and shw[j-1][i] == ".":
      ans = False
      break

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

Solution (Python):
def isDraw(s, H, W):
    for h in range(H):
        for w in range(W):
            if s[h][w] != "
                continue
            if h > 0 and s[h-1][w] == "
                continue
            if h < H-1 and s[h+1][w] == "
                continue
            if w > 0 and s[h][w-1] == "
                continue
            if w < W-1 and s[h][w+1] == "
                continue
            return "No"
    return "Yes"

H, W = map(int, input().split())
s = []

for i in range(H):
    s.append(input())

print(isDraw(s, H, W))

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

if s[0][0] == "
    
    if not (s[0][1] == "
        print("No")
        exit()

for j in range(1, W-1):
    if s[0][j] == "
     
        if not (s[1][j] == "
            print("No")
            exit()

if s[0][-1] == "
    
    if not (s[0][-2] == "
        print("No")
        exit()

for i in range(1, H-1):
    if s[i][0] == "
     
        if not (s[i][1] == "
            print("No")
            exit()

for i in range(1, H-1):
    if s[i][-1] == "
     
        if not (s[i][-2] == "
            print("No")
            exit()

if s[-1][0] == "
    
    if not (s[-1][1] == "
        print("No")
        exit()

for j in range(1, W-1):
    if s[-1][j] == "
     
        if not (s[-2][j] == "
            print("No")
            exit()

if s[-1][-1] == "
    
    if not (s[-1][-2] == "
        print("No")
        exit()

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

Solution (Python):
H, W = map(int, 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] == '
            print('No')
            exit()
print('Yes')

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

S =[list(input()) for i in range(H)]
dy = [-1, 0, 1, 0]
dx = [0, 1, 0, -1]

for y in range(H):
    for x in range(W):
        if S[y][x] == "
            count = 0
            err_count = 0
            for i in range(4):
                    if not (0 <= y + dy[i] < H) or not(0 <= x + dx[i] < W):
                        err_count += 1
                        continue
                    else:
                        if S[y + dy[i]][x + dx[i]] == ".":
                            count += 1
            if count + err_count== 4:
                print("No")
                sys.exit()

print("Yes")

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

S =[list(input()) for i in range(H)]
dy = [-1, 0, 1, 0]
dx = [0, 1, 0, -1]

for y in range(H):
    for x in range(W):
        if S[y][x] == "
            count = 0
            for i in range(4):
                    if not (0 <= y + dy[i] < H) or not(0 <= x + dx[i] < W):
                        continue
                    else:
                        if S[y + dy[i]][x + dx[i]] == ".":
                            count += 1
            if count == 4:
                print("No")
                sys.exit()

print("Yes")