Problem:
 Score: 300 points    Problem Statement  We have a canvas divided into a grid with H rows and W columns. The square at the i -th row from the top and the j -th column from the left is represented as (i, j) . Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}=  # , and to make Square (i, j) white when s_{i, j}=  . . However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black. Determine if square1001 can achieve his objective.      Constraints   H is an integer between 1 and 50 (inclusive).  W is an integer between 1 and 50 (inclusive).  For every (i, j)  (1 \leq i \leq H, 1 \leq j \leq W) , s_{i, j} is # or . .         Input  Input is given from Standard Input in the following format:  H  W  s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}  s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}  :  :  s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}       Output  If square1001 can achieve his objective, print Yes ; if he cannot, print No .        Sample Input 1 3 3
.#.
###
.#.      Sample Output 1 Yes  One possible way to achieve the objective is shown in the figure below. Here, the squares being painted are marked by stars.        Sample Input 2 5 5
#.#.#
.#.#.
#.#.#
.#.#.
#.#.#      Sample Output 2 No  square1001 cannot achieve his objective here.       Sample Input 3 11 11
...#####...
.##.....##.
#..##.##..#
#..##.##..#
#.........#
#...###...#
.#########.
.#.#.#.#.#.
##.#.#.#.##
..##.#.##..
.##..#..##.      Sample Output 3 Yes

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

matrix = []
ans = "Yes"

for _ in range(H):
    siw = list(input())
    matrix.append(siw)

memo = []

for h in range(H):
    for w in range(W):
        if matrix[h][w] == "
            if w == 0:
                if matrix[h][w+1] == ".":
                    memo.append((h,w))
            elif w == W-1:
                if matrix[h][w-1] == ".":
                    memo.append((h,w))
            else:
                if matrix[h][w-1] == "." and matrix[h][w+1] == ".":
                    memo.append((h,w))

for h, w in memo:
    if h == 0:
        if matrix[h+1][w] == ".":
            ans = "No"
            break
    elif h == H-1:
        if matrix[h-1][w] == ".":
            ans = "No"
            break
    else:
        if matrix[h-1][w] == "." and matrix[h+1][w] == ".":
            ans = "No"
            break

print(ans)

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


def read():
    H, W = map(int, input().strip().split())
    S = []
    for i in range(H):
        s = list(input().strip())
        S.append(s)
    return H, W, S


def solve(H, W, S):
    if H == 1 and  W == 1 and S[0][0] == "
        return "No"
    
    dd = [(1, 0), (0, 1), (-1, 0), (0, -1)]

    def dfs(y, x):
        depth = 1
        S[y][x] = "."
        for dy, dx in dd:
            ny = y + dy
            nx = x + dx
            if 0 <= ny < H and 0 <= nx < W and S[ny][nx] == "
                depth = max(depth, dfs(ny, nx) + 1)
        return depth

    for i in range(H):
        for j in range(W):
            if S[i][j] == "
                depth = dfs(i, j)
                if depth == 1:
                    return "No"
    return "Yes"


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

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

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

ans="Yes"
for y in range(0, H):
    for x in range(0, W):
        if s[y][x]==".":
            continue

        c=0
        for d in range(-1, 2, 2):
            xx = x + d
            if 0<=xx and xx<W:
                if s[y][xx]=="
                    c+=1
            yy = y + d
            if 0<=yy and yy<H:
                if s[yy][x]=="
                    c+=1
        if c==0:
            ans="No"
print(ans)

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

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

ans="Yes"
for y in range(0, H):
    for x in range(0, W):
        if s[y][x]==".":
            continue

        c=0
        for dx in range(-1, 2, 2):
            xx = x + dx
            if 0<=xx and xx<W:
                if s[y][xx]=="
                    c+=1
                    
        for dy in range(-1, 2, 2):
            yy = y + dy
            if 0<=yy and yy<H:
                if s[yy][x]=="
                    c+=1

        if c==0:
            ans="No"
print(ans)

Solution (Python):
h,w=map(int,input().split())
s=[list(input()) for a in range(h)]
check=[[-1,0],[0,-1],[1,0],[0,1]]
for i in range(h):
    for j in range(w):
        cnt=0
        if s[i][j]=="
           if i>=1:
                if s[i+check[0][0]][j+check[0][1]]=="
                    cnt+=1
           if j>=1:
                if s[i+check[1][0]][j+check[1][1]]=="
                    cnt+=1
           if i <= h-2:
               if s[i + check[2][0]][j + check[2][1]]=="
                    cnt+=1
           if j <= w - 2:
               if s[i + check[3][0]][j + check[3][1]]=="
                   cnt+=1
           if cnt == 0:
               print("No")
               exit()

