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):
row = list(map(int, input().split()))
s = [input().split() for i in range(row[0])]
for i in range(row[0]):
    s[i] = list(s[i][0])
dx = [0, -1, 1, 0]
dy = [-1, 0, 0, 1]
Flag = True
for i in range(row[0]):
    for j in range(row[1]):
        if s[i][j] == "
            flag = False
            for d in range(4):
                nx = i + dx[d]
                ny = j + dy[d]
                if 0 <= nx < row[0] and 0<= ny < row[1]:
                    if s[nx][ny] == "
                        flag = True
                        break
            if flag == False:
                Flag = False
                break
    if Flag == False:
        print("No")
        break
if Flag:
    print("Yes")

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

S = []
for i in range(H):
	S.append("." + input() + ".")

S = ["."*(W+2)] + S + ["."*(W+2)]
flag = 1
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 = 0
print("Yes" if flag else "No")

Solution (Python):
H, W = map(int, input().split())
board = []
for i in range(0, H):
	board.append(input())
ans = 'Yes'
for i in range(0, H):
	for j in range(0, W):
		if board[i][j] == '
			flag = True
			for k in range(0, 2):
				nexth = i - 1 + 2*k
				nextw = j - 1 + 2*k
				if 0 <= nexth and nexth < H:
					if board[nexth][j] == '
						flag = False
						break
				if 0 <= nextw and nextw < W:
					if board[i][nextw] == '
						flag = False
						break
			if flag:
				ans = 'No'
				break
	if ans == 'No':
		break
print(ans)

