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())
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:
        if d == 2:
          cnt += 1
      elif i == 0 and j == W-1:
        if d == 2:
          cnt += 1
      elif i == H-1 and j == 0:
        if d == 2:
          cnt += 1
      elif 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')

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

ans = "Yes"
for i in range(H-1):
  for j in range(W-1):
    if(C[i][j] == "
      if(i != 0 and C[i-1][j] == "
        continue
      if(i != H and C[i+1][j] == "
        continue
      if(j != 0 and C[i][j-1] == "
        continue
      if(j != W and C[i][j+1] == "
        continue
      ans = "No"
print(ans)

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

ans = 'Yes'
for i in range(H):
    if ans == 'No':
        break
    for j in range(W):
        if s[i][j] == '.':
            continue
        l = []
        if j>0:
            l.append(s[i][j-1])
        if j<len(s[i])-1:
            l.append(s[i][j+1])
        if i>0:
            l.append(s[i-1][j])
        if i<H-1:
            l.append(s[i+1][j])
        if '
            ans = 'No'
            break

print(ans)

Solution (Python):
import sys
def main():
    H,W = map(int, input().split())
    S = [input() for i in range(H)]
    
    cnt = 0
    for i in range(H):
            
        for j in range(W):
            if S[i][j] == ".":
                continue
            else:
                
                cnt = 0
                for k in range(2):
                    if 0 <= i + (k*2 - 1) < H and S[i+(k*2-1)][j] == '
                        cnt = 1
                        break
                    elif 0 <= j + (k*2 -1) < W and S[i][j+(k*2-1)] == '
                        cnt = 1
                        break
                if cnt == 0:
                    print("No")
                    exit()
        
        
    print("Yes")
    
main()

Solution (Python):
import numpy as np
def repaint(h,w,s):
    for i in range(1,h+1):
        for p in range(1,w+1):
            if s[i][p] == '
                if (s[i-1][p] != '
                    return 'No'
    return 'Yes'
H, W = map(int, input().split())
S = np.array([['0']*(W+2)] + [list('0' + input() + '0') for i in range(H)] +[['0']*(W+2)])
print(repaint(H,W,S))

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

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 main() -> None:
    H, W = map(int, input().split())
    s = ['0' + input() + '0' for _ in range(H)]
    s.insert(0, '0' * (W + 2))
    s.append('0' * (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] == "
                    continue
                else:
                    print("No")
                    exit()
    print("Yes")


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
def repaint(h,w,s):
    for i in range(1,h+1):
        for p in range(1,w+1):
            if s[i][p] == '
                if (s[i-1][p] != '
                    return 'No'
    return 'Yes'
H, W = map(int, input().split())
S = np.array([['0']*(W+2)] + [list('0' + input() + '0') for i in range(H)] +[['0']*(W+2)])
print(repaint(H,W,S))

Solution (Python):

import sys

def main():
	y, x = map(int, input().split(" "))
	
	design_drawing = []
	for _ in range(y):
		line = input()
		design_drawing.append(list(line))
	
	for y, line in enumerate(design_drawing):
		for x, dot in enumerate(line):
			if dot == "
				if y != 0:
					if design_drawing[y-1][x] == "
						continue
				if y < len(design_drawing)-1:
					if design_drawing[y+1][x] == "
						continue
				if x != 0:
					if design_drawing[y][x-1] == "
						continue
				if x < len(line)-1:
					if design_drawing[y][x+1] == "
						continue
				print("No")
				sys.exit()
	print("Yes")
	
if __name__ == "__main__":
	main()

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

ans='Yes'
for i in range(1,h+1):
    for j in range(1,w+1):
        if l[i][j]=='
            if l[i-1][j]==l[i+1][j]==l[i][j-1]==l[i][j+1]=='.':
                ans='No'
print(ans)

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

ans='Yes'
for i in range(1,h-1):
    for j in range(1,w-1):
        if l[i][j]=='
            if l[i-1][j]==l[i+1][j]==l[i][j-1]==l[i][j+1]=='.':
                ans='No'
print(ans)

Solution (Python):
h,w=map(int,input().split())
s=[]
for i in range(h):
    s.append(list(input()))
for y in range(h):
    for x in range(w):
        if s[y][x]=="
            if 0<y<h-1 and 0<x<w-1:
                if not (s[y-1][x]=="
                    print("No")
                    exit()
            elif y==0 and x==0:
                if not (s[y+1][x]=="
                    print("No")
                    exit()
            elif y==0 and x==w-1:
                if not (s[y+1][x]=="
                    print("No")
                    exit()
            elif y==h-1 and x==0:
                if not (s[y-1][x]=="
                    print("No")
                    exit()
            elif y==h-1 and x==w-1:
                if not (s[y-1][x]=="
                    print("No")
                    exit()
            elif y==0:
                if not (s[y][x-1]=="
                    print("No")
                    exit()
            elif y==h-1:
                if not (s[y][x-1]=="
                    print("No")
                    exit()
            elif x==0:
                if not (s[y-1][x]=="
                    print("No")
                    exit()
            else:
                if not (s[y-1][x]=="
                    print("No")
                    exit()
print("Yes")

Solution (Python):
class UnionFindTree():
    def __init__(self, values=[]):
        self.parent_of = {}
        self.rank_of = {}
        for value in values:
            self.add(value)

    def add(self, value):
        if value in self.parent_of:
            raise RuntimeError("Dupulicated Value Added")
        self.parent_of[value] = None
        self.rank_of[value] = 0

    def __root(self, value):
        if self.parent_of[value] is None:
            return value
        else:
            self.parent_of[value] = self.__root(self.parent_of[value])
            return self.parent_of[value]

    def unite(self, a, b):
        r1 = self.__root(a)
        r2 = self.__root(b)
        if r1 != r2:
            if self.rank_of[r1] < self.rank_of[r2]:
                self.parent_of[r1] = r2
            else:
                self.parent_of[r2] = r1
                if self.rank_of[r1] == self.rank_of[r2]:
                    self.rank_of[r1] += 1

    def is_same(self, a, b):
        return self.__root(a) == self.__root(b)

    def groups(self):
        groups = {}
        for k in self.parent_of.keys():
            r = self.__root(k)
            if r not in groups:
                groups[r] = []
            groups[r].append(k)
        return [groups[x] for x in groups]


def main():
    H, W = map(int, input().split())
    S = [input() for _ in range(H)]
    uft = UnionFindTree()
    for i in range(H):
        for j in range(W):
            if S[i][j] == '
                uft.add((i, j))
                if i >= 1 and S[i-1][j] == '
                    uft.unite((i, j), (i-1, j))
                if j >= 1 and S[i][j-1] == '
                    uft.unite((i, j), (i, j-1))
    for g in uft.groups():
        if len(g) == 1:
            print("No")
            return
    print("Yes")


if __name__ == "__main__":
    main()

Solution (Python):
h,w = map(int,input().split())
s = ['.'*(w+2)]+['.'+input()+'.' for _ in range(h)]+['.'*(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]=='
                continue
            else:
                print('No')
                exit()
print('Yes')

Solution (Python):
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
if h == 1 and w == 1:
    print("Yes")
    exit()

for i in range(h):
    for j in range(w):
        if s[i][j] == "
            f = False
            if 0 <= i+1 < h and 0 <= j < w and s[i+1][j] == "
                f = True
            if 0 <= i-1 < h and 0 <= j < w and s[i-1][j] == "
                f = True
            if 0 <= i < h and 0 <= j+1 < w and s[i][j+1] == "
                f = True
            if 0 <= i < h and 0 <= j-1 < w and s[i][j-1] == "
                f = True
            if not f:
                print("No")
                exit()
print("Yes")

Solution (Python):
H,W = map(int,input().split())
Matrix = list()
S = ''

for x in range(0,W+2):
    S += '.' 

Matrix.append(S)

for x in range(0,H):
    s = input()
    row = '.' + s + '.'
    Matrix.append(row)

Matrix.append(S)

answer = True

for x in range(1,H+1):
    for y in range(1,W+1):
        if Matrix[x][y] == '
            if Matrix[x+1][y] == '.' and Matrix[x-1][y] == '.' and Matrix[x][y+1] == '.' and Matrix[x][y-1] == '.':
                answer = False

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

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

l.append(["." for i in range(W + 2)])
Flag = True
for i in range(H + 2):
    if i == 0 or i == H + 1:
        continue
    
    for j in range(W + 2):
        if j == 0 or j == W + 1:
            continue
        if l[i][j] == "
            
            if l[i-1][j] == "." and l[i+1][j] == "." and l[i][j-1] == "." and l[i][j+1] == ".":
                Flag = False
                break
    
    if Flag == False:
        break 

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

Solution (Python):
import sys

def main():
  input = sys.stdin.readline
  H, W = map(int, input().split())
  A = [[0 for _ in range(W+2)] for _ in range(H+2)]
  for i in range(H):
    A[i+1] = [0] + [c == '
  
  ans = 'Yes'
  for i in range(H):
    for j in range(W):
      if A[i+1][j+1]:
        if not any([A[i][j+1], A[i+2][j+1], A[i+1][j+2], A[i+1][j]]):
          ans = 'No'
          break
  print(ans)


if __name__ == '__main__':
  main()

Solution (Python):
import sys

def main():
  input = sys.stdin.readline
  H, W = map(int, input().split())
  A = [[0 for _ in range(W+2)] for _ in range(H+2)]
  for i in range(H):
    a = [0] + [c == '
    A[i+1] = a
  
  ans = 'Yes'
  for i in range(H):
    for j in range(W):
      if A[i+1][j+1] == 1:
        u, d, r, l = A[i][j+1], A[i+2][j+1], A[i+1][j+2], A[i+1][j]
        if any([u, d, r, l]):
          continue
        else:
          ans = 'No'
          break
  print(ans)


if __name__ == '__main__':
  main()

Solution (Python):
grid = [[None for j in range(55)] for i in range(55)]
h, w = [int(i) for i in input().split()]
for i in range(h):
  a=list(input())
  for j in range(w):
    grid[i+1][j+1]=a[j]
for x in range(h):
  for y in range(w):
    if grid[x][y]=="
      if grid[x+1][y]=="
        continue
      else:
        print("No")
        exit()
print("Yes")

Solution (Python):
import sys

def main():
  input = sys.stdin.readline
  H, W = map(int, input().split())
  A = [[0 for _ in range(W+2)] for _ in range(H+2)]
  for i in range(H):
    a = [0] + [int(c == '
    A[i+1] = a
  
  ans = 'Yes'
  for i in range(H):
    for j in range(W):
      if A[i+1][j+1] == 1:
        u, d, r, l = A[i][j+1], A[i+2][j+1], A[i+1][j+2], A[i+1][j]
        if any([a == 1 for a in [u, d, r, l]]):
          continue
        else:
          ans = 'No'
          break
  print(ans)


if __name__ == '__main__':
  main()

Solution (Python):
h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
edge = [(0,1),(0,-1),(1,0),(-1,0)]
for i in range(h):
    for j in range(w):
        if s[i][j] =="
            for x,y in edge:
                if 0<= i+y <h and 0<= j+x < w and s[i+y][j+x] =="
            else:
                print("No")
                break 
    else:continue
    break
else:print("Yes")

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

expanded_grid = []
expanded_grid.append(list('&'*(w+2)))
for row in rows:
    expanded_grid.append(list('&'+row+'&'))
expanded_grid.append(list('&'*(w+2)))

judge = True

for i in range(h):
    for j in range(w):
        if (grid[i])[j] == '
            nearby = [
                
                (expanded_grid[i])[j+1],
                

                (expanded_grid[i+1])[j],
                (expanded_grid[i+1])[j+2],

                
                (expanded_grid[i+2])[j+1]
                
            ]   

            if nearby.count('
                judge = False


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

Solution (Python):
H, W = map(int, input().split())
S = [input() for _ in range(H)]
for h, line in enumerate(S):
    before = "."
    result = []
    for w, s in enumerate(line):
        if before == "." and s == ".":
            result.append(True)
        if before == "." and s == "
            result.append((h != 0 and S[h - 1][w] == "
        if before == "
            result.append(True)
        if before == "
            result[-1] = True
            result.append(True)
        before = s
    if not all(result):
        print("No")
        break
else:
    print("Yes")

Solution (Python):
h, w = map(int, input().split())
field = [input() for _ in range(h)]
directions = [(1, 0), (-1, 0), (0, 1), (0, -1)]
for i in range(h):
    for j in range(w):
        if field[i][j] == '
            ret = False
            for di, dj in directions:
                x = i + di
                y = j + dj
                if 0 <= x < h and 0 <= y < w and field[x][y] == '
                    ret = True
            if not ret:
                print('No')
                exit()
print('Yes')

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

ans = 'Yes'
for i in range(1, h - 1):
    for j in range(1, w - 1):
        if S[i][j] == '
            ans = 'No'
            
print(ans)

Solution (Python):

import sys



def solve(lines):
    def solve_iter(hi, wi):
        vec = [(0,1),(0,-1),(1,0),(-1,0)]
        for v in vec:
            hn = hi + v[0]
            wn = wi + v[1]
            if hn >= 0 and hn < H and wn >= 0 and wn < W:
                if NLIST[hn][wn] == '
                    NLIST[hi][wi] = '*'
                    NLIST[hn][wn] = '*'
                    
        return

    H,W = map(int, lines.pop(0).split(' '))
    NLIST = []
    for i in range(H):
        NLIST.append(list(lines.pop(0)) )

    res = 'Yes'
    for i in range(H):
        for j in range(W):
            if NLIST[i][j] == '
                solve_iter(i, j)
            if NLIST[i][j] == '
                res = 'No'

    print(res)




lines = [x.strip() for x in sys.stdin.readlines()]




solve(lines)

Solution (Python):
h,w=map(int,input().split())
mapdata=[]
re=0
for i in range(h):
  line=str(input())
  line2=list(line)
  mapdata.append(line2)
def jugde(i,j):
  count=0
  for x in (i-1,i+1):
    if 0<=x<=h-1:
      if mapdata[x][j]=='
        count+=1
  for y in (j-1,j+1):
    if 0<=y<=w-1:
      if mapdata[i][y]=='
        count+=1
  if count!=0:
    return True
for i in range(h):
  for j in range(w):
    if mapdata[i][j]=='
      if jugde(i,j)==True:
        pass
      else:
        re+=1
if re==0:
  print('Yes')
if re!=0:
  print('No')

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

def search(arr, x, y):
    dif = ((-1, 0), (0, -1), (0, 1), (1, 0))
    flag = 1

    for dx, dy in dif:
        try:    
            if (x+dx) >= 0 and (y+dy) >= 0 and arr[x + dx][y + dy] == '
                flag = 0
                break
        except:
            pass
    return flag

for i in range(h):
    for j in range(w):
        if s[i][j] == '
            if search(s, i, j):
                print("No")
                exit(0)
print("Yes")

Solution (Python):
h,w = list(map(int,input().split()))
table = list()
x = [0,1,0,-1]
y =[1,0,-1,0]

for i in range(h):
    table.append(list(input()))
    
for i in range(h):
    j_check = False
    for j in range(w):
        if table[i][j] == "
            counter = 0
            for a,b in zip(x,y):
                if i + b >= h or i + b < 0 or j + a >= w or j + a < 0:
                    continue
                elif table[i+b][j+a] == "
                    counter += 1
            if counter == 0:
                print("No")
                j_check = True
                break
    if j_check:
        break
else:
    print("Yes")

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

ans='Yes'
for i in range(1,h-1):
    for j in range(1,w-1):
        if S[i][j]=='
            ans='No'

print(ans)

Solution (Python):

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

can = True
for i in range(h-1):
    for j in range(w-1):
        if s[i][j] == '
            cnt = 0
            if j+1 < w and s[i][j+1] == '
                cnt += 1
            if j-1 >= 0 and s[i][j-1] == '
                cnt += 1
            if i+1 < h and s[i+1][j] == '
                cnt += 1
            if i-1 >= 0 and s[i-1][j] == '
                cnt += 1
            if cnt > 0:
                continue
            else:
                can = False
                break
    if not can:
        break
if can:
    print('Yes')
else:
    print('No')

Solution (Python):
h,w = map(int,input().split())
a = [input() for _ in range(h)]
x = [1,-1,0,0]
y = [0,0,1,-1]
for i in range(h):
    for j in range(w):
        cnt = 0
        if a[i][j] == '
            for k in range(4):
                if 0 <= i+x[k] < h and 0 <= j+y[k] < w:
                    if a[i+x[k]][j+y[k]] == '
                        cnt += 1
        else:
            continue

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

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

count = 0
pa = 0
for i in range(H):
    for j in range(W):
        a = S[i][j]
        if a == '
            if j-1 >= 0 and S[i][j-1] == '
                count += 1
            if j+1 <= W-1 and S[i][j+1] == '
                count += 1
            if i-1 >= 0 and S[i-1][j] == '
                count += 1
            if i+1 <= H-1 and S[i+1][j] == '
                count += 1

            if count >= 1:
                continue
            else:
                pa += 1
                break
        count = 0
if pa != 0:
    print('No')
else:
    print('Yes')

Solution (Python):
import itertools
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def judge(i,j):
    if j != 0:
        if l[i][j-1] == "
            return True
    if j != W-1:
        if l[i][j+1] == "
            return True
    if i != 0:
        if l[i-1][j] == "
            return True
    if i != H-1:
        if l[i+1][j] == "
            return True
    return False

H,W = IL()
l = [input() for i in range(H)]

for i in range(H):
    for j in range(W):
        if l[i][j] == "
            if judge(i,j) == False:
                print("No")
                exit()
print("Yes")

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

delta = [[0, -1], [-1, 0], [1, 0], [0, 1]]
ans = 'Yes'
for y in range(h):
  for x in range(w):
    if s[y][x] == '
      for xd, yd in delta:
        if 0 <= x + xd < w and 0 <= y + yd < h and s[y + yd][x + xd] == '
          break
      else:
        ans = 'No'
        break

print(ans)

Solution (Python):
from sys import stdin
h, w = [int(x) for x in stdin.readline().rstrip().split()]
matrix = [stdin.readline().rstrip() for _ in range(h)]
for i in range(h):
    matrix[i] = [matrix[i][x:x+1] for x in range(len(matrix[i]))]
    

for i in range(h):
    for j in range(w):
        if matrix[i][j] == '
            flag = 0
            for n in list([-1, 1]):
                i_n = i + n
                j_n = j + n
                if i_n >= 0 and i_n < h:
                    if matrix[i_n][j] == '
                        flag = 1
                        break
                if j_n >= 0 and j_n < w:
                    if matrix[i][j_n] == '
                        flag = 1
                        break
            if flag == 0:
                print('No')
                exit()
print('Yes')

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

ans = "Yes"
for i in range(H-1):
  for j in range(W-1):
    if(HW[i][j] == '.'):
      continue
    if(HW[i-1][j] == '
      continue
    if(HW[i][j-1] == '
      continue
    if(HW[i+1][j] == '
      continue
    if(HW[i][j+1] == '
      continue
    ans = "No"
print(ans)

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

Solution (Python):
h,w = map(int, input().split())
s = []
for i in range(h):
    s.append(str(input()))
    
flag = True
for i in range(h):
    for j in range(w):
        if s[i][j] == '
            check = False
            if i+1 < h:
                if s[i+1][j] == '
                    check = True
            if j+1 < w:
                if s[i][j+1] == '
                    check = True
            if i-1 >= 0:
                if s[i-1][j] == '
                    check = True
            if j-1 >= 0:
                if s[i][j-1] == '
                    check = True
            if check == False:
                flag = False
if flag:
    print('Yes')
else:
    print('No')

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

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

Solution (Python):
H,W=map(int,input().split())
M=[['.' for _ in range(W+2)] for _ in range(H+2)]
flag=True
for i in range(H):
    s=input()
    for j in range(W):
        M[i+1][j+1]=s[j]
for i in range(H):
    for j in range(W):
        if M[i+1][j+1]=='
            if M[i][j+1]=='.' and M[i+2][j+1]=='.' and M[i+1][j]=='.' and M[i+1][j+2]=='.':
                flag=False
if flag==True:
    print('Yes')
else:
    print('No')

Solution (Python):
H,W = map(int,input().split())
mass = []
for h in range(H):
    mass.append(input())
def check(h,w):
    global mass
    x=[1,-1,0,0]
    y=[0,0,1,-1]
    for xx,yy in zip(x,y):
        if 0<=h+xx and h+xx<H and 0<=w+yy and w+yy<W: 
            if mass[h+xx][w+yy] == "
                return True
    return False
for h in range(H):
    for w in range(W):
        if mass[h][w] == '
            if check(h,w) == False:
                print("No")
                exit()
print("Yes")

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

ans = "Yes"
for i in range(H-1):
  for j in range(W-1):
    if(HW[i][j] == "."):
      continue
    if(i != 0 and HW[i-1][j] == "
      continue
    if(j != 0 and HW[i][j-1] == "
      continue
    if(j != H and HW[i+1][j] == "
      continue
    if(j != W and HW[i][j+1] == "
      continue
    ans = "No"
print(ans)

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

for i, t in enumerate(s):
    for j, w in enumerate(t):
        if w == '
            Bl.add((i, j))

for p in Bl:
    if (p[0]+1, p[1]) not in Bl and (p[0], p[1]+1) not in Bl and \
     (p[0]-1, p[1]) not in Bl and (p[0], p[1]-1) not in Bl:
        print("No")
        break
else:
    print("Yes")

Solution (Python):
def solve(H, W, field):
    for hi, row in enumerate(field):
        for wi, cel in enumerate(row):
            if cel != "
                continue
            if any([field[hi + dh][dw + wi] == "
                    for dh, dw in [(-1, 0), (1, 0), (0, -1), (0, 1)]
                    if 0 <= hi + dh < H and 0 <= dw + wi < W]):
                pass
            else:
                return "No"
    return "Yes"


if __name__ == "__main__":
    H, W = tuple(map(int, input().split(" ")))
    field = [input() for _ in range(H)]
    print(solve(H, W, field))

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

Solution (Python):
def main():
    H, W = map(int, input().split())
    s = [list(input()) for _ in range(H)]
    for h in range(H):
        for w in range(W):
            if s[h][w] != '
                continue
            flg = False
            for dh, dw in zip([-1, 0, 0, 1], [0, -1, 1, 0]):
                if h + dh >= 0 and H > h + dh and \
                    w + dw >= 0 and W > w + dw and \
                        s[h + dh][w + dw] == '
                    flg = True
                    break
            if flg is False:
                print('No')
                exit()

    print('Yes')


main()

Solution (Python):
def main():
    H, W = map(int, input().split())
    s = [list(input()) for _ in range(H)]
    if s[0][0] == '
        if s[1][0] != '
                s[0][1] != '
            print('No')
            exit()
    if s[H - 1][0] == '
        if s[H - 2][0] != '
                s[H - 1][1] != '
            print('No')
            exit()
    if s[0][W - 1] == '
        if s[0][W - 2] != '
                s[1][W - 1] != '
            print('No')
            exit()
    if s[H - 1][W - 1] == '
        if s[H - 2][W - 1] != '
                s[H - 1][W - 2] != '
            print('No')
            exit()

    for h in range(H):
        if s[h][0] == '
            if s[h - 1][0] != '
                s[h][1] != '
                    s[h + 1][0] != '
                print('No')
                exit()
        if s[h][W - 1] == '
            if s[h - 1][W - 1] != '
                s[h][W - 2] != '
                    s[h + 1][W - 1] != '
                print('No')
                exit()

    for w in range(W):
        if s[0][w] == '
            if s[0][w - 1] != '
                s[1][w] != '
                    s[0][w + 1] != '
                print('No')
                exit()
        if s[H - 1][w] == '
            if s[H - 1][w - 1] != '
                s[H - 2][w] != '
                    s[H - 1][w + 1] != '
                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] != '
                    s[h + 1][w] != '
                    s[h][w - 1] != '
                        s[h][w + 1] != '
                    print('No')
                    exit()
    print('Yes')


main()