print("Yes")

Solution (Python):
H,W = map(int,input().split())
s = [input() for _ in range(H)]
for i in range(H):
  for j in range(W):
    if s[i][j] == "
      if i != 0 and s[i-1][j] == "
        continue
      if i != H-1 and s[i+1][j] == "
        continue
      if j != 0 and s[i][j-1] == "
        continue
      if j != W-1 and s[i][j+1] == "
        continue
      print("No")
      exit()
print("Yes")

Solution (Python):
































h, w = map(int, input().split())
s = [["a"]*(w + 2)]
 
for i in range(h):
    s.append(list("a" + input() + "a"))
s.append(["a"]*(w + 2))
 
for i in range(h + 1):
    for j in range(w + 1):
        if s[i][j] == "
            if s[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())
for i in range(1,H-1):
    for j in range(1,W-1):
        if S[i][j]== "
            print("No")
            exit()
print("Yes")

Solution (Python):
H,W = map(int,input().split())
C = [list(input()) for i in range(H)]
for i in range(H):
  for j in range(W):
    if C[i][j]=='
      if (i>0 and C[i-1][j]=='.') and (i<H-1 and C[i+1][j]=='.') and (j>0 and C[i][j-1]=='.') and (j<H-1 and C[i][j+1]=='.'):
        print("No")
        exit()
print("Yes")

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

for i in range(h):
    s.append(list("a" + input() + "a"))
s.append(["a"]*(w + 2))

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

print("Yes")

Solution (Python):
import sys

h,w=map(int,input().split())
C=[input() for i in range(h)]
for i in range(h):
    for j in range(w):
        if C[i][j]==".":
            continue
        flag=0
        if i!=0:
            if C[i-1][j]=="
                flag=1
        if i!=h-1:
            if C[i+1][j]=="
                flag=1
        if j!=0:
            if C[i][j-1]=="
                flag=1
        if j!=w-1:
            if C[i][j+1]=="
                flag=1
        if flag==0:
            print("No")
            sys.exit()
print("Yes")

Solution (Python):
import sys
readline = sys.stdin.readline
directions = [(0, -1), (0, 1), (-1, 0), (1, 0)]

def main():
    H, W = map(int, readline().rstrip().split())
    S = [readline().rstrip() for _ in range(H)]
    res = 'Yes'
    for h in range(H):
        for w in range(W):
            if S[h][w] != '
                continue
            flg = False
            for dh, dw in directions:
                if 0 <= h+dh < H and 0 <= w+dw < W:
                    if S[h+dh][w+dw] == '
                        flg = True
                        break
            if not flg:
                res = 'No'
                break
        else:
            continue
        break

    print(res)

if __name__ == '__main__':
    main()

Solution (Python):

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] == '
            
            if 0 < j and grid[i][j-1] == '
                continue
            if j < (w - 1) and grid[i][j+1] == '
                continue
            
            if 0 < i and grid[i-1][j] == '
                continue
            if i < (h - 1) and grid[i+1][j] == '
                continue
            
            print("No")
            exit()

print("Yes")

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


map_input = [list(map(str,list(input()))) for i in range(h)]

map_list = [['.']*(w+2)]
for m in map_input:
    map_list.append(['.']+m+['.'])
map_list.append(['.']*(w+2))

for i in range(h+2):
    for j in range(w+2):
        if map_list[i][j]=='
            if map_list[i+1][j]=='
                continue
            elif map_list[i-1][j]=='
                continue
            elif map_list[i][j+1]=='
                continue
            elif map_list[i][j-1]=='
                continue
            else:
                print('No');exit()

print('Yes')

Solution (Python):
import itertools

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

ok = True        
for i in range(H):
  for j in range(W):
    if S[i][j] == '
      flg = False
      for x,y in itertools.product([-1,0,1],repeat=2):
        if not (abs(x) + abs(y) == 1):
          continue
        nx = i + x;ny = j + y
        if 0 <= nx < H and 0 <= ny < W:
          if S[nx][ny] == '
            flg = True
      if not flg:
        ok = False
        break
if ok:
  print('Yes')
else:
  print('No')

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