Solution (Python):
def f(i, S, H, W):
    indices = [i - W, i - 1, i + 1, i + W]
    indices = [i for i in indices if 0 <= i < H * W]
    return any([S[i] == "


H, W = map(int, input().split())
S = ""
for _ in range(H):
    S += input()
for i in range(H * W):
    if S[i] == "
        if not f(i, S, H, W):
            print("No")
            break
else:
    print("Yes")

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

for h in range(H):
  for w in range(W):
    if G[h][w] == '.':
      continue
    if h == 0:
      if w == 0:
        right = G[h][w+1]
        down = G[h+1][w]
        if right == '.' and down == '.':
          print('No')
          exit()
      elif w == W-1:
        left = G[h][w-1]
        down = G[h+1][w]
        if left == '.' and down == '.':
          print('No')
          exit()
      else:
        right = G[h][w+1]
        left = G[h][w-1]
        down = G[h+1][w]
        if right == '.' and left == '.' and down == '.':
            print('No')
            exit()
    elif h == H-1:
      if w == 0:
        right = G[h][w+1]
        up = G[h-1][w]
        if right == '.' and up == '.':
          print('No')
          exit()
      elif w == W-1:
        left = G[h][w-1]
        up = G[h-1][w]
        if left == '.' and up == '.':
          print('No')
          exit()
      else:
        right = G[h][w+1]
        left = G[h][w-1]
        up = G[h-1][w]
        if right == '.' and left == '.' and up == '.':
            print('No')
            exit()
    else:
      if w == 0:
        right = G[h][w+1]
        up = G[h-1][w]
        down = G[h+1]
        if right == '.' and up == '.' and down == '.':
          print('No')
          exit()
      elif w == W-1:
        left = G[h][w-1]
        up = G[h+1][w]
        down = G[h-1][w]
        if left == '.' and up == '.' and down=='.' :
          print('No11')
          exit()
      else:
        right = G[h][w+1]
        left = G[h][w-1]
        up = G[h+1][w]
        down = G[h-1][w]
        if right == '.' and left == '.' and up == '.' and down == '.':
            print('No')
            exit()
print('Yes')

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

ans = 0
for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j] == '.':
            continue
        c = 0
        for k in range(4):
            if s[i+d[k][0]][j+d[k][1]] == "
                c += 1
        if c == 0:
            ans = -1

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

Solution (Python):
H, W = map(int,input().split())
S = [input() for i in range(H)]
S = ["."*(W)]+S+["."*(W)]
S = ["."+s+"." for s in S]
ans = True
for h in range(1,H+1):
    if ans == False:
        break
    for w in range(1,W+1):
        if S[h][w]=="
            if not(S[h-1][w]=="
                ans = False
                break
print("Yes" if ans else "No")

Solution (Python):
h,w=map(int,input().split())
a=[0]*(w+2)
m=[a]
ans='Yes'
for i in range(h):
    s=input()
    m.append([0]+[1 if x=='
m.append(a)
for i in range(1,h+1):
    for j in range(1,w+1):
        if m[i][j]==1 and sum(m[i][j-1:j+2],m[i-1][j]+m[i+1][j])==1:
            ans='No'
print(ans)

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

def solve(S):
    for i in range(1,h+1): 
        for j in range(1,w+1): 
            if S[i][j] == "
                if S[i-1][j] == ("
                    S[i][j] == "a"
                else:
                    return False
    return True

if solve(S):
    print("Yes")
else:
    print("No")

Solution (Python):
h,w = map(int, input().split())
S = [["." for i in range(w+2)]]
S += [["."] + list(input()) + ["."] for i in range(h)]
S += [["." for i in range(w+2)]]
ans = False
for i in range(1,h+1): 
    for j in range(1,w+1): 
        if S[i][j] == "
            if S[i-1][j] == ("
                S[i][j] == "a"
            else:
                break
    else:
        continue
    
    print("No")
    break
else:
    print("Yes")

Solution (Python):
h,w = map(int, input().split())
S = [["." for i in range(w+2)]]
S += [["."] + list(input()) + ["."] for i in range(h)]
S += [["." for i in range(w+2)]]
ans = False
for i in range(1,h+1): 
    for j in range(1,w+1): 
        if S[i][j] == "
            if S[i-1][j] == ("
                S[i][j] == "a"
            else:
                break
    else:
        continue
    
    print("No")
    break
else:
    print("Yes")

Solution (Python):
h,w = map(int, input().split())
S = [["." for i in range(w+2)]]
S += [["."] + list(input()) + ["."] for i in range(h)]
S += [["." for i in range(w+2)]]
ans = False
for i in range(1,h+1): 
    for j in range(1,w+1): 
        if S[i][j] == "
            if S[i-1][j] == ("
                S[i][j] == "a"
            else:
                break
    else:
        continue
    
    print("No")
    break
else:
    print("Yes")

Solution (Python):
h,w = map(int, input().split())
S = [["." for i in range(w+2)]]
S += [["."] + list(input()) + ["."] for i in range(h)]
S += [["." for i in range(w+2)]]
ans = False
for i in range(1,h+1): 
    for j in range(1,w+1): 
        if S[i][j] == "
            if S[i-1][j] == ("
                S[i][j] == "a"
            else:
                break
    else:
        continue
    
    print("No")
    break
else:
    print("Yes")

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

dict = (
    (-1, 0),
    (0, -1),
    (0, 1),
    (1, 0),
)
achievable = True

for i in range(h):
    for j in range(w):
        count = 0
        if grid[i][j] == "
            for dy, dx in dict:
                y = i + dy
                x = j + dx
                if y >= 0 and h > y and x >= 0 and w > x:
                    if grid[y][x] == '
                        count += 1
            if count == 0:
                achievable = False

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

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

achievable = True

for i in range(h):
    for j in range(w):
        x = grid[i][j]
        
        if x == '
            count = 0
            if i - 1 >= 0 and grid[i - 1][j] == '
                count += 1
            if i + 1 < h and grid[i + 1][j] == '
                count += 1
            if j - 1 >= 0 and grid[i][j - 1] == '
                count += 1
            if j + 1 < w and grid[i][j + 1] == '
                count += 1
            
            if count == 0:
                achievable = False
                
print('Yes' if achievable else 'No')

Solution (Python):
import sys
H, W = map(int, input().split())
coordinates = [[0]] * (H + 2)
coordinates[0] = ["."] * (W + 2)
coordinates[H + 1] = ["."] * (W + 2)

for i in range(1, H + 1):
    coordinates[i] = ['.'] + [i for i in input()] + ['.']

for j in range(1, H + 1):
    for k in range(1, W + 1):
        if coordinates[j][k] == '
            if coordinates[j - 1][k] == '
                continue
            else:
                print('No')
                sys.exit()
print('Yes')

Solution (Python):
h,w = map(int, input().split())
grid = [list(input()) for i in range(h)]
error = False
for i in range(h):
    for j in range(w):
        if grid[i][j] == "
            if i > 0 and grid[i-1][j] == "B":
                grid[i][j] = "B"
            elif j > 0 and grid[i][j-1] == "B":
                grid[i][j] = "B"
            elif i < h-1 and (grid[i+1][j] == "B" or grid[i+1][j] == "
                grid[i][j] = "B"
                grid[i+1][j] = "B"
            elif j < w-1 and (grid[i][j+1] == "B" or grid[i][j+1] == "
                grid[i][j] = "B"
                grid[i][j+1] = "B"
            else:
                error = True
                break
    if error == True:
        break
if error == True:
    print("No")
else:
    print("Yes")

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

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

print("Yes")

Solution (Python):
H,W=map(int,input().split())
check=[[0 for _ in range(W+2)] for _ in range(H+2)]
canvas=[['.' for _ in range(W+2)] for _ in range(H+2)]
for i in range(H):
    s=list(input())
    for j in range(W):
        canvas[i+1][j+1]=s[j]

for i in range(H):
    for j in range(W):
        if canvas[i+1][j+1]=='
            if canvas[i+1][j]=='
            or canvas[i+1][j+2]=='
            or canvas[i][j+1]=='
            or canvas[i+2][j+1]=='
                check[i+1][j+1]=1
ans='Yes'
for i in range(H):
    for j in range(W):
        if canvas[i+1][j+1]=='
            if check[i+1][j+1]==0:
                ans='No'
                break
            else:
                continue
            break
print(ans)

Solution (Python):
H,W = map(int,input().split())
Pic = [[i=="." for i in input()] for j in range(H)]
ans = "Yes"
for h,row in enumerate(Pic):
    for w,p in enumerate(row):
        if p:continue
        if all([
            h==0 or Pic[h-1][w],
            h==H-1 or Pic[h+1][w],
            w==0 or Pic[h][w-1],
            w==W-1 or Pic[h][w+1]
            ]):ans = "No"
print(ans)

Solution (Python):
def resolve():
	h,w=map(int,input().split())
	s=[input() for i in range(h)]
	kekka='Yes'
	for i in range(h):
		for j in range(w):
			if s[i][j]=='
				ans=0
				if j==0:
					ans+=s[i][1]=='
				elif j==w-1:
					ans+=s[i][-2]=='
				else:
					ans+=s[i][j-1]=='
					ans+=s[i][j+1]=='
					
				if i==0:
					ans+=s[1][j]=='
				elif i==h-1:
					ans+=s[-2][j]=='
				else:
					ans+=s[i-1][j]=='
					ans+=s[i+1][j]=='
				if ans==0:
					kekka='No'
					break
		else:
			continue
		break
	print(kekka)
resolve()

Solution (Python):
import sys
sys.setrecursionlimit(10000)
h, w = map(int, input().split())
cam = [input() for _ in range(h)]
painted = [[False for i in range(w)] for j in range(h)]

def dfs(x, y):
    global cnt
    if x < 0 or y < 0 or x > h-1 or y > w-1:
        return
    elif cam[x][y] == ".":
        return
    elif painted[x][y]:
        return
    cnt += 1
    painted[x][y] = True
    dfs(x-1, y)
    dfs(x, y-1)
    dfs(x+1, y)
    dfs(x, y+1)
    
for i in range(h):
    for j in range(w):
        cnt = 0
        if cam[i][j] == "
            dfs(i, j)
        if cnt == 1:
            painted[i][j] = False
            
flag = False
for i in range(h):
    for j in range(w):
        if cam[i][j] == "
            if not painted[i][j]:
                flag = True
                break
        elif cam[i][j] == ".":
            if painted[i][j]:
                flag = True
                break
    if flag:
        break
if flag:
    print("No")
else:
    print("Yes")

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

lst = ["." + input() + "." for _ in range(h)]
matrix = ["." * (w + 2)] + lst + ["." * (w + 2)]


ans = "Yes"
for i in range(1, h + 1):
    for j in range(1, w + 1):
        center = matrix[i][j]
        up = matrix[i - 1][j]
        down = matrix[i + 1][j]
        left = matrix[i][j - 1]
        right = matrix[i][j + 1]
        if center == "
            ans = "No"
print(ans)

Solution (Python):
h, w = map(int, input().split())
a = [[0 for i in range(w+2)] for j in range(h+2)]
for i in range(1, h+1):
  s = input()
  for j in range(1, w+1):
    if ord(s[j-1]) is 35:
      a[i][j] = 1

for i in range(1, h+1):
  for j in range(1, w+1):
    if a[i][j] is 1:
      if a[i-1][j] is 0 and a[i+1][j] is 0 and a[i][j-1] is 0 and a[i][j+1] is 0:
        print('No')
        exit()
print('Yes')

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

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

ans = "Yes"

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

flg1 = 0
flg2 = 0

for y in range(H) :
    if flg1 : break
    for x in range(W) :
        if flg2 : break
        if L[y][x] == "
            flg3 = 0
        
            for dy,dx in dxy :


                ny = y+dy
                nx = x+dx

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

                if L[ny][nx] == "
                    flg3 = 1
                    break
            
            if not flg3 :
                ans = "No"
                flg1 = 1
                flg2 = 1
                flg3 = 1
                break
print(ans)

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

line_list = []

for i in range(H):
    line = input()
    line_list.append(line)

flag = True
for i in range(len(line_list)):
    for j in range(len(line_list[i])):
        if flag == False:
            break
        if line_list[i][j] == "
            if i == 0:
                if j == 0:
                    if "
                        flag = False
                elif j == W - 1:
                    if "
                        flag = False
                else:
                    if "
                        flag = False
            elif i == H - 1:
                if j == 0:
                    if "
                        flag = False
                elif j == W - 1:
                    if "
                        flag = False
                else:
                    if "
                        flag = False
            else:
                if j == 0:
                    if "
                        flag = False
                elif j == W - 1:
                    if "
                        flag = False
                else:
                    if "
                        flag = False

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

Solution (Python):
h,w=map(int,input().split())
ss=[list(input()) for i in range(h)]
f=True
s=[["."]*(w+2)]
s.extend(ss)
for i in range(1,h+1):
    s[i].insert(0,".")
    s[i].append(".")
s.append(["."]*(w+2))

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

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

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

Solution (Python):
h,w = map(int,input().split())
s=[]
for _ in range(h):
  s.append(str(input()))
for i in range(h):
  for j in range(w):
    flag=False
    if s[i][j]!="
      continue
    for k in [-1,1]:
      if 0<=i+k<h:
        if s[i+k][j]=="
          flag=True
      if 0<=j+k<w:
        if s[i][j+k]=="
          flag=True
    if not flag:
      print("No")
      exit()
print("Yes")

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

for i in range(H):
    for j in range(W-1):
        if S[i][j]!='.' and S[i][j+1]!='.':
            S[i][j]='x'
            S[i][j+1]='x'

for j,s in enumerate(zip(*S)):
    for i in range(H-1):
        if s[i]!='.' and s[i+1]!='.':
            S[i][j]='x'
            S[i+1][j]='x'

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=[['.']*(w+2)]
for i in range(h):
    s+=[['.']+list(input())+['.']]
s+=[['.']*(w+2)]

dset=((-1,0),(0,1),(1,0),(0,-1))

for i in range(1,h+1):
    for j in range(1,w+2):
        if s[i][j]=='.':continue
        flag=False
        for y,x in dset:
            if s[i+y][j+x]=='
                flag=True
                break
        if not flag:
            print('No')
            exit()
print('Yes')

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

dx = [-1, 0, 0, 1]
dy = [0, 1, -1, 0]
for i in range(H):
    for j in range(W):
        flag = False
        for k in range(4):
            if s[i][j] == '
                nx = j + dx[k]
                ny = i + dy[k]
                if nx < 0 or nx >= W or ny < 0 or ny >= H:
                    continue
                if s[ny][nx] == '
                    flag = True
            else:
                flag = True
        if flag == False:
            print('No')
            exit()        

print('Yes')

Solution (Python):
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

H, W = nl()

mas = []
for i in range(H):
    mas.append(s())

for i in range(H):
    for j in range(W):
        if mas[i][j] == '
            if (i > 0 and mas[i-1][j] == '
               (i < H-1 and mas[i+1][j] == '
               (j > 0 and mas[i][j-1] == '
               (j < W-1 and mas[i][j+1] == '
                pass
            else:
                print('No')
                import sys
                sys.exit()

print('Yes')

Solution (Python):

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

lis = []

for i in range(H):

    s = input()
    lis.append(s)

ans = "Yes"

for i in range(H):

    for j in range(W):

        if lis[i][j] == "

            flag = True

            if i != 0 and lis[i-1][j] == "
                flag = False

            if i != H-1 and lis[i+1][j] == "
                flag = False

            if j != 0 and lis[i][j-1] == "
                flag = False

            if j != W-1 and lis[i][j+1] == "
                flag = False


            if flag:
                ans = "No"
                break

print (ans)

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

    dl = [(-1, 0), (0, 1), (1, 0), (0, -1)]
    for i, row in enumerate(S):
        for j, val in enumerate(row):
            if val == '.':
                continue

            can_paint = False
            for dx, dy in dl:
                di, dj = i + dx, j + dy
                if di < 0 or H <= di or dj < 0 or W <= dj:
                    continue
                if S[di][dj] == '
                    can_paint = True
                    break
            if not can_paint:
                return 'No'
    return 'Yes'

print(resolve())

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

flag=True
count=0
for i in range(h):
    for j in range(w):
        if s[i][j]=="
            if h==1:
                count+=1
            elif i!=0 and i!=h-1:
                if s[i-1][j]=="
                    continue
            elif i==0:
                if s[i+1][j]=="
                    continue
            elif i==h-1:
                if s[i-1][j]=="
                    continue
            
            if w==1:
                count+=1
            elif j!=0 and j!=w-1:
                if s[i][j-1]=="
                    continue
            elif j==0:
                if s[i][j+1]=="
                    continue
            elif j==w-1:
                if s[i][j-1]=="
                    continue
            flag=False

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

Solution (Python):
H, W = map(int, input().split())
s = [input() for _ in range(H)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
def solve():
    for x in range(H):
        for y in range(W):
            if s[x][y] == '
                flag = True
                for k in range(4):
                    nx = x + dx[k]
                    ny = y + dy[k]
                    if 0 <= nx and nx < H and 0 <= ny and ny < W and s[nx][ny] == '
                        flag = False
                if flag:
                    return False
    return True
print("Yes" if solve() else "No")

Solution (Python):
H,W=map(int,input().split())
S=[input()+'.'for _ in range(H)]+['.'*W]
print(('Yes','No')[any(S[y-1][x]==S[y+1][x]==S[y][x-1]==S[y][x+1]=='.'for y in range(H)for x in range(W)if S[y][x]=='

Solution (Python):
H,W=map(int,input().split())
S=[input()+'.'for _ in range(H)]+['.'*(W+2)]
print(('Yes','No')[any(S[y-1][x]==S[y+1][x]==S[y][x-1]==S[y][x+1]=='.'for y in range(H)for x in range(W)if S[y][x]=='

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

for i in range(1, h+1):
    for j in range(1, w+1):
        if not f[i][j] == '
            continue
        else:
            if f[i][j-1]=='
                pass
            else:
                print('No')
                exit()

print('Yes')

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

Solution (Python):


import numpy as np
import sys
buf = sys.stdin.buffer

H,W = map(int,buf.readline().split())
S = np.frombuffer(buf.read(H*(W+1)), dtype='S1').reshape((H,W+1))
S = S[:,:-1]

black = (S == b'
black_nbd = np.zeros((H,W), dtype=np.bool)


black_nbd[1:,:] |= black[:-1,:]

black_nbd[:-1,:] |= black[1:,:]

black_nbd[:,1:] |= black[:,:-1]

black_nbd[:,:-1] |= black[:,1:]

impossible = (black & ~black_nbd).any()
answer = 'Yes' if not impossible else 'No'
print(answer)

Solution (Python):
import sys

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

li = [[0] * (w+2)]  + [[0] + list(input()) + [0] for _ in range(h)] + [[0] * (w+2)]

for i in range(h+2):
    for j in range(w+2):
        if li[i][j] == "
            if li[i][j-1] == "
                pass
            else:
                print("No")
                sys.exit()
else:
    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] == "
      bk = sum([t[j].count("
      bk += S[i][max(0,j-1):min(W,j+2)].count("
      if bk == 1:
        print("No")
        exit()

print("Yes")

Solution (Python):
temp=list(map(lambda x:int(x),input().split()))
H,W=temp[0],temp[1]
grid=[]


for _ in range(H):
    row=list(input())
    row.insert(0,'pad')
    row.append('pad')
    grid.append(row)

pad=['pad' for _ in range(W+2)]
grid.insert(0,pad)
grid.append(pad)


dx=[1,0,-1,0]
dy=[0,1,0,-1]
flag=True
for r in range(1,H+1):
    for c in range(1,W+1):
        if grid[r][c]=='
            cnt=0
            for i in range(4):
                if grid[r+dx[i]][c+dy[i]]=='
                    cnt+=1
            if cnt==0:
                flag=False
                break
    if flag==False:break

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

Solution (Python):
hw = input().split(" ");
h = int(hw[0]);
w = int(hw[1]);
pic = [['.']*(w+2) for i in range(h+2)];
can = 0;
for i in range(1,h+1) :
	s = list(input().rstrip('\n'));
	for j in range(1,w+1) :
		pic[i][j] = s[j-1];
for i in range(1,h+1) :
	for j in range(1,w+1) :
		if pic[i][j] == '
			can = can + 1;
if can == 0 :
	print('Yes');
else :
	print('No');

Solution (Python):
H,W=map(int,input().split())
campus=[]
for _ in range(H):
    campus.append(input())
    
def ok(y,x):
    if campus[y][x]==".":
        return(True)
    else:
        TRUE=0
        if y==0:
            pass
        else:
            if campus[y-1][x]=="
                TRUE=1
        if y==H-1:
            pass
        else:
            if campus[y+1][x]=="
                TRUE=1
        if x==0:
            pass
        else:
            if campus[y][x-1]=="
                TRUE=1
        if x==W-1:
            pass
        else:
            if campus[y][x+1]=="
                TRUE=1
        if TRUE==1:
            return(True)
        else:
            return(False)

achievement=0            
for i in range(H):
    for j in range(W):
        if ok(i,j):
            pass
        else:
            achievement+=1
            
if achievement==0:
    print("Yes")
else:
    print("No")

Solution (Python):
H,W = (int(i) for i in input().split())

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

canComplete = True

for row in range(H):
    for column in range(W):
        above = row - 1
        bottom = row + 1
        left = column - 1
        right = column + 1
        
        if goal[row][column] == "
            if above >= 0 and goal[above][column] == "
                continue
            elif bottom < H and goal[bottom][column] == "
                continue
            elif left >= 0 and goal[row][left] == "
                continue
            elif right < W and goal[row][right] == "
                continue
            else:
                canComplete = False
                break

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

Solution (Python):

import sys
sys.setrecursionlimit(4100000)

h, w = [int(i) for i in input().split()]
a = [[str(i) for i in input()] for _ in range(h)]

def check(row,col):
    if row < 0 or col < 0 or row >= h or col >= w:
        return False
    if a[row][col] == ".":
        return False
    return True

def bfs(row, col):
    if any([check(row-1,col), check(row+1, col), check(row,col-1), check(row,col+1)]):
        return True
    return False
end = 0
for i in range(h):
    if end == 0:
        for k in range(w):
            if end == 0:
                if a[i][k] == "
                    if bfs(i,k) == False:
                        end = 1
if end == 0:
    print("Yes")
else:
    print("No")

Solution (Python):
h,w=[int(i) for i in input().split()]
s=[[i for i in input()] for _ in range(h)]
flg=True
for i in range(h):
    for j in range(w):
        if s[i][j]=="
            flg=False
            for y,x in [(1,0),(-1,0),(0,1),(0,-1)]:
                try:
                    if s[i+y][j+x]=="
                        flg=True
                except:
                    pass
        if not flg:
            break
    if not flg:
        break
print("Yes" if flg else "No")

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

ans = True
for i in range(H):
    for j in range(W):
        b = 0
        if s[i][j] == '
            if i-1>=0:
                if s[i-1][j] == '
                    b += 1
            if i+1<H:
                if s[i+1][j] == '
                    b += 1
            if j-1>=0:
                if s[i][j-1] == '
                    b += 1
            if j+1<W:
                if s[i][j+1] == '
                    b += 1
            if b == 0:
                ans = False
if ans:
    print('Yes')
else:
    print('No')

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

S = []

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

flag = True

for i in range(H):
    for j in range(W):
        s_list = []
        if S[i][j] == "
            
            if j + 1 < W:
                s_list.append(S[i][j + 1])
            
            if j - 1 >= 0:
                s_list.append(S[i][j - 1])
            
            if i - 1 >= 0:
                s_list.append(S[i - 1][j])
            
            if i + 1 < H:
                s_list.append(S[i + 1][j])
            if "
                
                flag = False


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

Solution (Python):
l = input().split()
H = int(l[0])
W = int(l[1])

S = []

for i in range(H):
    S.append(input().split()[0])



for i in range(1, H - 1):
    for j in range(1, W - 1):
        s = S[i][j]
        if s == '.':
            continue
        if S[i][j - 1] == '
            continue
        if S[i][j + 1] == '
            continue
        if S[i - 1][j] == '
            continue
        if S[i + 1][j] == '
            continue
        print('No')
        exit()
print('Yes')

Solution (Python):
def has_black_around(table, y, x):
    dxs = [0, 1, 0, -1]
    dys = [1, 0, -1, 0]

    for dx, dy in zip(dxs, dys):
        ny = y + dy
        nx = x + dx
        if table[ny][nx] == "
            return True
    return False


def solve(table, H, W):

    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if table[y][x] == '
                return False
    return True


if __name__ == '__main__':
    H, W = map(int, input().split())

    table = [["@" for j in range(W + 2)] for i in range(H + 2)]

    for i in range(1, H + 1):
        table[i][1:W+1] = [ch for ch in input().strip()]

    answer = "Yes" if solve(table, H, W) else "No"

    print(answer)