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 bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    h,w = LI()
    board = [["." for _ in range(w+2)]]
    for _ in range(h):
        line = list(S())
        board.append(["."] + line + ["."])
    board.append(["." for _ in range(w+2)])
    table = [[False]*(w+2) for _ in range(h+2)]
    exp = [[1,0],[0,1],[-1,0],[0,-1]]

    for i in range(h+2):
        for j in range(w+2):
            if board[i][j] == ".":
                table[i][j] = True
            else:
                for x,y in exp:
                    if board[i+x][j+y] == "
                        table[i][j] = True
    from functools import reduce
    def kakeru(lst):
        return reduce(lambda x,y: x and y,lst)
    ans = True
    for line in table:
        ans &= kakeru(line)
    print("Yes" if ans else "No")
main()

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

def judge(i,j,s,H,W):
    find=False
    dh=[0,1,0,-1]
    dw=[1,0,-1,0]
    for n in range(4):
        if 0<=i+dh[n]<=H-1 and 0<=j+dw[n]<=W-1:
            if s[i+dh[n]][j+dw[n]]=="
                find=True
                break
    return find

def main():
    end=False
    for i in range(H):
        if end==True:
            break
        for j in range(W):
            if s[i][j]=="
                if not judge(i,j,s,H,W):
                    print("No")
                    end=True
                    break
    if end==False:
        print("Yes")
if __name__=="__main__":
	main()

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

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):
H,W = map(int,input().split())
S = ["."*(W+2)]+["."+input()+"." for h in range(H)]+["."*(W+2)]

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):
H,W = map(int,input().split())
S = ["."*(W+2)]+["."+input()+"." for h in range(H)]+["."*(W+2)]

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

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

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):
h,w=map(int,input().split())
S=[]
for i in range(h):
    S.append(list(input()))
dx=[1,0,-1,0]
dy=[0,1,0,-1]
for i in range(1,h-1):
    for j in range(1,w-1):
        if S[i][j]=='
            if all(S[i+dx[k]][j+dy[k]]=='.' for k in range(4)):
                print("No")
                exit()
print("Yes")

Solution (Python):
h, w = list(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] == "
            sub_flag = False
            if i > 0 and s[i-1][j] == "
                sub_flag = True
            if j > 0 and s[i][j-1] == "
                sub_flag = True
            if i < h-1 and s[i+1][j] == "
                sub_flag = True
            if j < w-1 and s[i][j+1] == "
                sub_flag = True

            if sub_flag:
                pass
            else:
                flag = False
                break

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

Solution (Python):
H,W = map(int,input().split())
pict = [input() for i in range(H)]
for i in range(H):
    for j in range(W):
        if pict[i][j] == '
            flag = False
            for x,y in ((i-1,j),(i+1,j),(i,j-1),(i,j+1)):
                if 0<=x<H and 0<=y<W and pict[x][y]=='
                    flag = True
                    break
            if flag == False:
                print('No')
                exit(0)
print('Yes')

Solution (Python):
H, W = map(int, input().split())
S = [input() for _ in range(H)]
t = [(0, 1), (0, -1), (1, 0), (-1, 0)]
ans = True
for h in range(H):
    for w in range(W):
        if S[h][w] == '
            for h1, w1 in t:
                h2 = h1 + h
                w2 = w1 + w
                if H <= h2 or W <= w2 or h2 < 0 or w2 < 0:
                    continue
                if S[h2][w2] == '
                    break
            else:
                ans = False
print('Yes' if ans else 'No')

Solution (Python):
H,W=map(int,input().split())
s=[input() for _ in range(H)]
S=[]
S.append(['.' for _ in range(W+2)])
for i in range(H):
    s[i]='.'+s[i]+'.'
    S.append(list(s[i]))
S.append(['.' for _ in range(W+2)])
ans=True
for i in range(1,H+1):
    for j in range(1,W+1):
        if S[i][j]=='
            flag=False
            for k in range(-1,2,2):
                if S[i+k][j]=='
                    flag=True
                    break
            if flag==False:
                ans=False
                break
    else:
        continue
    break
if ans:
    print("Yes")
else:
    print("No")

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

ss=[['' for j  in range(W+2)]for i in range(H+2)]
for i in range(H):
    for j in range(W):
        ss[i+1][j+1]=s[i][j]

for i in range(H):
    for j in range(W):
        if ss[i][j]=='
            if ss[i][j-1]=='
                continue
            else:
                print('No')
                exit()