for i in range(1,H+1):
  for j in range(1,W+1):
    if List[i][j]=="
        ==List[i][j+1]==List[i+1][j]==".":
      print("No")
      break
  else:
    continue
  break  

else:print("Yes")

Solution (Python):


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

s = [list(input()) for _ in range(h)]
dx = [0,1,0,-1]
dy = [1,0,-1,0]

count = 0

for y in range(h):
    for x in range(w):
        cnt = 0
        for k in range(4):
            ny = y + dy[k]
            nx = x + dx[k]
            if nx < 0 or nx>=w or ny < 0 or ny >=h:
                continue
            if s[y][x] == '.':
                cnt +=1
                continue
            if s[y][x] == '
                if s[ny][nx] == '
                    cnt += 1
        if cnt == 0:
            print('No')
            exit()

                        
print('Yes')

Solution (Python):


h,w=map(int, input().split( ))
s= ["."*(w+2)]+["."+input()+"." for _ in range(h)]+["."*(w+2)]
od=0
ev=0
nb=[(1,0),(-1,0),(0,1),(0,-1)]
for i in range(1,h+1):
    for j in range(1,w+1):
        flag=False
        for x,y in nb:
            if s[i+x][j+y]=="
                flag=True
                break
        if not flag and s[i][j]=="
            print("No")
            exit()
        
        
print("Yes")

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

for i in range(H):
    for j in range(W):
        if s[i][j] == '
            count = 0
            for dx, dy in ((-1,0), (0,1), (1,0), (0,-1)):
                x, y = i+dx, j+dy
                if 0 <= x and 0 <= y and x <= H-1 and y <= W-1:
                    if s[x][y] == '.':
                        count += 1
            if count == 4:
                print('No')
                exit()

print('Yes')

