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())
area =[input() for i in range(h)]

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

for i in range(h):
  for j in range(w):
    if area[i][j] == '
      flag=0
      for x, y in xy:
        
        if 0 <= i + y < h and 0 <= j + x < w and area[i+y][j+x]=="
          flag=1
      if not flag:
        print('No')
        exit()
print('Yes')

Solution (Python):
import sys
H, W = map(int, input().split())
rows = []
for _ in range(0, H):
    rows.append(input())
x = [0,  0, 1, -1]
y = [1, -1, 0,  0]
for row_i in range(0, H):
    for col_i in range(0, W):
        if rows[row_i][col_i] != "
            continue
        flag = False
        for i in range(0, 4):
            dx = col_i + x[i]
            dy = row_i + y[i]
            if dx >= W or dx < 0 or dy >= H or dy < 0:
                continue
            if rows[dy][dx] == "
                flag = True
        if not flag:
            print ("No")
            sys.exit()
print ("Yes")

Solution (Python):
H, W = list(map(int, input().split()))
s = [input() for i in range(H)]
a = "
Ans = "Yes"
for i in range(H):
  for j in range(W):
    if s[i][j] == a:
      if i - 1 >= 0 and s[i - 1][j] == a: continue
      if i + 1 <= H - 1 and s[i + 1][j] == a: continue
      if j - 1 >= 0 and s[i][j - 1] == a: continue
      if j + 1 <= W - 1 and s[i][j + 1] == a: continue
      Ans = "No"
      break

print(Ans)

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

for i in range(0, h):
    s[i] = input()
    
def s_cor(i, j):
    global h, w
    if i < 0 or j < 0 or i >= h or j >= w:
        return False
    else:
        return s[i][j] == "

p = True
for i in range(0, h):
    for j in range(0, w):
        if s_cor(i, j) and (not s_cor(i - 1, j)) and (not s_cor(i, j - 1)) and (not s_cor(i + 1, j)) and (not s_cor(i, j + 1)):
            p = False
            break
    
if p:
    print("Yes")
else:
    print("No")

Solution (Python):
import sys
H,W = map(int,input().split())
lists= [[j for j in input()] for i in range(H)]
for l in lists:
    l.append(".")
    l.insert(0,".")
lists.insert(0,["."]*len(lists[0]))
lists.insert(len(lists),["."]*len(lists[0]))
check = True
for h in range(len(lists)):
    for w in range(len(lists[0])):
        if lists[h][w]=="
            if lists[h+1][w]!="
                print("No")
                sys.exit()
print("Yes")

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

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

Ses = []
for _ in range(H):
    Ses.append(input())

for y in range(H):
    for x in range(W):
        if Ses[y][x] == "
            found = False
            for dx, dy in OFFSETS:
                now_x = x+dx
                now_y = y+dy
                if now_x < 0 or now_x >= W:
                    continue
                if now_y < 0 or now_y >= H:
                    continue
                if Ses[now_y][now_x] == "
                    found = True
                    break
            if not found:
                print("No")
                exit()

print("Yes")

Solution (Python):
from itertools import product

H, W = map(int,input().split())
grid = [input() for i in range(H)]
colored_grid = ['.'*W for i in range(H)] 

