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
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    H, W = MI()
    D = Init(H, W, -1)
    L = [input().rstrip() for i in range(H)]
    move = [[1,0],[0,1],[-1,0],[0,-1]]
    for i in range(H):
        for j in range(W):
            if L[i][j] == "
                D[i][j] = 0
                dq = deque([(i, j)])
                while dq:
                    x, y = dq.popleft()
                    for x1, y1 in move:
                        x1+=x
                        y1+=y
                        if x1 >= 0 and x1 <= H-1 and y1 >= 0 and y1 <= W-1 and D[x1][y1] == -1:
                            if L[x1][y1] == "
                                D[x1][y1] = D[x][y]+1
                                dq.append((x1, y1))
                if D[x][y] == 0:
                    print("No")
                    exit()
    print("Yes")

if __name__ == "__main__":
    main()

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

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

canvas = []

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

for i in range(H):
  for j in range(W):
    cnt = 0
    if canvas[i][j] == "
      for h in range(-1,2):
        for w in range(-1,2):
          if canvas[min(max(i+h,0),H-1)][min(max(j+w,0),W-1)]=="
            cnt+=1
      if cnt==0:
        print("No")
        exit()
print("Yes")

Solution (Python):
H, W = map(int, input().split())
S = []
D = [[-1, 0], [0, -1], [1, 0], [0, 1]]
for i in range(H):
  S.append(input())
f = 0
for i in range(H):
  for j in range(W):
    if S[i][j] == "
      g = 0
      for k in range(4):
        if 0 <= i + D[k][0] < H and 0 <= j + D[k][1] < W and S[i+D[k][0]][j+D[k][1]] == "
          g = 1
      if g == 0:
        f = 1
if f == 0:
  print("Yes")
else:
  print("No")

Solution (Python):
H, W = map(int, input().split())
L = ['.' + input() + '.' for _ in range(H)]
L = ['.' * (W + 2)] + L + ['.' * (W + 2)]
for i in range(1, H + 1):
  for j in range(1, W + 1):
    if L[i][j] == "
      l = [L[i-1][j], L[i+1][j], L[i][j-1], L[i][j+1]]
      if '
        print('No')
        break
  else:
    continue
  break
else:
  print('Yes')

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

for _ in range(H):
  grid_i = input().split()
  grid.append(grid_i[0])

for i in range(H):
  for j in range(W):
    if grid[i][j] == "
      X = "NG"
      if (i-1 >= 0 and grid[i-1][j] == ".") or i < 1:
        None
      else:
        X = "OK"
      if (j-1 >= 0 and grid[i][j-1] == ".") or j < 1:
        None
      else:
        X = "OK"
      if (i+1 < H and grid[i+1][j] == ".") or i+1 >= H:
        None
      else:
        X = "OK"
      if (j+1 < W and grid[i][j+1] == ".") or j+1 >= W:
        None
      else:
        X = "OK"
      if X == "NG":
        ans = "No"

print(ans)

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

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

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

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

def get(lst, i, default=None):
  try:
    return lst[i]
  except IndexError:
    return default

for i in range(H):
  for j in range(W):
    s = SS[i][j]
    if s == '
      if '
        print('No')
        import sys
        sys.exit()

print('Yes')

Solution (Python):
col,row = [int(x) for x in input().split()]
map_list = [[0] * (row+2)]
for i in range(col):
    map_list.append(["0"] + list(input()) + ["0"])
map_list.append(map_list[0])


def check(x,y):
    lands = [[x,y]]
    
    area = 0
    sealine = 0
    while lands:
        
        
        x,y = lands.pop()
        
        area += 1
        map_list[y][x] = "2"
        if map_list[y+1][x] == "
            lands.append([x,y+1])
        elif not map_list[y+1][x] == "2":
            sealine += 1
        if map_list[y][x+1] == "
            lands.append([x+1,y])
        elif not map_list[y][x+1] == "2":
            sealine += 1
        if map_list[y-1][x] == "
            lands.append([x,y-1])
        elif not map_list[y-1][x] == "2":
            sealine += 1
        if map_list[y][x-1] == "
            lands.append([x-1,y])
        elif not map_list[y][x-1] == "2":
            sealine += 1
        lands = list(map(tuple,lands))
        lands = list(set(lands))
        
    return area

