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

for i in range(h):
    for j in range(w):
        if s[i][j] == "
            flag = False
            for i_new, j_new in [(i+1, j), (i-1, j), (i,j+1), (i,j-1)]:
                if i_new<0 or i_new>=h or j_new<0 or j_new>=w: continue
                if s[i_new][j_new] == "
                    flag = True
                    break
            if not flag:
                print("No")
                exit()
print("Yes")

Solution (Python):


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter  
from itertools import combinations as comb  
from itertools import permutations as permutate
from bisect import bisect_left as bl





from bisect import bisect_right as br
from bisect import bisect







BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)





from types import GeneratorType


def iterative(f, stack=[]):
    def wrapped_func(*args, **kwargs):
        if stack: return f(*args, **kwargs)
        to = f(*args, **kwargs)
        while True:
            if type(to) is GeneratorType:
                stack.append(to)
                to = next(to)
                continue
            stack.pop()
            if not stack: break
            to = stack[-1].send(to)
        return to

    return wrapped_func







mod = 1000000007


def inp(): return sys.stdin.readline().rstrip("\r\n")  

def integer(): return int(inp())


def out(var): sys.stdout.write(str(var))  


def lis(): return list(map(int, inp().split()))


def stringlis(): return list(map(str, inp().split()))


def sep(): return map(int, inp().split())


def strsep(): return map(str, inp().split())


def zerolist(n): return [0] * n


def nextline(): out("\n")  


def testcase(t):
    for p in range(t):
        solve()


def printlist(a):
    for p in range(0, len(a)):
        out(str(a[p]) + ' ')




def factors(n):
    return set(reduce(list.__add__,
                      ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))









def solve():
    n,m=sep()
    ar=[]
    dx=[1,-1,0,0]
    dy=[0,0,1,-1]
    for i in range(n):
        t=inp()
        temp=[]
        for i in t:
            temp.append(i)
        ar.append(temp)
    def isvalid(i,j):
        if 0<=i<n and 0<=j<m:
            return 1
        return 0
    for i in range(n):
        for j in range(m):
            t=0
            k=ar[i][j]
            if k=="
                for move in range(4):
                    cur_x,cur_y=i+dx[move],j+dy[move]
                    if isvalid(cur_x,cur_y):
                        if ar[cur_x][cur_y]=="
                            t=1
                            break
                if t==0:
                    print("No")
                    quit()
    print("Yes")








solve()

Solution (Python):
from itertools import product
H,W=map(int,input().split())
S=[input() for i in range(H)]
 
isOK=True
 
for y,x in product(range(H),range(W)):
    if S[y][x]=='.':
        continue
    sum=0
 
    if 0<x:
        if S[y][x-1]=='
    
    if x<W-1:
        if S[y][x+1]=='
    
    if 0<y:
        if S[y-1][x]=='
    
    if y<H-1:
        if S[y+1][x]=='
    
    if sum==0:
        isOK=False
 
if isOK:
    print("Yes")
else:
    print("No")

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

for h in range(H):
    c = 0
    for w in range(W):
        if S[h][w] == "
            c += 1
        else:
            if c == 1:
                cnt[h][w-1] = 1
            c = 0
    if c == 1:
        cnt[h][w] = 1

ans = "Yes"
for w in range(W):
    c = 0
    for h in range(H):
        if S[h][w] == "
            c += 1
        else:
            if c == 1:
                if cnt[h-1][w] == 1:
                    ans = "No"
                    break
            c = 0
    if c == 1:
        if cnt[h][w] == 1:
            ans = "No"
            break
            
print(ans)

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

ans = []
for row in src:
        ans.append(list(row))

dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
for x in range(h):
        for y in range(w):
                if src[x][y] == ".":
                        continue
                if src[x][y] == "
                        flag = 0
                        for dx, dy in dxy:
                                if x + dx < 0 or x + dx > h -1 or y + dy < 0 or y + dy > w - 1:
                                        continue
                                if src[x + dx][y + dy] == "
                                        flag = 1
                                        break
                        if flag == 0:
                                print("No")
                                exit()

print("Yes")

Solution (Python):
from itertools import product
H,W=map(int,input().split())
S=[input() for i in range(H)]

isOK=True