for i,j in product(range(H),range(W)):
    if grid[i][j] == '
        colored_grid[i][j].replace('.','
        
        for x,y in product(range(-1,2),repeat=2): 
            if abs(x) + abs(y) == 2:
                continue
            if x == 0 and y == 0:
                continue
            if 0 <= i+x <= H-1 and 0 <= j+y <= W-1 and grid[i+x][j+y] == '
                colored_grid[i+x][j+y].replace('.','
                break 
        else: 
            colored_grid[i][j].replace('
            print('No')
            break
else:
    print('Yes')

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

H, W = LI()

rows = [['.' for i in range(W+2)]]
for i in range(H):
    row = input()
    chars = ['.']
    for w in range(W):
        chars.append(row[w])
    chars.append('.')
    rows.append(chars)
rows.append(['.' for i in range(W+2)])




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

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

def check(i, j, h, w, grid):
    flg = False
    lst = [(i-1, j), (i+1, j), (i, j-1), (i, j+1)]
    if i == 0:
        lst.remove((i-1, j))
    if j == 0:
        lst.remove((i, j-1))
    if i == h-1:
        lst.remove((i+1, j))
    if j == w-1:
        lst.remove((i, j+1))
    for tpl in lst:
        if grid[tpl[0]][tpl[1]] == '
            flg = True
    return flg

flg = True
for i in range(h):
    for j in range(w):
        if grid[i][j] == '
            if check(i, j, h, w, grid):
                pass
            else:
                flg = False
print('Yes') if flg else print('No')

Solution (Python):
H,W=map(int,input().split())
S=[list(input()) for _ in range(H)]
dist=[[0,1],[1,0],[-1,0],[0,-1]]
ans='Yes'

for h in range(H):
    for w in range(W):
        if S[h][w]=='
            for dh,dw in dist:
                if 0<=h+dh<=H-1 and 0<=w+dw<=W-1 and (S[h+dh][w+dw]=='
                    S[h+dh][w+dw]='o'
                    S[h][w]='o'

for s in S:
    if '
        ans='No'
        
print(ans)

Solution (Python):
H,W=map(int,input().split())
s=[]
s.append(['.']*(W+2))

for i in range(H):
    l=list(input())
    l.insert(0,'.')
    l.append('.')
    s.append(l)

s.append(['.']*(W+2))
flag=0
for i in range(H):
    for j in range(W):
        if s[i][j]=='
            flag=1
            break
if flag==1:
    print("No")
else:
    print("Yes")

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

hw = []
hw.append('.'*(W+2))
for _ in range(H):
    edited = input()
    edited = '.' + edited + '.'
    hw.append(edited)
hw.append('.'*(W+2))

for i in range(1,H+1):
    for j in range(1,W+1):
        if hw[i][j] == '
            
            if hw[i+1][j] == '.' and hw[i-1][j] == '.' and hw[i][j+1] == '.' and hw[i][j-1] == '.':
                print('No')
                quit()

print('Yes')

Solution (Python):
H, W = map(int, input().split())
l = []
l.append([input() for i in range(H)])
B = []
b = 0
m = 0
for i in range(H):
    for j in range(W):
        if l[0][i][j] == '
            B.append([i, j])
for i in B:
    for j in B:
        if i == j:
            pass
        elif i[0] == j[0] and i[1] - 1 <= j[1] <= i[1] + 1:
            m = 1
        elif i[0] - 1 <= j[0] <= i[0] + 1 and i[1] == j[1]:
            m = 1
        else:
            pass
    if m == 0:
        b = 1
        print('No')
        break
    else:
        m = 0
if b == 0:
    print('Yes')

Solution (Python):
H,W=(int(i) for i in input().split())
s=[input() for i in range(H)]
for i in range(H):
    for j in range(W):
        if s[i][j]=='
            if i==0 or s[i-1][j]=='.':
                if i==H-1 or s[i+1][j]=='.':
                    if j==0 or s[i][j-1]=='.':
                        if j==W-1 or s[i][j+1]=='.':
                            print('No')
                            exit()
print('Yes')

Solution (Python):
def solve(string):
    h, w, *s = string.split()
    h = int(h)
    w = int(w)
    for i in range(h):
        for j in range(w):
            if s[i][j] == ".":
                continue
            check = False
            if i > 0:
                check |= s[i][j] == s[i - 1][j]
            if i < h - 1:
                check |= s[i][j] == s[i + 1][j]
            if j > 0:
                check |= s[i][j] == s[i][j - 1]
            if j < w - 1:
                check |= s[i][j] == s[i][j + 1]
            if not check:
                return "No"
    return "Yes"


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

Solution (Python):
def solve(string):
    h, w, *s = string.split()
    h = int(h)
    w = int(w)
    for i in range(h):
        for j in range(w):
            if s[i][j] == ".":
                continue
            check = False
            if i > 0:
                check |= s[i][j] == s[i - 1][j]
            if i < h - 1:
                check |= s[i][j] == s[i + 1][j]
            if j > 0:
                check |= s[i][j] == s[i][j - 1]
            if j < w - 1:
                check |= s[i][j] == s[i][j + 1]
            if not check:
                return "No"
    return "Yes"


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

Solution (Python):
def solve(string):
    h, w, *s = string.split()
    h = int(h)
    w = int(w)
    for i in range(h):
        for j in range(w):
            if s[i][j] == ".":
                continue
            check = False
            if i == 0 == h - 1:
                pass
            elif i == 0:
                check |= s[i][j] == s[i + 1][j]
            elif i == h - 1:
                check |= s[i][j] == s[i - 1][j]
            else:
                check |= s[i][j] == s[i + 1][j] or s[i][j] == s[i - 1][j]
            if j == 0 == w - 1:
                pass
            elif j == 0:
                check |= s[i][j] == s[i][j + 1]
            elif j == w - 1:
                check |= s[i][j] == s[i][j - 1]
            else:
                check |= s[i][j] == s[i][j + 1] or s[i][j] == s[i][j - 1]
            if not check:
                return "No"
    return "Yes"


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

Solution (Python):
H, W = map(int, input().split())
mat = [input() for i in range(H)]
mat_t = [''.join(x) for x in zip(*mat)]
def check(mat, t):
    stack = set()
    for i, string in enumerate(mat):
        string = '.' + string + '.'
        for j in range(len(string)):
            if j+3<=len(string):
                if string[j:j+3] == '.
                    if t==False:
                        stack.add((i, j))
                    else:
                        stack.add((j, i))
    return stack

stack1 = check(mat, False)
stack2 = check(mat_t, True)
if stack1 & stack2:
    print('No')
else:
    print('Yes')

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

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

for i in range(H):
    for j in range(W):
        if s[i][j] == '
            for k in range(4):
                if 0 <= i+dy[k] < H and 0 <= j+dx[k] < W:
                    
                    loop_num += 1
                    if s[i+dy[k]][j+dx[k]] == '.':
                        
                        count += 1
            
            if count == loop_num:
                flag = None
                break
            else:
                count = 0
                loop_num = 0
        else:
            pass
    if flag == None:
        break

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

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

mat = []
for i in range(h):
    mat.append(input())
def outrange(i,j,h,w):
    if i<0 or i>=h:
        return True
    if j<0 or j>=w:
        return True
    return False
for i in range(h):
    for j in range(w):
        if mat[i][j] == '.':
            continue
        
        if not outrange(i-1,j,h,w) and mat[i-1][j]=='
            continue
        if not outrange(i,j-1,h,w) and mat[i][j-1]=='
            continue
        if not outrange(i+1,j,h,w) and mat[i+1][j]=='
            continue
        if not outrange(i,j+1,h,w) and mat[i][j+1]=='
            continue

        print("No")
        exit(0)
print("Yes")

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(1, H+1):
    for j in range(1, W+1):
        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')
                break
    else:
        continue
    break
else:
    print('Yes')

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

def check(i, j):
    if g[i][j] == '.':
        return True
    lis = [[-1, 0], [0, -1], [0, 1], [1, 0]]
    f = 0
    for k in lis:
        rh = i + k[0]
        rw = j + k[1]
        if 0 <= rh <= h - 1 and 0 <= rw <= w - 1:
            if g[rh][rw] == '
                return True
    if f == 0:
        return False

for i in range(h):
    for j in range(w):
        if not check(i, j):
            print('No')
            exit()

print('Yes')

Solution (Python):

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

s = [[0] * (W+2) for i in range(H+2)]
for h in range(H):
    for w in range(W):
        s[h+1][w+1] = S[h][w]

c = [[0] * (W+2) for i in range(H+2)]
for h in range(1,H+1):
    for w in range(1,W+1):
        if s[h][w] == '
            if s[h][w-1] == '
                c[h][w] += 1
                c[h][w-1] +=1
            if s[h][w+1] == '
                c[h][w] += 1
                c[h][w+1] +=1
            if s[h+1][w] == '
                c[h][w] += 1
                c[h+1][w] +=1
            if s[h-1][w] == '
                c[h-1][w] += 1
                c[h-1][w] +=1

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

Solution (Python):
def printField(l):
    h = len(l)
    w = len(l[0])
    for i in range(h):
        for j in range(w):
            print(l[i][j], end='')
        print()


h, w = map(int, input().split())
l = [list(input()) for _ in range(h)]


for i in range(h):
        for j in range(w -1):
            if (l[i][j] != '.' and l[i][j+1] != '.'):
                l[i][j] = '$'
                l[i][j+1] = '$'



for j in range(w):
    for i in range(h -1):
        if (l[i][j] != '.' and l[i + 1][j] != '.'):
            l[i][j] = '$'
            l[i + 1][j] = '$'


flag = False
for sl in l:
    for s in sl:
        if s == '
            flag = True
            break
    if flag:
        break

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

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

diff = [[-1, 0], [1, 0], [0, -1], [0, 1]]
def is_isolated(y, x):
    if Sij[y][x] != "
        return False
    for d in diff:
        y2 = y + d[0]
        x2 = x + d[1]
        if y2 >= 0 and y2 < H and x2 >= 0 and x2 < W:
            if Sij[y2][x2] == "
                return False
    return True

out = "Yes"
for y in range(H):
    for x in range(W):
        if is_isolated(y, x):
            out = "No"
            break
print(out)

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] == "
      d = set()
      if i>0:
        d.add(s[i-1][j])
      if i<h-1:
        d.add(s[i+1][j])
      if j>0:
        d.add(s[i][j-1])
      if j<w-1:
        d.add(s[i][j+1])
      if "
        print("No")
        exit()
print("Yes")

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

for i in range(h):
	for j in range(w):
		if s[i][j] == '.':
			continue
		
		mawari = []
		if i != 0:
			mawari.append(s[i-1][j])
		if i != h-1:
			mawari.append(s[i+1][j])
		if j != 0:
			mawari.append(s[i][j-1])
		if j != w-1:
			mawari.append(s[i][j+1])
		if '
			answer = 'No'
			break

print(answer)

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

for i in range(H):
    for j in range(W):
        edge0 = (i == 0)
        edge1 = (i == H - 1)
        edge2 = (j == 0)
        edge3 = (j == W - 1)
        x = j
        if S[i][j] == "
            if (S[i - 1][j] == "
                    (S[i + 1][j] == "
                    (S[i][j - 1] == "
                    (S[i][j + 1] == "
                continue
            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)]

def judge():
    for i in range(H):
        for j in range(W):
            if s[i][j] == '.':
                continue
            periphery = []
            if i != 0:
                periphery.append(s[i - 1][j])
            if i != H - 1:
                periphery.append(s[i + 1][j])
            if j != 0:
                periphery.append(s[i][j - 1])
            if j != W - 1:
                periphery.append(s[i][j + 1])
            if '
                return False
    return True

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

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

for i in range(H):
    for j in range(W):
        if field[i][j] == '.':
            continue
        inflag = False
        for k in range(4):
            ni = i + dx[k]
            nj = j + dy[k]
            if ni < 0 or ni >= H or nj < 0 or nj >= W:
                continue
            elif field[ni][nj] == '
                inflag = True
        flag.append(inflag)

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

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

for i in range(H):
    for j in range(W):
        if field[i][j] == '.':
            continue
        inflag = False
        for k in range(4):
            ni = i + dx[k]
            nj = j + dy[k]
            if ni < 0 or ni >= H or nj < 0 or nj >= W:
                continue
            elif field[ni][nj] == '
                inflag = True
        flag.append(inflag)

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

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

for i in range(H):
    for j in range(W):
        if field[i][j] == '
            inflag = [False] * 4
            for k in range(4):
                ni = i + dx[k]
                nj = j + dy[k]
                if ni < 0 or ni >= H or nj < 0 or nj >= W:
                    inflag[k] = False
                elif field[ni][nj] == '
                    inflag[k] = True
            flag.append(any(inflag))
        elif field[i][j] == '.':
            flag.append(True)

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

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

def check(h,w):
  return S[h-1][w] == "
         S[h+1][w] == "
         S[h][w-1] == "
         S[h][w+1] == "

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

Solution (Python):
class UnionFind:
    def __init__(self, N:int):
        """N: 大きさ
        size: 連結成分の大きさ
        """
        self.par = [i for i in range(N)]
        self.size = [1]*N
        self.rank = [1]*N
        
    def root(self, x:int)->int:
        """根を求める"""
        if self.par[x] == x: 
            return x
        else:
            self.par[x] = self.root(self.par[x]) 
            return self.par[x]
        
    def is_same(self, x:int, y:int)->bool:
        """x と y が同じ集合に属するか否か"""
        return self.root(x)==self.root(y)
    
    def unite(self, x:int, y:int):
        """y を x の属する集合に併合"""
        root_x = self.root(x)
        root_y = self.root(y)
        if root_x == root_y: return
        if self.rank[root_x] == self.rank[root_y]:
            self.rank[root_x] += 1
        elif self.rank[root_x]<self.rank[root_y]:
            root_x,root_y = root_y,root_x
        
        self.par[root_y] = root_x
        self.size[root_x] += self.size[root_y]
        self.size[root_y] = 0 
        
    def get_size(self, x:int)->int:
        """xの属するグループのサイズ"""
        return self.size[self.root(x)]

H,W = map(int, input().split())
grid = [input() for _ in range(H)]
uf = UnionFind(H*W)
for h in range(H):
    for w in range(W):
        for i,j in zip([0,0,1,-1], [1,-1,0,0]):
            if not (0 <= h+i < H and 0 <= w+j < W): 
                continue
            if grid[h][w]=="
                uf.unite(h*W + w, (h+i)*W + w+j) 
                
        

ans = "Yes"
for h in range(H):
    for w in range(W):
        if grid[h][w]=="
            if uf.get_size(h*W + w)<2:
                ans = "No"
print(ans)

Solution (Python):


import sys


def solve(sn,h,w):
  for i in range(1,h+1):
    for j in range(1,w+1):
      if sn[i][j] > 0:
        if sn[i-1][j] + sn[i+1][j] + sn[i][j-1] + sn[i][j+1] == 0:
          return False
  return True



H,W = map(int, input().split())
Sn = []
Sn.append([0]*(W+2))
for _ in range(H):
  s_in = str(input())
  lst = [0] * (W+2)
  for i in range(len(s_in)):
    if s_in[i] == '
      lst[i+1] = 1
  Sn.append(lst)
Sn.append([0]*(W+2))

if solve(Sn,H,W):
  print("Yes")
else:
  print("No")

Solution (Python):
import sys

H, W = map(int, input().split())
S = [list(input()) for i in range(H)]
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]

for i in range(H):
    for j in range(W):
        if(S[i][j]=="."):
            continue
        exist = False
        for k in range(4):
            if(0<=i+dy[k]<H and 0<=j+dx[k]<W and S[i+dy[k]][j+dx[k]]=="
                exist = True
        if(exist==False):
            print("No")
            sys.exit()     
print("Yes")

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

Solution (Python):
import sys
h, w = map(int, input().split())
s = [input() for _ in range(h)]
dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]

for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            continue
        flag = 0
        for k in range(4):
            dh = i + dy[k]
            dw = j + dx[k]
            
            if 0 <= dh < h and 0 <= dw < w and s[dh][dw] == '
                flag = 1
        if flag == 0:
            print('No')
            sys.exit()
print('Yes')

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

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

for i in range(h):
    for j in range(w):
        if S[i][j] == '.':
            continue
        else:
            count = 0
            for k in range(4):
                    if not 0<=i+dy[k]<h or not 0<=j+dx[k]<w:
                        continue
                    if S[i+dy[k]][j+dx[k]] == '
                        count += 1
            if count == 0:
                print('No')
                exit()

print('Yes')

Solution (Python):
import sys

a = list(map(int,input().split()))
H = a[0]
W = a[1]
board = [["d" for j in range(W+2)] for i in range(H+2)]
for i in range(H):
    temp = input()
    for j in range(W):
        board[i+1][j+1] = temp[j]


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

Solution (Python):

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

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


def main():
    for y in range(H):
        for x in range(W):

            if s[y][x] == '.':
                continue

            cnt = 0

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

                if ny < 0 or H <= ny\
                        or nx < 0 or W <= nx\
                        or s[ny][nx] == '.':
                    continue

                cnt += 1

            if cnt == 0:
                print("No")
                return

    print("Yes")
    return


main()

Solution (Python):
H, W = map(int, input().split())
s = []
s.append(['.' for _ in range(W+2)])
for i in range(H):
    si = list(input())
    si = ['.'] + si + ['.']
    s.append(si)
s.append(['.' for _ in range(W+2)])
flag = True
for h in range(1,H+1):
    for w in range(1,W+1):
        if s[h][w] == '
            if s[h-1][w]=='.' and s[h+1][w]=='.' and s[h][w+1]=='.' and s[h][w-1]=='.' :
                flag = False

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

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

flg = True
for j in range(h):
    for i in range(w):
        if e[j][i] == ".":
            continue
        if i != 0 and e[j][i-1] == "
            continue
        if j != 0 and e[j-1][i] == "
            continue
        if i != w-1 and e[j][i+1] == "
            continue
        if j != h-1 and e[j+1][i] == "
            continue
        flg = False
        break

    if not flg:
        break

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

Solution (Python):
H,W = map(int,input().split())
s = [input() for i in range(H)]
precount = 0
for i in range(H):
    precount += s[i].count("
if precount == 0:
    print("Yes")
else:
    ans = "Yes"
    dx = [1,0,-1,0]
    dy = [0,1,0,-1]
    for i in range(H):
        for j in range(W):
            if s[i][j] == "
               count = 0
               for k in range(4):
                   nx = j+dx[k]
                   ny = i+dy[k]
                   if 0 <= nx < W and 0 <= ny < H:
                      if s[ny][nx] == "
                         count += 1
               if count == 0:
                  ans = "No"

    print(ans)

Solution (Python):
def solve():
    H,W=map(int,input().split())
    s=[]
    s.append(['.'] * (W+2))
    for y in range(H):
        s.append(['.'] + list(input()) + ['.'])
    s.append(['.'] * (W+2))
    for y in range(1,H):
        for x in range(1,W):
            if s[y][x] == '
                if s[y-1][x] == '.' and \
                   s[y+1][x] == '.' and \
                   s[y][x-1] == '.' and \
                   s[y][x+1] == '.':
                   return 'No'
    return 'Yes'

print(solve())

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

checktile = [[0] * H] * W

flg = True
for i in range(H):
    for j in range(W):
        tempflg = False
        if tile[i][j] == "
                
            if j < W -1:
                if tile[i][j+1] == "
                    tempflg = True
                
            if i < H -1:
                if tile[i+1][j] == "
                    tempflg = True
            
            if i > 0:
                if tile[i-1][j] == "
                    tempflg = True
            
            if j > 0:
                if tile[i][j-1] == "
                    tempflg = True
            if tempflg == False:
                
                flg = False
                
print("Yes" if flg else "No")

Solution (Python):
def grid_repeating2(H: int, W: int, S: list) -> bool:
    """マスに塗っていい回数の上限がないので、上下左右に黒ます
    がひとつでもあれば OK。つまり、孤立点の有無で判断すればよ
    い。
    """
    for h in range(H):
        for w in range(W):
            if S[h][w] == '.':
                
                continue
            
            if w > 0 and S[h][w-1] == '
                continue
            if w+1 < W and S[h][w+1] == '
                continue
            if h > 0 and S[h-1][w] == '
                continue
            if h+1 < H and S[h+1][w] == '
                continue

            
            return False
    return True


if __name__ == "__main__":
    H = 0
    W = 0
    H, W = map(int, input().split())
    S = [input() for _ in range(H)]
    yes = grid_repeating2(H, W, S)
    print('Yes' if yes else 'No')

Solution (Python):
H,W = map(int,input().split())
L = []
for i in range(H):
  L.append(list(input()))
dy_dx = [[1,0],[-1,0],[0,1],[0,-1]]
cnt = 0
for i in range(H):
  for j in range(W):
    d = 0
    if L[i][j] == '
      for p in range(4):
        if 0 <= i+dy_dx[p][0] <= H-1 and 0 <= j+dy_dx[p][1] <= W-1:
          if L[i+dy_dx[p][0]][j+dy_dx[p][1]] == '.':
            d += 1
      if 1 <= i <= H-2 and 1 <= j <= W-2:
        if d == 4:
          cnt += 1
      elif (i == 0 and j == 0) or (i == 0 and j == W-1) or (i == H-1 and j == 0) or (i == H-1 and j == W-1):
        if d == 2:
          cnt += 1
      else:
        if d == 3:
          cnt += 1
if cnt == 0:
  print('Yes')
else:
  print('No')