res = "Yes"
for i in range(1,col+1):
    for j in range(1,row+1):
        if map_list[i][j] == "
            if check(j,i) == 1:
              res = "No"
print(res)

Solution (Python):
import sys

def check(i,j,s_list,h,w):
    uesita_list = [-1,1]
    sayuu_list = [-1,1]

    for uesita in uesita_list:
        new_i = i + uesita
        if new_i < 0 or new_i > h-1:
            continue
        if s_list[new_i][j] == "
            return True

    for sayuu in sayuu_list:
        new_j = j + sayuu
        if new_j > w-1 or new_j < 0:
            continue
        if s_list[i][new_j] == "
            return True
    
    return False            


input = sys.stdin.readline

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

s_list = [[0 for _ in range(w)] for _ in range(h)]
for i in range(h):
    w_s_list = input()
    w_s_list = w_s_list.replace('\n','')
    w_s_list = list(w_s_list)
    for j in range(w):
        s_list[i][j] = w_s_list[j]


for i in range(h):
    for j in range(w):
        s = s_list[i][j]
        if s == "
            ok_flag = check(i,j,s_list,h,w)
            if not ok_flag:
                print("No")
                exit(0)

print("Yes")

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

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

for i in range(h):
  for j in range(w):
    cnt = 0
    if F[i][j] == '
      if 0 <= (i-1) < h: 
        if F[i-1][j] == '
      if 0 <= (i+1) < h: 
        if F[i+1][j] == '
      if 0 <= (j-1) < w:
        if F[i][j-1] == '
      if 0 <= (j+1) < w:
        if F[i][j+1] == '
      if cnt == 0:
        print('No')
        exit()
print('Yes')

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


def checkaround(i,j):
    dirc = [[0,1],[-1,0],[0,-1],[1,0]]
    for d in dirc:
        if S[i-d[0]][j-d[1]] == "
            return True
    return False
def main():
    for i in range(1,H+1):
        for j in range(1,W+1):
            if S[i][j] == "
                if not checkaround(i,j):
                    print("No")
                    return
    print("Yes")

main()

Solution (Python):


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

    return res


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

for y in range(H):
    for x in range(W):
        if s[y][x] == "
            print("No")
            exit()

print("Yes")

Solution (Python):
from itertools import product
from collections import deque
import numpy as np
class Grid:
    def __init__(self, grid, w=0, h=0, function=lambda x: x):
        self.w = w = w if w else len(grid[0])
        self.h = h = h if h else len(grid)
        dtype = type(function(grid[0][0]))
        self.grid = np.empty((h, w), dtype=dtype)
        for i, row in zip(range(h), grid):
            for j, val in zip(range(w), row):
                self.grid[i][j] = function(val)
    
    def is_valid_x(self, x):
        return 0 <= x < self.w
    def is_valid_y(self, y):
        return 0 <= y < self.h
    def is_valid_xy(self, x, y):
        return self.is_valid_x(x) and self.is_valid_y(y) 
    
    def __iter__(self):
        return iter(self.grid)
    def __repr__(self):
        return '\n'.join([' '.join(map(str, row)) for row in self.grid]) + '\n'
    def __getitem__(self, x):
        return self.grid[x]
    def __setitem__(self, x, val):
        self.grid[x] = val


def dfs(grid, root):
    stack = [root]
    x, y = root
    grid[y, x] = '!'
    while stack:
        x, y = stack.pop()
        yield (x, y)
        for dx, dy in zip([1, 0, -1, 0], [0, 1, 0, -1]):
            nx, ny = x+dx, y+dy
            if grid.is_valid_xy(nx, ny) and grid[ny, nx] == '
                stack.append((nx, ny))
                grid[ny, nx] = '!'

h, w = map(int, input().split())
grid = Grid([input() for s in range(h)])

for y, x in product(range(h), range(w)):
    if grid[y, x] == '
        if len(list(dfs(grid, (x, y)))) == 1:
            print('No')
            break
else:
    print('Yes')

Solution (Python):