Solution (Python):
def main():
    from collections import deque

    h, w = map(int, input().split())
    q = deque([])
    buffer = ["." for _ in range(w + 2)]
    for _ in range(h):
        r = ["."] + list(input()) + ["."]
        while q:
            i = q.pop()
            if r[i] == '.':
                print("No")
                exit()

        for i, (x, y, z) in enumerate(zip(r, r[1:], r[2:])):
            if (x, y, z) == (".", "
                q.append(i + 1)

        buffer = r
    else:
        if q:
            print("No")
        else:
            print("Yes")


if __name__ == '__main__':
    main()

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

    m = []
    wall = ['.' for _ in range(w + 2)]
    m.append(wall)
    for _ in range(h):
        r = ["."] + list(input()) + ["."]
        m.append(r)
    m.append(wall)

    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if m[i][j] == '
                f = any([m[i + x][j + y] == "
                if not f:
                    print("No")
                    exit()
    else:
        print("Yes")


if __name__ == '__main__':
    main()

Solution (Python):
def gridChecker(grid):
    flag = True
    for r in range(H):
        for c in range(W):
            color = grid[r][c]
            if color == '
                if r == 0:
                    up = '_'
                else:
                    up = grid[r-1][c]
                if c == W-1:
                    right = '_'
                else :
                    right = grid[r][c+1]
                if r == H - 1:
                    down = '_'
                else :
                    down = grid[r+1][c]
                if c == 0:
                    left = '_'
                else :
                    left = grid[r][c-1]
                
                if '
                    flag = False
                    break
            
    return flag

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

grid = [[i for i in input()] for row in range(H)]

if gridChecker(grid):
    print('Yes')
else :
    print('No')

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

for i in range(1, h+1):
    s=input()
    for j in range(1, w+1):
        table[i][j]=s[j-1]


for i in range(1, h+1):
    for j in range(1, w+1):
        if table[i][j]=="
            if table[i][j-1]!="
                flag=1

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

Solution (Python):
h, w = map(int, input().split())
s = []
s.append(['.']*(w+2))
for i in range(1, h+1):
    t = input()
    u = ['.']
    for j in range(w):
        u.append(t[j])
    u.append('.')
    s.append(u)
s.append(['.']*(w+2))
key = True
d = [[0, -1], [0, 1], [-1, 0], [1, 0]]
flag = True
for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j] == '
            key = False
            for k in range(len(d)):
                if s[i+d[k][0]][j+d[k][1]] == '
                    key = True
            if not key:
                flag = False
                break
    if not flag:
        break
if flag:
    print("Yes")
else:
    print("No")

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

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

    for h in range(H):
        for w in range(W):
            if S[h][w] == '.':
                continue

            flag = False
            for x, y in zip(dx, dy):
                if 0 <= x+w < W and 0 <= y+h < H and S[y+h][x+w] == '
                    flag = True
                    break

            if not flag:
                print('No')
                return

    print('Yes')
    
main()

Solution (Python):
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
D = [(-1, 0), (1, 0), (0, -1), (0, 1)]
for h in range(H):
    for w in range(W):
        if S[h][w] == '
            
            for dy, dx in D:
                ny = h + dy
                nx = w + dx
                if ny < 0 or ny < 0:
                    continue
                if nx >= W or ny >= H:
                    continue
                
                if S[ny][nx] == '
                    break
            else:
                print('No')
                exit()
print('Yes')

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

frag="True"
dxy=[(1,0),(0,1),(0,-1),(-1,0)]
for y in range(H):
    for x in range(W):
        if s[y][x]==".": continue
        c=0
        for dx,dy in dxy:
            if x+dx<0 or x+dx>W-1 or y+dy<0 or y+dy>H-1:
                c+=1
                continue
            if s[y+dy][x+dx]==".":
                c+=1
        if c==4:
            print("No")
            exit()
print("Yes")

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

s =[]
s_w =[]

for i in range(H):
    s_t = input()
    s_w =[]
    for j in range(W):           
        s_w.append(s_t[j])
    s.append(s_w)

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

flag = True

for i in range(H):
    for j in range(W):
        
        if s[i][j] != "
            continue
        
        flag2 = False
        for k in range(len(dx)):
            ni = i + dy[k]
            nj = j + dx[k]
            if (ni<0 or H<=ni) or (nj<0 or W<=nj):
                continue
            
            
            if s[ni][nj] == "
                flag2 = True
                break
        
        if flag2 == False:
            flag = False
if flag == True:
    print("Yes")
else:
    print("No")

Solution (Python):
h,w = map(int,input().split())
s = [input() for _ in range(h)]
vec = {(-1, 0), (0, -1), (1,0), (0,1)}
for i in range(h):
  for j in range(w):
    if s[i][j] == '
      b = False
      for v in vec:
        ii = i+v[0]
        jj = j+v[1]
        if 0 <= ii <= h-1 and 0 <= jj <= w-1 and s[ii][jj] == '
          b = True
          break
      if not b:
        print('No')
        exit()
print('Yes')

Solution (Python):
from sys import stdin
from collections import deque

def dfs(ny,nx):
    d=deque([[ny,nx]])
    count=0
    while len(d)>0:
        now=d.pop()
        count+=1
        for dy,dx in (-1,0),(1,0),(0,-1),(0,1):
            y=now[0]+dy
            x=now[1]+dx
            if 0<=y<H and 0<=x<W:
                if flags[y][x]==False and grid[y][x]=="
                    d.append([y,x])
                flags[y][x]=True
    return count


readline=stdin.readline
H,W=map(int,readline().split())
grid=[]
for i in range(H):
    s=readline().strip()
    grid.append(s)

flags=[[False]*W for _ in range(H)]
answer=True
for y in range(H):
    for x in range(W):
        if flags[y][x]==True:
            continue
        elif grid[y][x]==".":
            flags[y][x]=True
        elif grid[y][x]=="
            flags[y][x]=True
            res=dfs(y,x)
            if res==1:
                answer=False
                break
    if answer==False:
        break

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

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

Solution (Python):
h, w = map(int, input().split())
s = [[i for i in input()] for j in range(h)]
flag = True
vecs = [(-1, 0), (0, 1), (1, 0), (0, -1)]
for i in range(h):
    for j in range(w):
        if s[i][j] == '
            vec_cnt, w_cnt = 0, 0
            for di, dj in vecs:
                if 0 <= i + di < h and 0 <= j + dj < w:
                    vec_cnt += 1
                    if s[i + di][j + dj] == '.':
                        w_cnt += 1
            if vec_cnt == w_cnt:
                flag = False
print('Yes' if flag else 'No')

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

flag = True
for i in range(h):
    for j in range(w):
        now = canvas[i][j]
        if now == '
            left = canvas[i][max(0, j - 1)]
            right = canvas[i][min(w - 1, j + 1)]
            up = canvas[max(0, i - 1)][j]
            down = canvas[min(h - 1, i + 1)][j]
            if left == right == up == down == '.':
                flag = False

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

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

dxdy = [(0,-1), (-1,0), (0,1), (1,0)]
for y, row in enumerate(s):
    for x, e in enumerate(row):
        if e=='.':
            continue
        for dx, dy in dxdy:
            if not (0<=x+dx<w and 0<=y+dy<h):
                continue
            if s[y+dy][x+dx]=='
                break
        else:
            print('No')
            break
    else:
        continue
    break
else:
    print('Yes')

Solution (Python):
import numpy as np
H,W = map(int,input().split())
table = []
for i in range(H):
    col = list(input())
    table.append(col)
table = np.array(table)
for i in range(1,H):
    for j in range(1,W):
        bubun = table[i-1:i+2,j-1:j+2]
        if bubun.shape != (3,3):
            continue
        center = bubun[1,1]
        if center == "
            print("No")
            exit()
        
print("Yes")

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

    return H,W,S

def kansu(LH,LW,LS):
    success_flg  = True

    for h in range (LH):
        for w in range(LW):
            if LS[h][w] == '
                if h != 0:
                    if LS[h-1][w] == '
                        continue
                if h != LH-1:
                    if LS[h+1][w] == '
                        continue
                if w != 0:
                    if LS[h][w-1] == '
                        continue
                if W != LW-1:
                    if LS[h][w+1] == '
                        continue
                success_flg = False
                break
            

    
    if success_flg == True:
        print("Yes")
    else:
        print("No")




H,W,S = nyu()
kansu(H,W,S)

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

Solution (Python):
A = [-1, 0, 0, 1]
B = [0, -1, 1, 0]


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

answer = "Yes"
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if GRID[i][j] == ".":
            continue
        flag = True
        for a, b in zip(A, B):
            if GRID[i + a][j + b] == "
                flag = False
        if flag:
            answer = "No"

print(answer)

Solution (Python):
h, w = map(int, input().split())
campus = [["."] * (w + 2)]

for _ in range(h):
    c = ["."] + list(input()) + ["."]
    campus.append(c)

campus.append(["."] * (w + 2))

draw = True

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if campus[i][j] == "

            if campus[i - 1][j] == "." and\
               campus[i][j - 1] == "." and\
               campus[i + 1][j] == "." and\
               campus[i][j + 1] == ".":
               draw = False

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

Solution (Python):

H,W=input().split()
H=int(H)
W=int(W)
s = [[0 for c in range(W)] for r in range(H)]

for r in range(H):
    tempH=input()
    for c in range(W):
        s[r][c]=tempH[c]

for r in range(H):
    for c in range(W):
        if s[r][c]=='
            if r!=0:
                if s[r-1][c]=='
                    continue 
            if r!=(H-1):
                if s[r+1][c]=='
                    continue 
            if c!=0:
                if s[r][c-1]=='
                    continue 
            if c!=(W-1):
                if s[r][c+1]=='
                    continue 
            
            print('No')
            break
    else:
        continue
    break
else:
    
    print('Yes')

Solution (Python):
from itertools import product
H, W = list(map(int, input().split()))
S = [input() for _ in range(H)]
can = True
S = ['.' * (W + 2)] + ['.' + s + '.' for s in S] + ['.' * (W + 2)]
S = [list(s) for s in S]
dHW = [[-1, 0], [1, 0], [0, -1], [0, 1]]
for h, w in product(range(1, H + 1), range(1, W + 1)):
    if S[h][w] == '
        exist = False
        for (dh, dw) in dHW:
            if S[h + dh][w + dw] == '
                exist = True
                break
        if exist:
            continue
        else:
            can = False
            break
if can:
    print('Yes')
else:
    print('No')

Solution (Python):

h, w = map(int, input().split())
b = ".";j = [b+b*w+b]
s = j + [b+input()+b for _ in [0]*h] + j
for i in range(1, h+1):
    d = [n+1 for n in range(w) if s[i][n:n+3] == ".
    if d and any([s[i-1][c] == s[i+1][c] == b for c in d]):
        print("No");exit()
print("Yes")

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

print("Yes")

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    H, W = map(int, input().split())
    S = ['']* H
    for i in range(H):
        S[i] = input()
    delta = [1, -1]
    ans = 'Yes'
    for i in range(H):
        for j in range(W):
            if S[i][j] == '
                bl = False
                for d in delta:
                    if 0<=i+d<H and S[i+d][j]=='
                        bl = True
                    if 0<=j+d<W and S[i][j+d]=='
                        bl = True
                if bl == False:
                    ans = 'No'
    print(ans)







if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
s = np.array(s)
s[s == '
s[s == '.'] = 0
s = s.astype(np.int)
S = np.pad(s, [1, 1], 'constant')

ans = 'Yes'
for i in range(H):
    for j in range(W):
        if s[i, j] == 1:
            if np.sum(S[i:i+3, j+1]) + np.sum(S[i+1, j:j+3]) == 2:
                ans = 'No'
    if ans == 'No':
        break
                
print(ans)

Solution (Python):
H,W = list(map(int,input().split()))
table = []
for i in range(H):
    table.append(list(input()))
for i in range(H):
    for j in range(W):
        A = table[i][j]
        if A == "
            try:
                if table[i-1][j] == "
                    continue
            except IndexError:
                pass
            try:
                if table[i+1][j] == "
                    continue
            except IndexError:
                pass
            try:
                if table[i][j-1] == "
                    continue
            except IndexError:
                pass
            try:
                if table[i][j+1] == "
                    continue
            except IndexError:
                pass
            print("No")
            exit()
        else:
            continue
print("Yes")

Solution (Python):
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    H, W = list(map(int,_in[0].split(' ')))  
    s_arr = []
    for i in range(H):
        _ = [_ for _ in _in[i+1]]   
        s_arr.append(_)
    
    TF = 'Yes'
    for i in range(H):
        if TF == 'Yes':
            for j in range(W):
                if s_arr[i][j] == '
                    adjacent = []
                    if i>0:   
                        if s_arr[i-1][j] == '
                            continue
                    if i<H-1: 
                        if s_arr[i+1][j] == '
                            continue
                    if j>0:   
                        if s_arr[i][j-1] == '
                            continue
                    if j<W-1: 
                        if s_arr[i][j+1] == '
                            continue
                    TF = 'No'
                    break
    
    print(TF)

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

def resolve():
    def main():
        H,W=map(int, input().split())
        grid=[list(input()) for i in range(H)]
        for h in range(H):
            for w in range(W):
                if grid[h][w]=='
                    for j,k in [0,1],[0,-1],[1,0],[-1,0]:
                        nh=h+j
                        nw=w+k
                        if nh<0 or nh>=H or nw<0 or nw>=W:
                            continue
                        else:
                            if grid[nh][nw]=='
                                break
                            else:
                                if [j,k]==[-1,0]:
                                    return 'No'
        return 'Yes'
    print(main())
resolve()

Solution (Python):
import sys
H, W = map(int, input().split())
li = []
li.extend(["."*(W+2)])
for i in range(H):
    li.extend(["."+input()+"."])
li.extend(["."*(W+2)])

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

Solution (Python):
h,w=map(int,input().split())
s=[input() for _ in range(h)]
dx=[1,0,-1,0]
dy=[0,1,0,-1]
for i in range(h):
    for j in range(w):
        c=0
        if s[i][j]==".":
            continue
        for d in range(4):
            ni=i+dy[d]
            nj=j+dx[d]

            if ni<0 or h<=ni:
                continue
            if nj<0 or w <=nj:
                continue
            if s[ni][nj]=="
                c=1
        if c==0:
            print("No")
            exit()
print("Yes")

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop

import collections

h,w = map(int,input().split())
li = ["."*(w+2)]
for i in range(h):
    in_data = input()
    data = "." + in_data + "."
    li.append(data)
li.append("."*(w+2))

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

Solution (Python):
H, W = map(int, input().split())
s = [list(input()) for i in range(H)]
dh = [-1, 0, 0, 1]
dw = [0, -1, 1, 0]
cnt = 0

for h in range(H):
  for w in range(W):
    
    if s[h][w] == '.':
      continue
    for k in range(4):
      nh = h + dh[k]
      nw = w + dw[k]
      if nh < 0 or nw < 0 or H <= nh or W <= nw:
        continue
      
      if s[nh][nw] == '
        break
    
    else:
      print('No')
      break
  else:
    continue
  break
else:
  print('Yes')

Solution (Python):
H, W = map(int, input().split())
s = [list(input()) for i in range(H)]
dh = [-1, 0, 0, 1]
dw = [0, -1, 1, 0]
cnt = 0

for h in range(H):
  for w in range(W):
    
    if s[h][w] == '.':
      continue
    for k in range(4):
      nh = h + dh[k]
      nw = w + dw[k]
      if nh < 0 or nw < 0 or H <= nh or W <= nw:
        continue
      
      if s[nh][nw] == '
        break
    
    else:
      cnt += 1

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