print('Yes')

Solution (Python):
import math
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7





H,W = LI()
S = [list(_S()) for _ in range (H)]

def check(x, y):
    
    res = False
    
    dxs = [-1,1]
    dys = [-1,1]
    for dx in dxs:
        nx = x + dx
        ny = y
        if 0 <= nx and nx < H and S[nx][ny] == "
            res = True
    for dy in dys:
        nx = x
        ny = y + dy
        if 0 <= ny and ny < W and S[nx][ny] == "
            res = True
    return res

for i in range(H):
    for j in range(W):
        if S[i][j] == "
            if not check(i,j):
                print('No')
                exit()

print('Yes')

Solution (Python):

H, W=map(int,input().split())
s=[[0]*(W+2) for i in range(H+2)]
for ii in range(1,H+1):
    A=list(input())
    for jj in range(1,W+1):
        if A[jj-1]=='
            s[ii][jj]=1
can=1
for ii in range(1,H+1):
    for jj in range(1,W+1):
        if s[ii][jj]==1:
            if s[ii-1][jj]+s[ii+1][jj]+s[ii][jj-1]+s[ii][jj+1]==0:
                can=0
                break
    if can==0:
        break

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

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    H, W = LI()
    s = [SS() for _ in range(H)]

    d = ((1, 0), (0, 1), (-1, 0), (0, -1))

    def dfs(cy, cx, tmp):
        tmp.append((cy, cx))
        visited[cy][cx] = True
        for dy, dx in d:
            ny = cy + dy
            nx = cx + dx
            if 0 <= ny < H and 0 <= nx < W and s[ny][nx] == '
                dfs(ny, nx, tmp)

    
    is_ok = True
    visited = [[False] * W for _ in range(H)]
    for i, j in itertools.product(range(H), range(W)):
        if s[i][j] == '
            tmp = []
            dfs(i, j, tmp)
            if len(tmp) == 1:
                is_ok = False
                break

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

if __name__ == '__main__':
    resolve()

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

Solution (Python):
def main():
    H, W = map(int, input().split())
    s = [list(input()) for _ in range(H)]
    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

            cnt = 0
            for k in range(4):
                x = j + dx[k]
                y = i + dy[k]
                if x >= 0 and x < W and y >= 0 and y < H:
                    if s[y][x] == "
                        cnt += 1

            if cnt == 0:
                flag = False

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


if __name__ == "__main__":
    main()

Solution (Python):


h, w = list(map(int, input().split()))
s = [list(str(input())) for i in range(h)]

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

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

for y in range(h):
    for x in range(w):
        if s[y][x] == '.':
            continue
        if y > 0 and s[y - 1][x] == '
            continue
        if y < h - 1 and s[y + 1][x] == '
            continue
        if x > 0 and s[y][x - 1] == '
            continue
        if x < w - 1 and s[y][x + 1] == '
            continue
        print('No')
        exit(0)
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] == "
            temp = set()
            if i != 0:
                temp.add(S[i-1][j])
            if i != H-1:
                temp.add(S[i+1][j])
            if j != 0:
                temp.add(S[i][j-1])
            if j != W-1:
                temp.add(S[i][j+1])
            if temp == set("."):
                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] == "
            temp = set()
            if i != 0:
                temp.add(S[i-1][j])
            if i != H-1:
                temp.add(S[i+1][j])
            if j != 0:
                temp.add(S[i][j-1])
            if j != W-1:
                temp.add(S[i][j+1])
            if temp == set("."):
                print("No")
                exit()

print("Yes")

Solution (Python):
H, W = map(int, input().split())
s = list(list(input()) for _ in range(H))
ans = True
d = [(0,1),(0,-1),(1,0),(-1,0)]
for y in range(H):
    for x in range(W):
        if s[y][x] == "
            for dy, dx in d:
                ny = y + dy
                nx = x + dx
                if ny<0 or H<=ny or nx<0 or W<=nx:
                    continue
                if s[ny][nx]=="
                    break
            else:
                ans = False
print("Yes" if ans else "No")

Solution (Python):



import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 3
.

.
        output = """Yes"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """5 5

.

.

        output = """No"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """11 11
...
.




.
.

..
.
        output = """Yes"""
        self.assertIO(input, output)