for y,x in product(range(H),range(W)):
    if S[y][x]=='.':
        continue
    sum=0

    if 0<x:
        if S[y][x-1]=='
    
    if x<W-1:
        if S[y][x+1]=='
    
    if 0<y:
        if S[y-1][x]=='
    
    if y<H-1:
        if S[y+1][x]=='
    
    if sum==0:
        isOK=False

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

Solution (Python):
h,w = map(int, input().split())
s = list()
t = list()
a = [0 for i in range(w+2)]
s.append(a)
for i in range(h):
    b = str(input())
    c = list(('0'+b+'0').replace('.','0').replace('
    d = list(map(int, c))
    s.append(d)
    t.append(b)
s.append(a)
flag = 0

for j in range(1,h+1):
    for k in range(1,w+1):
        if flag == 1:
            break
        if s[j][k] == 1:
            cnt = 0
            cnt = s[j-1][k] + s[j][k-1] + s[j][k+1] + s[j+1][k] 
            if cnt == 0:
                flag = 1
                print('No')

if flag == 0:
    print('Yes')

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

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

check = True
for i in range(H):
  for j in range(W):
    if s[i][j] == "
      flag = False
      for (n,m) in jougesayuu:
        ni, nj = i + n, j + m
        if ni < 0 or H <= ni or nj < 0 or W <= nj:
          continue
        if s[ni][nj] == "
          flag = True
      if not flag:
        check = False
        
print("Yes" if check else "No")

Solution (Python):
H, W = map(lambda x:int(x)+2, input().split())
grid = "."*W
for _ in range(H-2):
  grid += "."+input()+"."
grid += "."*W

Flag = True
move_list = [1, -1, W, -W]

for i in range(1, H-1):
  for j in range(1, W-1):
    if grid[i*W+j] == "
      Flag = False
      break

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

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

import sys
for j in range(1,H-1):
    for i in range(1,W-1):
        if s[j][i] =='
            if s[j][i-1] == '
                pass
            elif s[j-1][i] == '
                pass
            elif s[j][i+1] == '
                pass
            elif s[j+1][i] == '
                pass
            else:
                print('No')
                sys.exit()
print('Yes')

Solution (Python):
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right 
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
MOD = 10**9+7

def mint():
    return map(int,input().split())
def lint():
    return map(int,input().split())
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)

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

def f(i,j):
    ans = 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 S[x][y]=='
            ans = True
            break
    return ans

for i in range(H):
    for j in range(W):
        if S[i][j]=='
            if not f(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] == "
            c = 0
            for ni, nj in [(i+1, j),(i, j+1),(i-1, j),(i, j-1)]:
                if 0 <= ni < h and 0 <= nj < w and s[ni][nj] == "
                    c += 1
            if c == 0:
                print("No")
                exit(0)
print("Yes")

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

ans=[[0]*w for i in range(h)]

for i in range(h):
  for j in range(w):
    x,y=0,0
    if lis[i][j]=="
      ans[i][j]=1
      for a in range(-1,2):
        if 0<=i+a<h and lis[i+a][j]=="
          x+=1
      ans[i][j]+=x
      for b in range(-1,2):
        if 0<=j+b<w and lis[i][j+b]=="
          y+=1
      ans[i][j]+=y
      if ans[i][j]==1:
        print("No")
        exit()
    else:
      ans[i][j]=0
      
print("Yes")

Solution (Python):

import sys

YES = "Yes"  
NO = "No"  


def solve(H: int, W: int, S: "List[str]"):
    for i in range(H):
        for j in range(W):
            if S[i][j] == ".":
                continue
            if i - 1 >= 0:
                if S[i - 1][j] == "
                    continue
            if i + 1 < H:
                if S[i + 1][j] == "
                    continue
            if j - 1 >= 0 and S[i][j - 1] == "
                continue
            if j + 1 < W and S[i][j + 1] == "
                continue
            print(NO)
            return
    print(YES)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    H = int(next(tokens))  
    W = int(next(tokens))  
    S = [list(next(tokens)) for _ in range(H)]  
    solve(H, W, S)


if __name__ == "__main__":
    main()

Solution (Python):
h,w=map(int,input().split())
dx=[0,1,0,-1] ; dy=[1,0,-1,0]
A=[list(input()) for i in range(h)]

for i in range(h):
    for  j in range(w):
        if A[i][j]=="
            for q,e in zip(dx,dy):
                if 0<=i+q<h and 0<=j+e<w:
                    if A[i+q][e+j]=="
            else:
                print("No");exit()
print("Yes")

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

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

def check(x, y, up, down, left, right):
    if s[x][y] == '.':
        return 0
    if up and s[x-1][y] == '
        return 0
    if down and s[x+1][y] == '
        return 0
    if left and s[x][y-1] == '
        return 0
    if right and s[x][y+1] == '
        return 0
    else:
        print('No')
        exit()


check(0, 0, False, True, False, True)
for y in range(1, w-1):
    check(0, y, False, True, True, True)
check(0, w-1, False, True, True, False)


for x in range(1, h-1):
    check(x, 0, True, True, False, True)
    for y in range(1, w-1):
        check(x, y, True, True, True, True)
    check(x, w-1, True, True, True, False)


check(h-1, 0, True, False, False, True)
for y in range(1, w-1):
    check(h-1, y, True, False, True, True)
check(h-1, w-1, True, False, True, False)

print('Yes')

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

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

def check(x, y, up, down, left, right):
    if s[x][y] == '.':
        return 0
    if up and s[x-1][y] == '
        return 0
    if down and s[x+1][y] == '
        return 0
    if left and s[x][y-1] == '
        return 0
    if right and s[x][y+1] == '
        return 0
    else:
        print('No')
        exit()


check(0, 0, False, True, False, True)
for y in range(1, w-1):
    check(0, y, False, True, True, True)
check(0, w-1, False, True, True, False)


for x in range(1, h-1):
    check(x, 0, True, True, False, True)
    for y in range(1, w-1):
        check(x, y, True, True, True, True)
    check(x, w-1, True, True, True, False)


check(h-1, 0, True, False, False, True)
for y in range(1, w-1):
    check(h-1, y, True, False, True, True)
check(h-1, w-1, True, False, True, False)

print('Yes')

Solution (Python):
from itertools import product

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

def dfs(p):
    if s[p[0]][p[1]] == '.':  
        return None

    temp = [1 if s[p[0]+y][p[1]+x] == '
    if sum(temp) <= 0:
        print('No')
        exit(0)


for i in range(len(s)):
    for j in range(len(s[0])):
        dfs([i, j])
print('Yes')

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

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

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

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

Solution (Python):
H,W=map(int,input().split())
List = [list(input()) for i in range(H)]
res = "Yes"
flag = True

def checkAround(ListX,i,j):
  if i == 0 and j ==0:
    if List[i+1][j] == "
      return True
    else: 
      return False
  elif i == 0 and j !=0 and j != W-1:
    if List[i+1][j] == "
      return True
    else: 
      return False
  elif i == 0 and j == W-1:
    if List[i+1][j] == "
      return True
    else: 
      return False
  elif i != 0 and i != H-1 and j == 0:
    if List[i+1][j] == "
      return True
    else: 
      return False
  elif i == H-1 and j == W-1:
    if List[i-1][j] == "
      return True
    else: 
      return False
  elif i == H-1 and j !=0 and j != W-1:
    if List[i-1][j] == "
      return True
    else: 
      return False
  elif i == H-1 and j == 0:
    if List[i-1][j] == "
      return True
    else: 
      return False
  elif i != 0 and i != H-1 and j == W-1:
    if List[i+1][j] == "
      return True
    else: 
      return False
  else:
    if List[i+1][j] == "
      return True
    else: 
      return False

for k in range(H):
  for l in range(W):
    if List[k][l] == ".":
      pass
    else:
      flag = checkAround(List,k,l)
      if not flag:
        res = "No"
        break
  if not flag:
    break
print(res)

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

import sys
for j in range(1,H-1):
    for i in range(1,W-1):
        if s[j][i] =='
            if s[j][i-1] == '
                pass
            elif s[j-1][i] == '
                pass
            elif s[j][i+1] == '
                pass
            elif s[j+1][i] == '
                pass
            else:
                print('No')
                sys.exit()
print('Yes')

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

ans = "Yes"
for i, s in enumerate(sl):
    for j, p in enumerate(s):
        if sl[i][j] == ".":
            continue
        up_s = sl[i - 1][j] if i - 1 >= 0 else ""
        down_s = sl[i + 1][j] if i + 1 < H else ""
        left_s = sl[i][j - 1] if j - 1 >= 0 else ""
        right_s = sl[i][j + 1] if j + 1 < W else ""
        if "
            continue
        ans = "No"
        break
    if ans == "No":
        break

print(ans)

Solution (Python):
import sys
H,W = map(int,input().split())
lsHW = [['.' for i in range(W+2)]]
for i in range(H):
    Sls = ['.'] + list(input()) + ['.']
    lsHW.append(Sls)
lsHW.append(['.' for i in range(W+2)])
for i in range(1,H+1):
    for j in range(1,W+1):
        if lsHW[i][j] == '.':
            continue
        else:
            if not (lsHW[i-1][j] == '
                print('No')
                sys.exit()
print('Yes')

Solution (Python):
import sys


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


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

    uf = UnionFind(H * W)
    direction = [(1, 0), (-1, 0), (0, 1), (0, -1)]

    for i in range(H):
        for j in range(W):
            if Grid[i][j] == '
                for dx, dy in direction:
                    nx, ny = i + dx, j + dy
                    if 0 <= nx <= H - 1 and 0 <= ny <= W - 1:
                        if Grid[nx][ny] == '
                            uf.union(i * W + j, nx * W + ny)
    ans = True

    for k, v in uf.all_group_members().items():
        i, j = k // W, k % W
        if Grid[i][j] == '
            ans = False
            break

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


if __name__ == '__main__':
    main()

Solution (Python):
import sys

input = sys.stdin.readline

d = '.'
dn = '

def isPaintable(h, w, x, y, canvas):
    if x > 0:
        if canvas[y][x-1] == dn:
            return True
    if x < w-1:
        if canvas[y][x+1] == dn:
            return True
    if y > 0:
        if canvas[y-1][x] == dn:
            return True
    if y < h-1:
        if canvas[y+1][x] == dn:
            return True
    return False

def main():
    ans = 'Yes'
    h, w = map(int, input().split())
    canvas = []
    for _ in range(h):
        s = list(input().rstrip('\n'))
        canvas.append(s)
    for y in range(h):
        if ans == 'No':
            break
        for x in range(w):
            if canvas[y][x] == dn and not isPaintable(h, w, x, y, canvas):
                ans = 'No'
                break
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
h,w=map(int,input().split())
a=['.'*(w+2)]
s=['.'+input()+'.' for _ in range(h)]
s=a+s+a
f=True
for i in range(1,h+1):
  for j in range(1,w+1):
    if s[i][j]=='
      f=False
if f:
  print('Yes')
else:
  print('No')

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


def sirokuro(i,j):
    result = True
    if i + 1  < h :
        if s[i + 1][j] == '
            result = False
    if i - 1 >= 0:
        if s[i - 1][j] == '
            result = False
    if j + 1 < w:

        if s[i][j + 1] == '

            result = False
    if j - 1 >= 0:
        if s[i][j - 1] == '
            result = False
    return result

for i in range(h):
    for j in range(w):
        if s[i][j] == '
            if sirokuro(i,j):
                print('No')
                sys.exit()
print('Yes')

Solution (Python):

import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


H, W = zz()
board = []
for i in range(H):
    board.append(S())

dx_lis = (-1, 0, 1, 0)
dy_lis = (0, -1, 0, 1)


def check(i, j):
    for dx, dy in zip(dx_lis, dy_lis):
        if (i + dx >= H or i + dx < 0 or j + dy >= W or j + dy < 0):
            continue
        if (board[i + dx][j + dy] == '
            return(True)
    return False


for i in range(H):
    for j in range(W):
        if (board[i][j] == '
            if (check(i, j) is False):
                print('No')
                exit()
print('Yes')

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


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())
s=[[] for i in range(h+2)]
for i in range(h):
    x=input()
    x="."+x
    x=x+"."
    s[i+1]=list(x)
s[0]=["." for i in range(w+2)]
s[-1]=["." for i in range(w+2)]
f=0
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j]=="
            f=1
print("Yes" if f==0 else "No")

Solution (Python):

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

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


result = 'Yes'
for h in range(H):
    for w in range(W):
        
        if s[h][w] == '
            cnt = 0   
            for i in range(4):
                nxt_w = w + dw[i]
                nxt_h = h + dh[i]
                if not(-1<nxt_w<W) or not(-1<nxt_h<H):
                    continue
                if s[nxt_h][nxt_w] == '
                    cnt += 1
            if cnt == 0:
                result = 'No'
                break            
    else:
        continue
    break

print(result)

Solution (Python):
h,w = map(int,input().split())
grid = []
for i in range(h):
  grid.append(input())
walk = [[1,0],[-1,0],[0,1],[0,-1]]
ans = 'Yes'
for i in range(h):
  for j in range(w):
    if grid[i][j]=='
      temp = 1
      for k,l in walk:
        ni = i+k
        nj = j+l
        if 0<=ni<h and 0<=nj<w:
          if grid[ni][nj]=='
            temp = 0
      if temp:
        ans = 'No'
print(ans)

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

grid = ["*" + input() + "*" for _ in range(h)]
grid.append("*" * (w + 2))
grid.insert(0, "*" * (w+2))

for y in range(1, h+1):
    for x in range(1, w+1):
        if grid[y][x] == "
            if grid[y+1][x] == "
               grid[y-1][x] == "
               grid[y][x+1] == "
               grid[y][x-1] == "
               continue
            else:
                print("No")
                exit()

print("Yes")

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

s = [["."] * (W + 2) for i in range(H+2)]

for i in range(1, H + 1):
    ss = input()
    for j in range(1, W + 1):
        s[i][j] = ss[j-1]


f = 0

for i in range(1, H+1):
    for j in range(1, W+1):
        if s[i][j] == "
            f =1
    if f == 1:
        break

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

Solution (Python):


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

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

print('Yes')

Solution (Python):
h, w = map(int, input().split())
s = [['.'] * (w + 2) ]
for _ in range(h):
  s.append(['.'] + list(input()) + ['.'])
s.append(['.'] * (w + 2))
for y in range(1, h + 1):
  for x in range(1, w + 1):
    if s[y][x]=="
        print("No")
        exit()
print("Yes")

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

ans = True
for i in range(h):
    for j in range(w):
        if s[i][j] == "
            u_r_d_l = [(-1, 0), (0, 1), (1, 0), (0, -1)]
            if i == 0:
                u_r_d_l[0] = (0, 0)
            if i == h - 1:
                u_r_d_l[2] = (0, 0)
            if j == 0:
                u_r_d_l[3] = (0, 0)
            if j == w - 1:
                u_r_d_l[1] = (0, 0)
            for k in u_r_d_l:
                if k != (0, 0):
                    if s[i + k[0]][j + k[1]] == "
                        
                        break
            else:
                ans = False


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

Solution (Python):
def color(s):
    col = 'black'
    if s == '.':
        col = 'white'
    return col


def main():
    h, w = map(int, input().split())
    s_lst = list(str(input()) for _ in range(h))
    sw_lst = []
    for i in range(h):
        tmp_lst = []
        s = s_lst[i]
        for j in range(w):
            tmp_lst.append(s[j])
        sw_lst.append(tmp_lst)

    flag = True
    black_count = 0

    for i in range(h):
        for j in range(w):

            surroundings = []
            if color(sw_lst[i][j]) == 'black':
                black_count += 1
                if i != 0:
                    surroundings.append(color(sw_lst[i - 1][j]))
                if i != h - 1:
                    surroundings.append(color(sw_lst[i + 1][j]))
                if j != 0:
                    surroundings.append(color(sw_lst[i][j - 1]))
                if j != w - 1:
                    surroundings.append(color(sw_lst[i][j + 1]))

                if 'black' not in surroundings:
                    flag = False

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


if __name__ == '__main__':
    main()

Solution (Python):
import sys
h,w=map(int,input().split())
s=[input() for i in range(h)]
ss=[[0 for _ in range(w+2)] for _ in range(h+2)]
for j in range(w):
    for i in range(h):
        ss[i+1][j+1]=s[i][j]
for j in range(1,w+1):
    for i in range(1,h+1):
        c=True
        if ss[i][j]=='.':
            continue
        if not(ss[i-1][j]=='
            print('No')
            sys.exit()
print('Yes')

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

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

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