"""
Created on Fri Sep 18 10:13:51 2020

@author: liang
"""
H, W = map(int, input().split())
flag = True
field = [input() for i in range(H)]

for i in range(H):
    for j in range(W):
        if field[i][j] == "
            tmp = False
            if i-1>= 0 and field[i-1][j] == "
                tmp = True
            if i+1 < H and field[i+1][j] == "
                tmp = True
            if j-1>= 0 and field[i][j-1] == "
                tmp = True
            if j+1 < W and field[i][j+1] == "
                tmp = True
            if tmp == False:
                flag = False

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

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

for y in range(h):
    for x in range(w):
        if s[y][x] == ".":
            continue
        if 0 < x < w-1:
            if 0 < y < h-1:
                if s[y][x-1] == "." and s[y][x+1] == "." and s[y-1][x] == "." and s[y+1][x] == ".":
                    print("No")
                    exit()
            elif y == 0:
                if s[y][x-1] == "." and s[y][x+1] == "." and s[y+1][x] == ".":
                    print("No")
                    exit()
            else:
                if s[y][x-1] == "." and s[y][x+1] == "." and s[y-1][x] == ".":
                    print("No")
                    exit()
        elif x == 0:
            if 0 < y < h-1:
                if s[y][x+1] == "." and s[y-1][x] == "." and s[y+1][x] == ".":
                    print("No")
                    exit()
            elif y == 0:
                if s[y][x+1] == "." and s[y+1][x] == ".":
                    print("No")
                    exit()
            else:
                if s[y][x+1] == "." and s[y-1][x] == ".":
                    print("No")
                    exit()
        else:
            if 0 < y < h-1:
                if s[y][x-1] == "." and s[y-1][x] == "." and s[y+1][x] == ".":
                    print("No")
                    exit()
            elif y == 0:
                if s[y][x-1] == "." and s[y+1][x] == ".":
                    print("No")
                    exit()
            else:
                if s[y][x-1] == "." and s[y-1][x] == ".":
                    print("No")
                    exit()
print("Yes")

Solution (Python):
h,w=map(int,input().split()) 
l = [input() for _ in range(h)]
dx = [1,-1,0,0]
dy = [0,0,1,-1]
for i in range(h):
    for j in range(w):
        if l[i][j] =='
            cnt = 0
            for di in range(4):
                y = i+dx[di]
                x = j+dy[di]
                if x<0 or y<0 or x>w-1 or y>h-1:
                    continue
                else:
                    if l[y][x] =='
                        cnt +=1
            if cnt == 0:
                print('No')
                exit()

print('Yes')