def resolve():
    H, W = map(int, input().split())
    S = [["."] * (W+2) for _ in range(H+2)]
    for i in range(H):
        S[i+1][1:W+1] = list(".") + list(input())

    ans = "Yes"
    for i in range(1, H+2):
        for j in range(1, W+2):
            if S[i][j] == "
                if S[i-1][j] == "." and S[i][j-1] == "." and S[i][j+1] == "." and S[i+1][j] == ".":
                    ans = "No"
                    break

    print(ans)


if __name__ == "__main__":
    
    resolve()

Solution (Python):
def main():
    h, w = map(int, input().split())
    inlis = list()
    for _ in range(h):
        alis = list(input())
        inlis.append(alis)
    
    for i in range(h):
        for j in range(w):
            if inlis[i][j] == "
                tmp = 0
                if i+1 < h:
                    if inlis[i+1][j] != "
                        tmp += 1
                else:
                    tmp += 1
                if j+1 < w:
                    if inlis[i][j+1] != "
                        tmp += 1
                else:
                    tmp += 1
                if j-1 >= 0:
                    if  inlis[i][j-1] != "
                        tmp += 1
                else:
                    tmp += 1
                if i-1 >= 0:
                    if inlis[i-1][j] != "
                        tmp += 1
                else:
                    tmp += 1
                       
                if tmp == 4:
                    print("No")
                    exit()
    print('Yes')
        




if __name__ == "__main__":
    main()

Solution (Python):
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
ans = [[0]*w for _ in range(h)]
def dfs(x,y):
    if 0 <= x < h and 0 <= y < w:
        if s[x][y] == "
            ans[x][y] = 1 
            
for i in range(h):
    for j in range(w):
        if s[i][j] == '
            dfs(i+1, j)
            dfs(i, j+1)
            dfs(i, j-1)
            dfs(i-1, j)
for i in range(h):
    for j in range(w):
        if s[i][j] == '
            if ans[i][j]!=1:
                print("No")
                exit()
print("Yes")

Solution (Python):
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
ans = [[0]*w for _ in range(h)]
cnt=0
def dfs(x,y):
    if 0 <= x < h and 0 <= y < w:
        if s[x][y] == "
            ans[x][y] = 1 
            

for i in range(h):
    for j in range(w):
        if s[i][j] == '
            dfs(i+1, j)
            dfs(i, j+1)
            dfs(i, j-1)
            dfs(i-1, j)
        cnt=0
for i in range(h):
    for j in range(w):
        if s[i][j] == '
            if ans[i][j]!=1:
                print("No")
                exit()
print("Yes")

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

for i in range(h):
    for j in range(w):
        if grid[i][j] == ".":
            continue

        check = []
        if j != 0:
            check.append([i, j-1])
        if j != w-1:
            check.append([i, j+1])
        if i != 0:
            check.append([i-1, j])
        if i != h-1:
            check.append([i+1, j])

        p = False
        for c in check:
            if grid[c[0]][c[1]] == "
                p = True
                break

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

print("Yes")

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

for i in range(H):
    for j in range(W):
        if s[i][j] == "
            for d in range(4):
                ni = i + dy[d]
                nj = j + dx[d]
                if ni < 0 or ni >= H:
                    continue
                if nj < 0 or nj >= W:
                    continue
                if s[ni][nj] == "
                    break
            else:
                break
            continue
    else:
        continue
    print("No")
    break
else:
    print("Yes")

Solution (Python):
H, W = map(int, input().split(' '))
S = []
for i in range(H):
  S.append(input())
 
dj = [-1, 0, 0, 1]
dk = [0, -1, 1, 0]
flug = []
for j in range(H):
  for k in range(W):
    judge = 'No'
    if S[j][k] == '.':
      judge = 'Yes'
    if S[j][k] == '
      for d in range(4):
        if 0 <= j+dj[d] <= H-1:
          if 0 <= k+dk[d] <= W-1:
            if S[j+dj[d]][k+dk[d]] == '
              judge = 'Yes'
      if judge == 'No':
        flug.append(0)
if 0 in flug:
  print('No')
else:
  print('Yes')

Solution (Python):
H, W = map(int, input().split())
s = []
s.append(["."]*(W+2))
for _ in range(H):
    string = input()
    string = "." + string + "."
    s.append(list(string))
s.append(["."]*(W+2))
ans = True
for row in range(1, H+1):
    for col in range(1, W+1):
        if s[row][col] == "
            is_ok = False
            for dh, dw in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
                if s[row+dh][col+dw] == "
                    is_ok = True
                    break
            if not is_ok:
                ans = False
                break
if ans:
    print("Yes")
