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):
import sys
input = sys.stdin.readline

H, W = [int(x) for x in input().strip().split()]
S = [list(input().strip()) for _ in range(H)]
C = [['.'] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == '
            for i2, j2 in zip([1, 0, -1, 0],[0, 1, 0, -1]):
                if i+i2 < 0 or i+i2 >= H or j+j2 < 0 or j+j2 >= W:
                    continue
                if S[i+i2][j+j2] == '
                    C[i][j] = C[i+i2][j+j2] = '
                    break
            else:
                print('No')
                exit()

print('Yes')

Solution (Python):
H, W = list(map(lambda x: int(x), input().split(' ')))
table = [[c for c in input()] for _ in range(H)]

for i in range(H):
    for j in range(W):
        if table[i][j] == '
            if i > 0 and table[i-1][j] == '
                continue

            elif i < H-1 and table[i+1][j] == '
                continue

            elif j > 0 and table[i][j-1] == '
                continue

            elif j < W-1 and table[i][j+1] == '
                continue

            else:
                print('No')
                exit()

print('Yes')

Solution (Python):
H,W=map(int,input().split())
L=[["."]+list(input())+["."] for _ in range(H)]
l=[["." for i in range(W+2)]]
L=l+L+l
A=[-1,1,0,0]
B=[0,0,-1,1]
n=True
for i in range(1,H+1):
  for j in range(1,W+1):
    if L[i][j]=="
      if all(L[i+A[k]][j+B[k]]!="
        n=False
        break
  else:
    continue
  break
if n:
  print("Yes")
else:
  print("No")

Solution (Python):


import sys










def main():
    h, w = (int(x) for x in sys.stdin.readline().split())
    canvas = ['.' * (w + 2)]
    for i in range(h):
        line = '.' + sys.stdin.readline().rstrip() + '.'
        canvas.append(line)
    canvas.append('.' * (w + 2))
    for i in range(1, h+1):
        for j in range(1, w+1):
            if canvas[i][j] == '.':
                continue
            else:
                if canvas[i-1][j] == '
                    continue
                else:
                    print('No')
                    exit()
    print('Yes')


if __name__ == "__main__":
    
    main()

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

Solution (Python):
h, w = map(int,input().split())
s = []
for i in range(h):s.append(list(input()))
dx = [-1, 0, 1, 0]
dy = [0, 1, 0,-1]
for i in range(h):
    for j in range(w):
        if s[i][j] == "
            flag=False
            for k in range(4):
                x = j+dx[k];y=i+dy[k]
                if 0 <= x and x <= w-1 and 0 <= y and y <= h-1:
                    if s[y][x]=="
            if not flag:
                print('No')
                exit()
print('Yes')

Solution (Python):
from sys import exit
H, W = map(int, input().split())
slist = [["."] * (W + 2), ]
for _ in range(H):
    line = list(input())
    line.insert(0, ".")
    line.append(".")
    slist.append(line)
slist.append(["."] * (W + 2))
points = ((0, -1), (0, 1), (-1, 0), (1, 0))
flg = True
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if slist[i][j] == "
            counter = 0
            for x, y in points:
                if slist[i - x][j - y] == "
                    counter += 1
                    break
            else:
                print("No")
                exit()
print("Yes")

Solution (Python):
def dfs(grid, start, wall, w, h):
    dxy = [(0,1), (0,-1), (1,0), (-1,0)]
    for i in range(1,h+1):
        for j in range(1,w+1):
            if grid[i][j] == '.':
                continue
            if sum([grid[i+dy][j+dx] == wall  for dx,dy in dxy]) == 0:
                return False
    return True

h,w = map(int, input().split())
wall = '.'
edges = [wall] * (w+2)
grid = [edges]
for i in range(h):
    s = input()
    grid.append([wall] + list(s) + [wall])
grid.append(edges)
print('Yes' if dfs(grid, [0,0], '

Solution (Python):
import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7

    h, w = list(map(int, input().rstrip('\n').split()))
    s = [list(str(input().rstrip('\n'))) for _ in range(h)]
    ql = []
    ql = collections.deque(ql)
    for i in range(h):
        for j in range(w):
            if s[i][j] == "
                ql.append([0, i, j])
    while True:
        if len(ql) != 0:
            b = False
            cost, xv, yv = ql.popleft()
            for xv, yv in [[xv + 1, yv], [xv - 1, yv], [xv, yv + 1], [xv, yv - 1]]:
                if 0 <= xv < h and 0 <= yv < w:
                    if s[xv][yv] == "
                        b = True
                        break
            if not b:
                print("No")
                exit()
        else:
            break
    print("Yes")


if __name__ == '__main__':
    solve()

Solution (Python):
h,w=map(int,input().split())
s=[]
for i in range(h):s.append(list(input()))
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]
for i in range(h):
  for j in range(w):
    if s[i][j]=='
      flag=False
      for k in range(4):
        x = j+dx[k];y=i+dy[k]
        if 0 <= x and x <= w-1 and 0 <= y and y <= h-1:
          if s[y][x]=="
      if not flag:
        print('No')
        exit()
 
print('Yes')

Solution (Python):


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

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

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

for i in range(h):
  for j in range(w):
    if grid[i][j]=='
      isFillable = False
      for k in range(4):
        x = j + dx[k]
        y = i + dy[k]
        if 0 <= x and x <= w-1 and 0 <= y and y <= h-1:
          if grid[y][x] == "
            isFillable = True
      if not isFillable:
        print('No')
        exit()

print('Yes')

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

d = {(i, j):c for i, row in enumerate(s) for j, c in enumerate(row)}

def next_to_black(i, j):
    directions = ((-1, 0), (1, 0), (0, -1), (0, 1))
    surroundings = ((i + a, j + b) for a, b in directions)
    colors = (d.get(cell, '.') for cell in surroundings)
    return any(color == "

black_coords = (coord for coord, c in d.items() if c == "
paintable = all(next_to_black(*coord) for coord in black_coords)
print("Yes" if paintable else "No")

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

ans = 1
for h in range(H):
    for w in range(W):
        if campus[h][w] == '
            check = 0
            if h != 0:
                if campus[h-1][w] == '
                    check = 1
            if w != 0:
                if campus[h][w-1] == '
                    check = 1
            if h != H-1:
                if campus[h+1][w] == '
                    check = 1
            if w != W-1:
                if campus[h][w+1] == '
                    check =1
            if check == 0:
                ans = 0
                break

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

Solution (Python):
import numpy as np
h, w = map(int, input().rstrip("\n").split())

array = np.array([[" "] * (w + 2)] + [list(" " + input().rstrip("\n") + " ") for _ in range(h)] + [[" "] * (w + 2)])

def solve():
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if array[i][j] == "
                if "
                    continue
                else:
                    return "No"
    return "Yes"

print(solve())

Solution (Python):
def DFS(x,y): 
    global h,w,maze,log
    if not (x<0 or h<=x or y<0 or w<=y):
        if (y!=0 and maze[x][y-1]=="
            log[x][y]=1
    

def main():
    n,m = map(int,input().split())
    global h,w,maze,log
    maze=[]
    for _ in range(n):
        maze.append(list(input()))
    log = [[0 for _ in range(m)] for _ in range(n)]
    for i in range(n):
        for j in range(m):
            if maze[i][j]==".":
                log[i][j]=1
    h=n
    w=m
    for i in range(n):
        for j in range(m):
            if log[i][j]==0:
                DFS(i,j)
    for i in range(n):
        for j in range(m):
            if log[i][j]==0:
                print("No")
                return
    print("Yes")
    
main()

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

ans = 'Yes'
break_flg = False

for h_i in range(h):
  if break_flg:
    break
  for w_i in range(w):
    check_str = target[h_i][w_i]
    if check_str == '
      left = target[h_i][w_i-1] if w_i-1>=0 else '.'
      right = target[h_i][w_i+1] if w_i+1<w else '.'
      top = target[h_i-1][w_i] if h_i-1>=0 else '.'
      bottom = target[h_i+1][w_i] if h_i+1<h else '.'
      
      if left==right==top==bottom=='.':
        ans = 'No'
        break_flg = True
        break
        
print(ans)

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

g = ["." + input() + "." for _ in range(H)]
g = ["." * (W + 2)] + g + ["." * (W + 2)]

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

Solution (Python):
n,m=map(int,input().split())
mat=[]
dx=[0,0,-1,1]
dy=[1,-1,0,0]
for i in range(n):
    mat.append(list(input().strip()))
f=0 
for i in range(n):
    for j in range(m):
        if mat[i][j]=='
            f=0 
            for k in range(4): 
                if 0<=i+dx[k]<n and 0<=j+dy[k]<m and mat[i+dx[k]][j+dy[k]]=='
                    f=1  
            if not f:
                print('No')
                exit()
print('Yes')

Solution (Python):
h, w = map(int, input().split())
able = True
tonari = [(-1, 0), (0, -1), (1, 0), (0, 1)]
s = []
for _ in range(h):
    s.append(input())
for i in range(h):
    for j in range(w):
        if s[i][j] == '
            count = 0
            for tx, ty in tonari:
                y = i + ty
                x = j + tx
                if 0 <= y < h and 0 <= x < w:
                    if s[y][x] == '
                        count += 1
            if count == 0:
                able = False
                break

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

Solution (Python):
import numpy as np

H, W = map(int, input().split())
G = np.zeros((H+2, W+2))

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

check = True

for i in range(H):
    for j in range(W):
        if G[i+1, j+1] == 0:
            continue

        up    = G[i  , j+1]
        right = G[i+1, j+2]
        down  = G[i+2, j+1]
        left  = G[i+1, j]
        if up + right + down + left == 0:
            check = False
            break

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

Solution (Python):
H, W = map(int, input().split())
cam = [input() for i in range(H)]
ans = 'Yes'
for i in range(1, H-1):
	for j in range(1, W-1):
		if cam[i][j] == "
			if cam[i-1][j] == cam[i+1][j] == cam[i][j-1] == cam[i][j+1] == ".":
				ans = 'No'
				break
print(ans)

Solution (Python):
import sys
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]=="
            count=0
            if i>0:
                if s[i-1][j]=="
                    count+=1
            if i<h-1:
                if s[i+1][j]=="
                    count+=1
            if j>0:
                if s[i][j-1]=="
                    count+=1
            if j<w-1:
                if s[i][j+1]=="
                    count+=1
            if count==0:
                break
    else:
        continue
    break
else:
    print("Yes")
    sys.exit()
print("No")

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


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

for i in range(h):
    for j in range(w):
        canPaint = 0
        if s[i][j] == '
            if i >= 1 and s[i - 1][j] == '
                canPaint = 1
            if j >= 1 and s[i][j - 1] == '
                canPaint = 1
            if j <= w - 2 and s[i][j + 1] == '
                canPaint = 1
            if i <= h - 2 and s[i + 1][j] == '
                canPaint = 1
            if not canPaint:
                print('No')
                quit()

print('Yes')

Solution (Python):
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    h, w = map(int, input().split())
    
    ss = ['.' * (w + 2)] + ['.' + input() + '.' for _ in range(h)] + ['.' * (w + 2)]

    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if ss[i][j] == '
                if ss[i + 1][j] == '.' and ss[i - 1][j] == '.' and ss[i][j + 1] == '.' and ss[i][j - 1] == '.':
                    print("No")
                    break
        else:
            continue
        break
    else:
        print("Yes")



if __name__ == '__main__':
    main()

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

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

Solution (Python):
H,W=map(int,input().split())
a=[[False for j in range(W+2)] for i in range(H+2)]

for i in range(1,H+1):
    si=input()
    for j in range(1,W+1):
        a[i][j]=si[j-1]=='

f=True
fEND=False
for i in range(1,H+1):
    if fEND:
        break
    for j in range(1,W+1):
        if a[i][j] and not (a[i-1][j] or a[i+1][j] or a[i][j-1] or a[i][j+1]):
            f=False
            fEND=True
            break

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

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

shift = [[1,0],[-1,0],[0,-1],[0,1]]

flag = True
for j in range(H):
    for i in range(W):
        if s[j][i] == ".":
            continue
        else:
            flag = False
            for dx,dy in shift:
                nx = i + dx
                ny = j + dy
                
                if nx >= 0 and nx < W and ny >= 0 and ny < H:
                    if s[ny][nx] == "
                        flag = True
            if not flag:
                print("No")
                exit(0)

print("Yes")

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

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

Solution (Python):
import sys
h, w = map(int, input().split())
sq = []

for i in range(h):
    sq.append(input())

def is_valid(i, j):

    valid = False
    if i > 0 and sq[i-1][j] == '
        valid = True
    elif i < h-1 and sq[i+1][j] == '
        valid = True
    elif j > 0 and sq[i][j-1] == '
        valid = True
    elif j < w-1 and sq[i][j+1] == '
        valid = True
    return valid

for i in range(h):
    for j in range(w):
        c = sq[i][j]
        if c == '
            if not is_valid(i, j):
                print('No')
                sys.exit()

print('Yes')

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

dis=[[-1,0],[1,0],[0,-1],[0,1]]

for i in range(H):
    for j in range(W):
        if s[i][j]=='
            isfound=False
            for k in dis:
                if  0<=i+k[0]<H and 0<=j+k[1]<W:
                    if s[i+k[0]][j+k[1]]=='
                        isfound=True
                else:
                    continue

            if not isfound:
                print("No")
                exit()

print("Yes")

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

dis=[[-1,0],[1,0],[0,-1],[0,1]]

for i in range(H):
    for j in range(W):
        if s[i][j]=='
            isfound=False
            for k in dis:
                if  0<=i+k[0]<H and 0<=j+k[1]<W:
                    if s[i+k[0]][j+k[1]]=='
                        isfound=True


            if not isfound:
                print("No")
                exit()

print("Yes")

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

    mv = [[1,0],[-1,0],[0, 1],[0, -1]]
    for i in range(H):
        for j in range(W):
            if s[i][j] == "
                isfound = False
                for di, dj in mv:
                    i1, j1 = i+di, j+dj
                    if 0<=i1<H and 0<=j1<W and s[i1][j1] == "
                        isfound = True
                        break
                if not isfound: return "No"
    return "Yes"


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

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

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

for i in range(H):
    s = input()
    b.append('.' + s + '.')

b.append('.' * (W + 2))

r = True

for i in range(1, H + 1):
    for j in range(1, W + 1):
        if b[i][j] == '
            
            if b[i][j-1] == '
                pass
            elif b[i][j+1] == '
                pass
            elif b[i-1][j] == '
                pass
            elif b[i+1][j] == '
                pass
            else:
                r = False

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

Solution (Python):
H,W=map(int,input().split())
S=[input() for i in range(H)]
ans=1
for i in range(H):
  for j in range(W):
    if(S[i][j]=='
      if(i==0 and j==0):
        if(S[i+1][j]=='.' and S[i][j+1]=='.'):
          ans=0
      elif(i==0 and j==W-1):
        if(S[i+1][j]=='.' and S[i][j-1]=='.'):
          ans=0
      elif(i==0):
        if(S[i+1][j]=='.' and S[i][j+1]=='.' and S[i][j-1]=='.'):
          ans=0
      elif(i==H-1 and j==0):
        if(S[i-1][j]=='.' and S[i][j+1]=='.'):
          ans=0
      elif(i==H-1 and j==W-1):
        if(S[i-1][j]=='.' and S[i][j-1]=='.'):
          ans=0
      elif(i==H-1):
        if(S[i][j+1]=='.' and S[i-1][j]=='.' and S[i][j-1]=='.'):
          ans=0
      elif(j==0):
        if(S[i+1][j]=='.' and S[i][j+1]=='.' and S[i-1][j]=='.'):
          ans=0
      elif(j==W-1):
        if(S[i+1][j]=='.' and S[i-1][j]=='.' and S[i][j-1]=='.'):
          ans=0
      else:
        if(S[i+1][j]=='.' and S[i][j+1]=='.' and S[i-1][j]=='.' and S[i][j-1]=='.'):
            ans=0
if(ans):
  print("Yes")
else:
  print("No")

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

for i in range(h):
    for j in range(w):
        flag = True
        if S[i][j] == '
            for di, dj in zip([-1, 0, 1, 0], [0, -1, 0, 1]):
                if 0 <= i+di < h and 0 <= j+dj < w and S[i+di][j+dj] == '
                    flag = False
                    break
        else:
            flag = False
        if flag:
            break
    if flag:
        break

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

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

      if not any(b):
        print("No")
        sys.exit()

print("Yes")

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

for i in range(w):
    for j in range(h):
        if s[j][i] == '
            if j + 1 < h and s[j+1][i] == '
                continue
            if j - 1 >= 0 and s[j-1][i] == '
                continue
            if i + 1 < w and s[j][i+1] == '
                continue
            if i - 1 >= 0 and s[j][i-1] == '
                continue
            print('No')
            exit()

print('Yes')

Solution (Python):
from collections import deque
H,W = map(int, input().split())
m = [input() for _ in range(H)]
visited=[[0]*W for _ in range(H)]
dhw = [(1,0),(-1,0),(0,1),(0,-1)]
def main():
  global visited
  for h in range(H):
    for w in range(W):
      if m[h][w]==".":
        continue
      for dh, dw in dhw:
        nh, nw = h+dh, w+dw
        if 0<=nh<H and 0<=nw<W:
          if m[nh][nw]=="
            break
      else:
        print("No")
        return
  print("Yes")
  return

if __name__ == "__main__":
  main()

Solution (Python):
h, w = map(int, input().split())
ans = "Yes"
c = ["0"]*(w+2)
s = []
s.append(c)
for i in range(h):
    S = ["0"]
    S1 = list(input())
    S1.append("0")
    S = S+S1
    s.append(S)
s.append(c)

for i in range(1,h+1):
    for j in range(1, w+1):
        if s[i][j]=="
            if s[i-1][j]!="
                ans ="No"
            else:
                continue
print(ans)

Solution (Python):
h,w = map(int,input().split())
graph = [input() for _ in range(h)]
y = [ 0, 0, 1,-1]
x = [-1, 1, 0, 0]
for i in range(h):
    for j in range(w):
        if graph[i][j] == "
            for k in range(4):
                nh = i + y[k]
                nw = j + x[k]
                if nh < 0 or nh >= h or nw < 0 or nw >= w:continue
                if graph[nh][nw] == "
            else:print("No");exit()
print("Yes")

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

for h in range(1, H):
    for w in range(1, W):
        if s[h][w] == '
            if h != 0 and w != 0 and h != H - 1 and w != W - 1:
                if s[h - 1][w] != '
                    print('No')
                    exit()
print('Yes')

Solution (Python):
import sys

H,W = 0,0
Data = []

def check(x,y):
    if x > 0:
        if Data[y][x-1] == '
            return True
    if x < W-1:
        if Data[y][x+1] == '
            return True
    if y > 0:
        if Data[y-1][x] == '
            return True
    if y < H-1:
        if Data[y+1][x] == '
            return True
    return False 

H,W = map(int,input().split())
for _ in range(H):
    data = list(input())
    Data.append(data)

for y in range(H):
    for x in range(W):
        c = Data[y][x]
        if c == '
            if check(x,y) == False:
                print('No')
                sys.exit()
print('Yes')

Solution (Python):
h,w=map(int,input().split())
l=[list(map(str, input())) for i in range(h)]
for i in range(h):
    l[i]=['.']+l[i]+['.']
l=[['.']*(w+2)]+l+[['.']*(w+2)]
for i in range(1,h+1):
    for j in range(1,w+1):
        if l[i][j]=='
            print('No')
            break
    else:
        continue
    break
else:
    print('Yes')

Solution (Python):

H, W = map(int, input().split())
S = [input()  for i in range(H)]
ans = "Yes"

if S[0][0] == "
    if S[0][1] == S[1][0] == ".":
        ans = "No"
if S[0][W-1] == "
    if S[0][W-2] == S[1][W-1] == ".":
        ans = "No"
if S[H-1][0] == "
    if S[H-2][0] == S[H-1][1] == ".":
        ans = "No"
if S[H-1][W-1] == "
    if S[H-2][W-1] == S[H-1][W-2] == ".":
        ans = "No"


for w in range(1, W-1):
    if S[0][w] == "
        if S[0][w-1] == S[0][w+1] == S[1][w] == ".":
            ans = "No"
    if S[H-1][w] == "
        if S[H-1][w-1] == S[H-1][w+1] == S[H-2][w] == ".":
            ans = "No"


for h in range(1, H-1):
    if S[h][0] == "
        if S[h-1][0] == S[h][1] == S[h+1][0] == ".":
            ans = "No"
    if S[h][W-1] == "
        if S[h-1][W-1] == S[h][W-2] == S[h+1][W-1] == ".":
            ans = "No"


for h in range(1, H-1):
    for w in range(1, W-1):
        if S[h][w] == "
            if S[h-1][w] == S[h][w-1] == S[h][w+1] == S[h+1][w] == ".":
                ans = "No"

print(ans)

Solution (Python):
H,W=map(int,input().split())
S=["."+input()+"." for i in range(H)]
S=["."*(W+2)]+S+["."*(W+2)]
flag=0
for i in range(H):
    for j in range(W):
        if S[i][j]=="
            if S[i-1][j]=="." and S[i+1][j]=="." and S[i][j-1]=="." and S[i][j+1]==".":
                flag=1
print("Yes" if flag==0 else "No")

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

Solution (Python):
h, w = map(int, input().split())
s = [list(map(str, input())) for i in range(h)]
isCase = True
count = 1

def isBlack(i, j, h, w):
    if ((i-1>0 and s[max(i-1,0)][j] == 'B') or (j-1>0 and s[i][max(j-1,0)] == 'B') or (j+1<w-1 and s[i][min(j+1,w-1)] == 'B') or (i+1<h-1 and s[min(i+1,h-1)][j] == 'B')):
        return True
    else:
        return False

while (count != 0 and isCase):
    count = 0
    for i in range(h):
        for j in range(w):
            if (s[i][j] == '
                s[i][j] = 'B'
                count += 1
                if (s[max(i-1,0)][j] == '
                    s[max(i-1,0)][j] = 'B'
                elif (s[i][max(j-1,0)] == '
                    s[i][max(j-1,0)] = 'B'
                elif (s[i][min(j+1,w-1)] == '
                    s[i][min(j+1,w-1)] = 'B'
                elif (s[min(i+1,h-1)][j] == '
                    s[min(i+1,h-1)][j] = "B"
                elif (isBlack(i, j, h ,w)):
                    pass
                else:
                    isCase = False
                    break
        if (isCase == False):
            break

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

Solution (Python):
H, W = map(int, input().split())
tmp = '.' * (W + 2)
matrix = [tmp] * (H + 2)
for i in range(1,H+1):
    matrix[i] = '.' + input() + '.'
for i in range(1,H+1):
    for k in range(1,W+1):
        if matrix[i][k] == '.':
            continue
        elif matrix[i][k-1] == '.' and matrix[i][k+1] == '.' and matrix[i-1][k] == '.' and matrix[i+1][k] == '.':
            print('No')
            exit()
print('Yes')

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

for _ in range(h):
    rows.append(input())

for i in range(h):
    for j in range(w):
        if rows[i][j] =='
            judge = 0
            for nh,nw in [(1,0),(-1,0),(0,-1),(0,1)]:
                if (0<=i+nh<=h-1)and(0<=j+nw<=w-1):
                    if rows[i+nh][j+nw] =='
                        judge =1
                        break
            if judge == 0:
                print('No')
                exit()
print('Yes')

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

for i in range(1, H):
    for j in range(1, W):
        if s[i][j] == '
            if i < H - 1 and j < W - 1:
                if '
                    ng += 1
            elif i == H - 1 and j == W - 1:
                if '
                    ng += 1
            elif j == W - 1:
                if '
                    ng += 1
            elif i == H - 1:
                if '
                    ng += 1
    if ng > 0:
        print('No')
        exit()

print('Yes')

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

for i in range(h):
    for k in range(w):
        if s[i][k] == "
            count = True
            d = [[0, 1], [1, 0], [0, -1], [-1, 0]]
            for l in d:
                if 0 <= i + l[0] < h and 0 <= k + l[1] < w:
                    if s[i + l[0]][k + l[1]] == "
                        count = False
                        break

            if count:
                ans = False

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

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

ans = 'Yes'
for hi in range(h):
  for wi in range(w):
    if field[hi][wi] == '
      is_one = True
      for dw,dh in ((-1,0),(0,1),(1,0),(0,-1)):        
        if (0<= hi+dh < h) and (0<= wi+dw < w) :          
          if field[hi][wi] == field[hi+dh][wi+dw]:
            is_one = False      
      if is_one:
        ans ='No'
  
print(ans)

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

for i in range(1, h+1):
    for j in range(1, w+1):
        if m[i][j] == '
            if all(m[i+x][j+y] == '.' for x, y in [(-1, 0), (1, 0), (0, -1), (0, 1)]):
                print('No')
                exit(0)
else:
    print('Yes')

Solution (Python):
def main():
  h,w=map(int,input().split())
  s=["*"*(w+2)]
  for i in range(h):
    s.append("*"+input()+"*")
  s+=["*"*(w+2)]
  a=[[0]*w for _ in range(h)]
  for i in range(h):
    for j in range(w):
      if s[i+1][j+1]!="
        a[i][j]=2
      else:
        a[i][j]=(s[i][j+1]+s[i+1][j:j+3]+s[i+2][j+1]).count("
  for i in a:
    if i.count(1)>0:
      print("No")
      return
  print("Yes")
main()

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

for i in range(h):
    for j in range(w):
        if m[i][j] == '
            cnt = sum([0 <= i-1, i+1 < h, 0 <= j-1, j+1 < w])

            
            if 0 <= i-1:
                if m[i-1][j] != '
                    cnt -= 1

            
            if i+1 < h:
                if m[i+1][j] != '
                    cnt -= 1
            
            if 0 <= j-1:
                if m[i][j-1] != '
                    cnt -= 1

            
            if j+1 < w:
                if m[i][j+1] != '
                    cnt -= 1

            if cnt == 0:
                print('No')
                exit(0)
else:
    print('Yes')