Solution (Python):
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
flag = True
for i in range(h):
    for j in range(w):
        if s[i][j] == '
            if not(i == 0 or s[i-1][j] == '
                flag = False
print('Yes' if flag else 'No')

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

mx = [0, 1, 0, -1]
my = [1, 0, -1, 0]
for i in range(h):
    for j in range(w):
        if table[i][j] == "
            for k in range(4):
                tx = j + mx[k]
                ty = i + my[k]
                if 0 <= tx < w and 0 <= ty < h and table[ty][tx] == "
                    break
            else:
                print("No")
                exit(0)
print("Yes")

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

mx = [0, 1, 0, -1]
my = [1, 0, -1, 0]
for i in range(h):
    for j in range(w):
        if table[i][j] == "
            for k in range(4):
                tx, ty = j + mx[k], i + my[k]
                if 0 <= tx < w and 0 <= ty < h and table[ty][tx] == "
                    break
            else:
                print("No")
                exit(0)
print("Yes")

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

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

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

sq=[list(input()) for i in range(H)]

for i in range(H):
    for j in range(W):
        if sq[i][j]=="
            temp=0
            if j!=0:
                if sq[i][j-1]=="
                    temp+=1
            if j!=W-1:
                if sq[i][j+1]=="
                    temp+=1
            if i!=0:
                if sq[i-1][j]=="
                    temp+=1
            if i!=H-1:
                if sq[i+1][j]=="
                    temp+=1
            if temp==0:
                print("No")
                exit()

print("Yes")

Solution (Python):


N, M = map(int, input().split())

c = 0
l = []
for i in range(N):
  l.append(list(input()))
  

N -= 1
M -= 1

for i in range(N):
  for j in range(M):
    if l[i][j] == ".":
      pass
    else:
      if i-1>=0 and i+1<=N and j-1>=0 and j+1<=M and l[i-1][j] == "." and l[i+1][j] == "." and l[i][j-1] == "." and l[i][j+1] == ".":
        c+=1
      if i==0 and j-1>=0 and j+1<=M and l[i+1][j] == "." and l[i][j-1] == "." and l[i][j+1] == ".":
        c+=1
      if i-1>=0 and i+1<=N and j==0 and l[i-1][j] == "." and l[i+1][j] == "." and l[i][j+1] == ".":
        c+=1
      if i==N and j-1>=0 and j+1<=M and l[i-1][j] == "." and l[i][j-1] == "." and l[i][j+1] == ".":
        c+=1
      if i-1>=0 and i+1<=N and j-1>=0 and j==M and l[i-1][j] == "." and l[i+1][j] == "." and l[i][j-1] == ".":
        c+=1
      if i==0 and j==0 and l[i+1][j] == "." and l[i][j+1] == ".":
        c+=1
      if i==0 and j==M and l[i+1][j] == "." and l[i][j-1] == ".":
        c+=1
      if i==N and j==0 and l[i-1][j] == "." and l[i][j+1] == ".":
        c+=1
      if i==N and j==M and l[i-1][j] == "." and l[i][j-1] == ".":
        c+=1

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

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

for i in range(len(x)):
    x[i].insert(0, ".")
    x[i].append(".")
x.insert(0, ["."]*(W+2))
x.append(["."]*(W+2))

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

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


flug = True
for i in range(H):
    for j in range(W):
        if s[i][j] == '
            if not (s[i+1][j] == '
                    or s[i-1][j] == '
                    or s[i][j+1] == '
                    or s[i][j-1] == '
                flug = False
if flug:
    print("Yes")
else:
    print("No")

Solution (Python):
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

H, W = I()

pad_s = ['.'*(W+2)]
for h in range(H):
  pad_s.append('.' + input() + '.')
pad_s.append('.'*(W+2))

for i,ss in enumerate(pad_s):
  for j,s in enumerate(ss):
    if s == '
      and pad_s[i][j+1] == '.'\
      and pad_s[i][j-1] == '.'\
      and pad_s[i+1][j] == '.'\
      and pad_s[i-1][j] == '.':
      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(H):
    for w in range(W):
        if S[h][w] in ['.', 'B']: continue
        
        ary = [[0,1], [0,-1], [1,0], [-1,0]]
        flag = False
        for x, y in ary:
            xd = h+x
            yd = w+y
            if xd < 0 or xd >= H or yd < 0 or yd >=W: continue
            if S[xd][yd] in ['B', '
                S[h][w] = 'B'
                S[xd][yd] = 'B'
                flag = True
        
        if not flag:
            print('No') 
            exit()

print('Yes')

Solution (Python):
h,w=list(map(int,input().split()))
masu=[]
masu.append([])
for i in range(w+2):
  masu[0].append('.')
for i in range(h):
  masu.append([])
  masu[i+1].append('.')
  yoko=input()
  for j in range(w):
    masu[i+1].append(yoko[j])
for i in range(w+2):
  masu[0].append('.')
for i in range(1,h-1):
  for j in range(1,w-1):
    if masu[i][j]=='
      if masu[i][j+1]=='.' and masu[i][j-1]=='.' and masu[i+1][j]=='.' and masu[i-1][j]=='.':
        print('No')
        exit()
print('Yes')

Solution (Python):
import sys
import copy
import math
import itertools
import numpy as np

H,W = [int(c) for c in input().split()]
s = [list(input()) for c in range(H)]
a = [[1 for c in range(W)] for d in range(H)]
b = [[0 for c in range(W)] for d in range(H)]

for i in range(H):
    for j in range(W):
        if s[i][j]=="
            if i-1 >= 0:
                if s[i-1][j] == "
                    a[i][j]=0
            if j-1 >= 0:
                if s[i][j-1] == "
                    a[i][j]=0
            if j+1 < W:
                if s[i][j+1] == "
                    a[i][j]=0
            if i+1 < H:
                if s[i+1][j] == "
                    a[i][j]=0
        else:
            a[i][j]=0
        if a[i][j] == 1:
            print("No")
            sys.exit(0)

print("Yes")

Solution (Python):
import re
import copy

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

def process(s):
    if s == "
        return 1
    else:
        return 0
H,W,S = accept_input()
arr1 = [(-1,-1),(-1,0),(-1,1),(1,-1),(1,0),(1,1),(0,1),(0,-1)]
arr = [(-1,0),(1,0),(0,1),(0,-1)]
new_S = copy.deepcopy(S)
g = 0
b = 0
for i in range(H):
    for j in range(W):
        if new_S[i][j] == "
            bl = 0
            for idou in arr:
                if i+idou[0] == -1 or i+idou[0] == H:
                    continue
                elif j+idou[1] == -1 or j+idou[1] == W:
                    continue
                else:
                    if new_S[i+idou[0]][j+idou[1]] == "
                        bl = 1
            if bl != 1:
                b = 1
                break
    if b == 1:
        break
if b == 1:
    print("No")
else:
    print("Yes")

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

dh = [0, 1, 0, -1]
dw = [1, 0, -1, 0]
flag = 0

for i in range(h):
    for j in range(w):
        if s[i][j] == '
            cnt = 0
            for p in range(4):
                if i + dh[p] < 0 or i + dh[p] >= h or j + dw[p] < 0 or j + dw[p] >= w:
                    continue
                else:
                    if s[i + dh[p]][j + dw[p]] == '
                        cnt += 1
            if cnt == 0:
                flag = 1
                break
        if flag == 1:
            break
    if flag == 1:
        print('No')
        break
else:
    print('Yes')

Solution (Python):
H,W=map(int,input().split())
s=[input() for _ in range(H)]
cells=[(i,j) for i in range(H) for j in range(W)]
di=[1,0,-1,0]
dj=[0,1,0,-1]

for i,j in cells:
    if s[i][j]=='.':
        continue
    flag=False
    for k in range(4):
        ni=i+di[k]
        nj=j+dj[k]
        if ni<0 or nj<0 or ni>=H or nj>=W:
            continue
        if s[ni][nj]=='
            flag=True
    if not flag:
        print("No")
        break
else:
    print("Yes")

Solution (Python):
import sys



def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


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


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

    directions = ((1, 0), (0, 1), (-1, 0), (0, -1))

    for i in range(1, h + 1):
        for j in range(1 + w + 1):
            
            if grid[i][j] == "
                cnt = 0
                for x, y in directions:
                    if grid[i + x][j + y] == "
                        cnt += 1
                if cnt == 0:
                    print("No")
                    return
    print("Yes")
    return


if __name__ == "__main__":
    main()

Solution (Python):
from itertools import product


H, W = map(int, input().split())
s = [input() for _ in range(H)]
for i, j in product(range(H), range(W)):
    if s[i][j] == ".":
        continue
    is_ok = False
    for di, dj in (1, 0), (-1, 0), (0, 1), (0, -1):
        ni, nj = i + di, j + dj
        if not (0 <= ni < H and 0 <= nj < W):
            continue
        if s[ni][nj] == "
            is_ok = True
    if not is_ok:
        print("No")
        break
else:
    print("Yes")

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

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


for i in range(H):
    for j in range(W):
        if s[i][j]=='
            f=0
            for x,y in [(j,i+1),(j+1,i),(j,i-1),(j-1,i)]:
                if x<0 or x>W-1 or y<0 or y>H-1:
                    continue
                if s[y][x]=='
                    f=1
                    break
            if f==0:
                print('No')
                exit()

print('Yes')

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

for y in range(1, h + 1):
    for x in range(1, w + 1):
        if s[y][x] == '
            print('No')
            exit()
print('Yes')

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

for y in range(1, h + 1):
    for x in range(1, w + 1):
        if s[y][x] == '.':
            continue
        ok = False
        for dy, dx in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
            if s[y + dy][x + dx] == '
                ok = True
        if not ok:
            print('No')
            exit()
print('Yes')

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

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


print('Yes')

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate, product 

from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq














import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7


from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
h,w = readInts()
maze = [input() for _ in range(h)]
dxy = [(-1,0),(1,0),(0,1),(0,-1)]
flag = True
for y in range(h):
    for x in range(w):
        if maze[y][x] == '
            ok = False
            for dy,dx in dxy:
                ny = y + dy
                nx = x + dx
                if not(0 <= ny < h and 0 <= nx < w):
                    continue
                if maze[ny][nx] == '
                    ok = True
                    break
            if ok:
                flag = True
            else:
                flag = False
                break
    if not flag:
        break
if flag:
    print('Yes')
else:
    print('No')

Solution (Python):
import sys

H, W = map(int, input().split())
S = [list(sys.stdin.readline().strip()) for _ in range(H)]

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

for i, row in enumerate(S):
    for j, s in enumerate(row):
        if s == ".":
            continue
        ok = False
        for k in range(4):
            nx = j + dx[k]
            ny = i + dy[k]
            if not(0 <= nx < W and 0 <= ny < H):
                continue
            if S[ny][nx] == "
                ok = True
        if ok is False:
            print("No")
            exit()

print("Yes")

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

for i in range(H):
    for j in range(W):
        if Map[i][j] == '
            for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
                ny = i + dy
                nx = j + dx
                if ny < 0 or ny >= H or nx < 0 or nx >= W:
                    continue
                if Map[ny][nx] == '
                    break
            else:
                print('No')
                exit()
print('Yes')

Solution (Python):
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
a = [[-1]*W for _ in range(H)]
for i in range(H):
  for j in range(W):
    if s[i][j] == ".":
      a[i][j] = 1
    dh = [-1,0,1,0]
    dw = [0,-1,0,1]
    for k in range(4):
      ii = i + dh[k]
      jj = j + dw[k]
      if 0 <= ii < H and 0 <= jj < W:
        if s[i][j] == "
          a[i][j] = 1
          a[ii][jj] = 1
flag = True
for i in range(H):
  for j in range(W):
    if a[i][j] != 1:
      flag = False
      break
if flag:
  print("Yes")
else:
  print("No")

Solution (Python):
import sys


def LI():
    return list(map(int, input().split()))


def LSH(h):
    return [input() for _ in range(h)]


H, W = LI()
masu = LSH(H)
for i in range(H):
    for j in range(W):
        ok = 0
        if masu[i][j] == ".":
            continue
        if j+1 < W:
            if masu[i][j+1] == "
                ok = 1
        if j-1 >= 0:
            if masu[i][j-1] == "
                ok = 1
        if i+1 < H:
            if masu[i+1][j] == "
                ok = 1
        if i-1 >= 0:
            if masu[i-1][j] == "
                ok = 1
        if ok == 0:
            print("No")
            sys.exit()
print("Yes")

Solution (Python):
H,W = map(int,input().split())
S = [input().strip() for _ in range(H)]
flag = 0
for i in range(H):
    for j in range(W):
        if S[i][j]=="
            if j+1<W and S[i][j+1]=="
            or i+1<H and S[i+1][j]=="
                continue
            else:
                flag = 1
                break
    if flag==1:break
if flag==0:
    print("Yes")
else:
    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):
        if s[i][j] == '.':
            continue
        ok = False
        for dx, dy in [(1, 0), (0, 1), (0, -1), (-1, 0)]:
            nx = j + dx
            ny = i + dy
            if 0 <= nx < w and 0 <= ny < h and s[ny][nx] == '
                ok = True
        if not ok:
            print('No')
            exit()
print('Yes')

Solution (Python):
from sys import exit
h, w = map(int, input().split())
S = [input() for i in range(h)]
for i, T in enumerate(S):
    for j, t in enumerate(T):
        if t == "
            flag = 0
            if j > 0:
                if T[j - 1] == "
                    flag += 1
            if j < w - 1:
                if T[j + 1] == "
                    flag += 1
            if i > 0:
                if S[i - 1][j] == "
                    flag += 1
            if i < h - 1:
                if S[i + 1][j] == "
                    flag += 1
            if flag == 0:
                print("No")
                exit()
print("Yes")