else:
    print("No")

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

d = [-1, 1]
for h in range(H):
    for w in range(W):
        if S[h][w] == '
            ls = []
            for i in range(2):
                for j in range(2):
                    hs = h + d[i]
                    ws = w + d[j]
                    if 0 <= hs < H and 0 <= ws < W:
                        ls.append(S[hs][w])
                        ls.append(S[h][ws])
            if '
                print('No')
                exit()
print('Yes')

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

d = [-1, 1]
for h in range(H):
    for w in range(W):
        if S[h][w] == '
            ls = []
            for i in range(2):
                for j in range(2):
                    hs = h + d[i]
                    ws = w + d[j]
                    if 0 <= hs < H and 0 <= ws < W:
                        ls.append(S[hs][w])
                        ls.append(S[h][ws])
            if '
                print('No')
                exit()
print('Yes')

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

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

for i in range(1,h+1):
  for j in range(1,w+1):
    if lst[i][j]=='
      judge=False
      for k in range(4):
        nx=i+dx[k]
        ny=j+dy[k]
        if lst[nx][ny]=='
          judge=True
          
      if judge==False:
        print('No')
        exit()
        
print('Yes')

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

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

ans=True
for h in range(H):
    for w in range(W):
        if (S[h][w]=='
            f=False
            for dh,dw in D:
                h2=h+dh
                w2=w+dw
                if h2<0 or H<=h2 or w2<0 or W<=w2: continue
                if S[h2][w2]=='
                    f=True
                    break
            else:
                ans=False
print('Yes' if ans else 'No')

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

dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]
for i in range(h):
    for j in range(w):
        if maze[i][j] == '
            flag = False
            for k in range(4):
                nx = i + dx[k]
                ny = j + dy[k]
                if nx >= 0 and nx < h and ny >= 0 and ny < w and maze[nx][ny] == '
                    flag = True
                    break
            if not flag:
                print('No')
                sys.exit()
print('Yes')

Solution (Python):
H, W = map(int, input().split())
s = ['.'+input()+'.' for _ in range(H)]
s.insert(0,'.'*(W+2))
s.append('.'*(W+2))
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())
gazo = []
for i in range(h):
    s = str(input())
    s_i = []
    s_i.append(s[0])
    for j in range(1,w):
        if s[j] == '.':
            s_i.append(s[j])
        else:
            if s[j-1]=='
                s_i[j-1]='-'
                s_i.append('-')
            elif s[j-1]=='-' and s[j]=='
                s_i.append('-')
            else:
                s_i.append(s[j])
    gazo.append(s_i)

for j in range(0,w):
    for i in range(1,h):
        if gazo[i-1][j]=='
            gazo[i-1][j]='-'
            gazo[i][j]='-'
        elif gazo[i-1][j]=='-' and gazo[i][j]=='
            gazo[i][j]='-'
        elif gazo[i-1][j]=='
            gazo[i-1][j]='-'


isError = False
for i in range(h):
    for j in range(w):
        if gazo[i][j]=='
            isError = True
            break

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

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

fail = 0

for i in range(H):
  for j in range(W):
    if i == 0:
      if j == 0:
        if s[i][j] == '.':
          pass
        elif s[i][min(W-1,j+1)] == '
          pass
        else:
          fail += 1
      elif j == W - 1:
        if s[i][j] == '.':
          pass
        elif s[i][max(0,j-1)] == '
          pass
        else:
          fail += 1
      else:
        if s[i][j] == '.':
          pass
        elif s[i][j-1] == '
          pass
        else:
          fail += 1
    elif i == H - 1:
      if j == 0:
        if s[i][j] == '.':
          pass
        elif s[i][min(W-1,j+1)] == '
          pass
        else:
          fail += 1
      elif j == W - 1:
        if s[i][j] == '.':
          pass
        elif s[i][max(0,j-1)] == '
          pass
        else:
          fail += 1
      else:
        if s[i][j] == '.':
          pass
        elif s[i][j-1] == '
          pass
        else:
          fail += 1
    else:
      if j == 0:
        if s[i][j] == '.':
          pass
        elif s[i-1][j] == '
          pass
        else:
          fail += 1
      elif j == W - 1:
        if s[i][j] == '.':
          pass
        elif s[i-1][j] == '
          pass
        else:
          fail += 1
      else:
        if s[i][j] == '.':
          pass
        elif s[i-1][j] == '
          pass
        else:
          fail += 1
          
isAllWhite = False
count = 0
for i in range(H):
  for j in range(W):
    if s[i][j] == '.':
      count += 1
else:
  if count == H * W:
    isAllWhite = True
    
  if isAllWhite or fail == 0:
    print('Yes')
  else:
    print('No')

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

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

print('Yes')

Solution (Python):
LI = lambda: list(map(int, input().split()))

H, W = LI()
S = [input() for _ in range(H)]


def main():
    for i in range(H):
        for j in range(W):
            if S[i][j] == ".":
                continue
            if j > 0 and S[i][j - 1] == "
                continue
            if j < W - 1 and S[i][j + 1] == "
                continue
            if i > 0 and S[i - 1][j] == "
                continue
            if i < H - 1 and S[i + 1][j] == "
                continue
            print("No")
            return
    print("Yes")


if __name__ == "__main__":
    main()

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

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] == '.':
                print('No')
                exit()

print('Yes')

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



if s[0][0] == '
    if s[0][1] == '.' and s[1][0] == '.':
        print('No')
        exit()

if s[0][W - 1] == '
    if s[0][W - 2] == '.' and s[1][W - 1] == '.':
        print('No')
        exit()

if s[H - 1][0] == '
    if s[H - 1][1] == '.' and s[H - 2][0] == '.':
        print('No')
        exit()

if s[H - 1][W - 1] == '
    if s[H - 1][W - 2] == '.' and s[H - 2][W - 1] == '.':
        print('No')
        exit()


for i in range(1, W - 1):
    if s[0][i] == '
        if s[0][i - 1] == '.' and s[0][i + 1] == '.' and s[1][i] == '.':
            print('No')
            exit()


for i in range(1, W - 1):
    if s[H - 1][i] == '
        if s[H - 1][i - 1] == '.' and s[H - 1][i + 1] == '.' and s[H - 2][i] == '.':
            print('No')
            exit()


for i in range(1, H - 1):
    if s[i][0] == '
        if s[i - 1][0] == '.' and s[i + 1][0] == '.' and s[i][1] == '.':
            print('No')
            exit()


for i in range(1, H - 1):
    if s[i][W - 1] == '
        if s[i - 1][W - 1] == '.' and s[i + 1][W - 1] == '.' and s[i][W - 2] == '.':
            print('No')
            exit()


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] == '.':
                print('No')
                exit()

print('Yes')

Solution (Python):
H, W = list(map(lambda n: int(n), input().split(" ")))
S = []
for i in range(H):
  if i == 0:
    S.append("X" * (W + 2))
  S.append("X" + input() + "X")
else:
  S.append("X" * (W + 2))

unpaintable = False
for i in range(1, H+1):
  for j in range(1, W+1):
    if S[i][j] == "
      unpaintable = True
      break
      
print("No") if unpaintable else print("Yes")

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

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

Solution (Python):
H,W=map(int,input().split())
L=[[0 for i in range(W)] for j in range(H)]
for i in range(H):
  L1=list(input())
  L[i]=L1
L = [["."] + i + ["."] for i in L]
L = [["." for i in range(W+2)]] + L + [["." for i in range(W+2)]]
for i in range(H+2):
  for j in range(W+2):
    if L[i][j]=="
      if L[i][j+1]==L[i][j-1]==L[i+1][j]==L[i-1][j]==".":
        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-1 >= 0 and i+1 < h and j-1 >= 0 and j+1 < w:
                if s[i-1][j] != "
                    print("No")
                    exit()
print("Yes")

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

ans = True

for i in range(H):
    for j in range(W):
        if S[i][j] == "
            t = False
            if i != 0:
                t = max(t, S[i - 1][j] == "
            if i != H - 1:
                t = max(t, S[i + 1][j] == "
            if j != 0:
                t = max(t, S[i][j - 1] == "
            if j != W - 1:
                t = max(t, S[i][j + 1] == "

            if not t:
                ans = False
                break

if ans:
    print("Yes")

else:
    print("No")

Solution (Python):
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
f = True
for i in range(h):
    for j in range(w):
        if s[i][j] == "
            dx = [0]
            dy = [0]
            if i != 0:
                dx.append(-1)
            if i != h - 1:
                dx.append(1)
            if j != 0:
                dy.append(-1)
            if j != w - 1:
                dy.append(1)
            ff = False
            for x in dx:
                for y in dy:
                    if abs(x) == abs(y):
                        continue
                    ff |= (s[i + x][j + y] == "
            f &= ff

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