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 i in range(h)]
ans = "Yes"
for i in range(h-1):
    for j in range(w-1):
        if s[i][j] == "
            if (j >= 1 and s[i][j] == "
                continue
            else:
                ans = "No"
                print(ans)
                exit()
        else:
            continue
print(ans)

Solution (Python):

H, W = map(int, input().split())
grid = []
answer = 'Yes'
for i in range(H):
    grid.append(list(input()))

for i in range(H):
    for j in range(W):
        tonari = []
        if i != 0:
            tonari.append(grid[i-2][j-1])
        if i != H:
            tonari.append(grid[i][j-1])
        if j != 0:
            tonari.append(grid[i-1][j-2])
        if j != W:
            tonari.append(grid[i-1][j])
            
        if '
            answer = 'No'
print(answer)

Solution (Python):
input_line = input().split()
H = int(input_line[0])
W = int(input_line[1])

square = []
empty = []
for i in range(W+2):
    empty.append('.')
square.append(empty)

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

square.append(empty)
a = 0
for i in range(H):
    for j in range(W):
        if square[1 + i][1 + j] =='
            if square[i][1 + j] == '
               or square[i +1][j+2] == '
                continue
            else:
                a = 1
                break

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

Solution (Python):
def abc096_c():
    import numpy as np
    h, w = map(int, input().split())
    c = np.zeros([h + 2, w + 2], dtype=int)
    for i in range(h):
        row = "." + input() + "."
        for j in range(w + 2):
            c[i + 1][j] = [0, 1][row[j] == "

    for i in range(1, h + 2):
        for j in range(1, w + 2):
            if c[i][j] == 1 and (np.sum([c[i - 1][j], c[i + 1][j], c[i][j - 1], c[i][j + 1]]) == 0):
                return "No"

    return "Yes"


print(abc096_c())

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

result = "Yes"



for j in range(H-1):
    for k in range(W):
        if i[j][k] == '.':
            if k == 0 or j == H - 1 or i[j+1][k-1] == '.':
                if i[j+1][k] == '
                    if j == H - 1 or k == W - 1 or i[j+1][k+1] == '.':
                        if j > H - 3 or i[j+2][k] == '.':
                            result = "No"


print(result)

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


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

print("Yes")

Solution (Python):
import numpy as np

i = input().split(' ')
H = int(i[0])
W = int(i[1])

arr = []

for h in range(0,H):
    s = input().replace('\n', "")
    s = s.replace('.', "0")
    s = s.replace('
    arr.append(list(s))

arr = np.array(arr, dtype=int)
able = "Yes"

for i in range(0,H):
    for j in range(0,W):
        if arr[i,j] == 0:
            continue
        localAble = 0
        if 0<=i-1:
            if arr[i-1,j] == 1:
                localAble = 1
        if i+1<H:
            if arr[i+1,j] == 1:
                localAble = 1
        if 0<=j-1:
            if arr[i,j-1] == 1:
                localAble = 1
        if j+1<W:
            if arr[i,j+1] == 1:
                localAble = 1
        if localAble == 0:
            
            
            able = "No"

print(able)

Solution (Python):
import sys
h, w = (int(i) for i in input().split()) 
arr = [['.' for i in range(w)] for j in range(h)]
for j in range(h):
  k = 0
  for char in input():
    arr[j][k] = char
    k += 1
for H in range(h):
  for W in range(w):
    if arr[H][W] =="
      if (H+1 <= h-1 and arr[H+1][W] == ".") and (H-1 >= 0 and arr[H-1][W] == ".") and (W+1 <= w-1 and arr[H][W+1] == ".") and (W-1 >= 0 and arr[H][W-1] == "."):
        print("No")
        sys.exit()
print("Yes")

Solution (Python):
import sys

h,w = map(int, input().split())
a = []
for i in range(w):
  a.append(0)
for i in range(h):
  for s in input():
    if s == "
      a.append(1)
    else:
      a.append(0)
for i in range(w):
  a.append(0)

for i,j in enumerate(a):
  if i < w:
    continue
  if i >= h*w+w:
    break
  if j == 1 and a[i-1]+a[i-w]+a[i+1]+a[i+w] == 0:
    print("No")
    sys.exit()
print("Yes")

Solution (Python):
h, w = list(map(int, input().split()))
grid = []
grid.append(list('.'*(w+2)))
for i in range(h):
    grid.append(['.'] + list(input()) + ['.'])
grid.append(list('.'*(w+2)))
bools = []
for i in range(h):
    for j in range(w):
        if grid[i+1][j+1] == '.':
            bools.append(True)
        else:
            if grid[i][j+1] == '
                bools.append(True)
            else:
                bools.append(False)
if all(bools):
    print('Yes')
else:
    print('No')

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

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

    lst =[]
    for i in range(h):
        tmp = input()
        lst.append(list(tmp))

    flag = False

    for i in range(len(lst)):
        if flag:
            break

        for j in range(len(lst[i])):
            if lst[i][j] == "
                if j != w - 1:
                    if lst[i][j+1] == "
                        continue

                if j != 0:
                    if lst[i][j-1] == '
                        continue

                if i != 0:
                    if lst[i-1][j] == '
                        continue

                if i != h -1:
                    if lst[i+1][j] == '
                        continue

                print("No")
                flag = True
                break

    if flag == False:
        print("Yes")

if __name__ == "__main__":
        main()

Solution (Python):
import numpy as np
H, W = map(int, input().split())

cambus = []
for h in range(H):
    cambus.append(list(input()))


def judge(_cambus, w, h):
    global W, H
    now = _cambus[h][w]
    if now == '.':
        return True
    status = False
    for dx, dy in zip([-1, 1, 0, 0], [0, 0, 1, -1]):
        x = w + dx
        y = h + dy
        if x > -1 and x < W and y > -1 and y < H:
            if now == _cambus[y][x]:
                status = True
    return status


flag =  True
for w in range(W):
    for h in range(H):
        flag = judge(cambus, w, h)
        if not flag: break
    if not flag: break

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

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

for i in range(H):
    if i == 0:
        for j in range(W):
            if j == 0 :
                if l[i][j] == '
                    if l[i+1][j] == '.' and l[i][j+1] == '.':
                        print("No")
                        sys.exit()
            if j == W -1 :
                 if l[i][j] == '
                    if l[i+1][j] == '.' and l[i][j-1] == '.':
                        print("No")
                        sysexit()
            else :
                if l[i][j] == '
                    if l[i+1][j] == '.' and l[i][j-1] == '.' and l[i][j+1] == '.':
                        print("No")
                        sys.exit()
    if i == H -1:
        for j in range(W):
            if j == 0 :
                if l[i][j] == '
                    if l[i-1][j] == '.' and l[i][j+1] == '.':
                        print("No")
                        sys.exit()
            if j == W -1 :
                 if l[i][j] == '
                    if l[i-1][j] == '.' and l[i][j-1] == '.':
                        print("No")
                        sys.exit()
            else :
                if l[i][j] == '
                    if l[i-1][j] == '.' and l[i][j-1] == '.' and l[i][j+1] == '.':
                        print("No")
                        sys.exit()
    else :
        for j in range(W):
            if j == 0 :
                if l[i][j] == '
                    if l[i-1][j] == '.' and  l[i+1][j] == '.' and l[i][j+1] == '.':
                        print("No")
                        sys.exit()
            if j == W -1 :
                 if l[i][j] == '
                    if l[i-1][j] == '.' and  l[i+1][j] == '.' and l[i][j-1] == '.':
                        print("No")
                        sys.exit()
            else :
                if l[i][j] == '
                    if l[i-1][j] == '.' and  l[i+1][j] == '.' and l[i][j-1] == '.' and l[i][j+1] == '.':
                        print("No")
                        sys.exit()

print("Yes")

Solution (Python):
n = input().split()

n = [int(n[0]), int(n[1])]
H = n[0]
W=n[1]

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

c = True
for i in range(H):
    for j in range(W):
        if(s[i][0][j] == '
            if(i == 0):
                if(j == 0):
                    if(s[i + 1][0][j] == '.' and s[i][0][j + 1] == '.'):
                        c = False
                        break
                elif(j == W - 1):
                    if(s[i+1][0][j ] == '.' and s[i][0][j-1] == '.'):
                        c = False
                        break
                else:
                     if(s[i + 1][0][j] == '.' and s[i][0][j + 1] == '.' and s[i][0][j-1] == '.'):
                        c = False
                        break
            elif(i == H - 1):
                if(j == 0):
                    if(s[i - 1][0][j] == '.' and s[i][0][j +1] == '.'):
                        c = False
                        break
                elif(j == W - 1):
                    if(s[i-1][0][j] == '.' and s[i][0][j-1] == '.'):
                        c = False
                        break
                else:
                     if(s[i - 1][0][j] == '.' and s[i][0][j + 1] == '.' and s[i][0][j-1] == '.'):
                        c = False
                        break
            else:
                if(j == 0):
                    if(s[i - 1][0][j] == '.' and s[i][0][j +1] == '.' and s[i + 1][0][j] == '.'):
                        c = False
                        break
                elif(j == W - 1):
                    if(s[i-1][0][j] == '.' and s[i][0][j-1] == '.' and s[i + 1][0][j] == '.'):
                        c = False
                        break
                else:
                     if(s[i - 1][0][j] == '.' and s[i][0][j + 1] == '.' and s[i][0][j-1] == '.' and s[i + 1][0][j] == '.'):
                        c = False
                        break
                
    
if(c):
    print("Yes")
else:
    print("No")

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

for h in range(H):
    input_line = input()
    l = []
    [l.append(input_line[i]=='
    canvas.append(l)

for h in range(H):
    for w in range(W):
        if canvas[h][w]:
            if not((h!=0 and canvas[h-1][w]) or (w!=0 and canvas[h][w-1]) or (h!=H-1 and canvas[h+1][w]) or (w!=W-1 and canvas[h][w+1])):
                print('No')
                break
    else:
        continue
    break
else:
    print('Yes')

Solution (Python):
H, W = map(int, raw_input().split())
P = [list(raw_input()) for h in range(H)]
ans = True
P.insert(0, ['.' for w in range(W)])
P.append(['.' for w in range(W)])
for i in range(len(P)):
  P[i].insert(0, '.')
  P[i].append('.')
for h in range(1,H+1):
  for w in range(1, W+1):
    if P[h][w] == '
      if P[h][w+1] != '
        ans = False
print 'Yes' if ans else 'No'

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

result = True
for i in range(h):
    for j in range(w):
        if P[i][j] == '
            try:
                up = P[i-1][j]
            except:
                up = ''
            try:
                down = P[i+1][j]
            except:
                down = '.'
            try:
                right = P[i][j+1]
            except:
                right = '.'
            try:
                left = P[i][j-1]
            except:
                left = '.'

            if up == '.' and down == '.' and right == '.' and left == '.':
                result = False

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

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

d=[]

d.append("."*(w+2))

for i in range(h):
    r = input()
    d.append("."+r+".")
    
d.append("."*(w+2))



no = False

def isok(d,i,j):
    c = 0
    c = c+1 if d[i-1][j]=="
    c = c+1 if d[i][j-1]=="
    c = c+1 if d[i][j+1]=="
    c = c+1 if d[i+1][j]=="
    result= True if c > 0 else False
    return result
        
    
for i in range(1,h+2):
    if no == True:
        break
    for j in range(1,w+2):
        if no == True:
            break
        if d[i][j] == "
            a = isok(d,i,j)
            if a == False:
                no = True
                break


result = "No" if no==True else "Yes"
print(result)

Solution (Python):

"""
Created on Sat May  5 20:55:26 2018
ABC096-3
@author: maezawa
"""

dxy = [[-1,0],[0,1],[1,0],[0,-1]]

def is_connect(i,j):
    global dxy
    global s
    for d in dxy:
        
        if s[i+d[0]][j+d[1]] == '
            return True
    return False

h, w = list(map(int, input().split()))
s = ['-'*(w+2)]
for i in range(h):
    s_in = input()
    s_temp = '-'+s_in+'-'
    s.append(s_temp)
s.append('-'*(w+2))



is_paint = 'Yes'
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == '
            if is_connect(i,j):
                continue
            else:
                is_paint = 'No'
                break

print(is_paint)

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

m = 0

for i in range(1,h-1):
    for j in range(1,w-1):
        if array[i][0][j] == '
            m = m+1
        else:
            pass

for i in range(1,h-1):
    if array[i][0][0]=='
        m = m + 1
    else:
        pass

for i in range(1,h-1):
    if array[i][0][w-1]=='
        m = m + 1
    else:
        pass

for j in range(1,w-1):
    if array[0][0][j]=='
        m = m + 1
    else:
        pass

for j in range(1,w-1):
    if array[h-1][0][j]=='
        m = m + 1
    else:
        pass

if array[0][0][0]=='
    m = m + 1
else:
    pass

if array[0][0][w-1]=='
    m = m + 1
else:
    pass

if array[h-1][0][w-1]=='
    m = m + 1
else:
    pass


if array[h-1][0][0]=='
    m = m + 1
else:
    pass

if m>=1:
    print('No')
else:
    print('Yes')

Solution (Python):
def a(n,x):
    if n<0:
        return n+1
    elif n >= x:
        return n-1
    else:
        return n
def f():
    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 s[a(i-1,h)][j]=='.' and s[a(i+1,h)][j]=='.' and s[i][a(j-1,w)]=='.' and s[i][a(j+1,w)]=='.':
                    return 'No'
    return 'Yes'

print(f())

Solution (Python):
def printg():
	for i in range(H+2):
		print(G[i])

def p(s):
	if s == '
		return True
	else:
		return False

def isok(i,j):
	u = p(G[i][j-1])
	r = p(G[i+1][j])
	d = p(G[i][j+1])
	l = p(G[i-1][j])
	if u or r or d or l:
		return True
	else:
		return False

if __name__ == '__main__':
	H,W = map(int,input().split())
	G = [['B']*(W+2) for _ in range(H+2)]

	for i in range(H):
		l = input()
		for j in range(W):
			G[i+1][j+1] = l[j]

	for i in range(H+1):
		for j in range(W+1):
			if G[i][j] == '
				if not isok(i,j):
					print('No')
					exit()

	print('Yes')

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

ans = True
for h,line in enumerate(canvas):
    for w,dot in enumerate(line):
        if dot == '
            ans0 = False
            if h-1 >=0 and canvas[h-1][w] == "
            if h+1 < H and canvas[h+1][w] == "
            if w-1 >=0 and canvas[h][w-1] == "
            if w+1 < W and canvas[h][w+1] == "
            if ans0 == False :
                ans = False
                break

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

Solution (Python):
h, w = input().split()
h = int(h)
w = int(w)
field = []
for _ in range(h):
    field.append(input())
    
ans = True
for i in range(h):
    for j in range(w):
        if field[i][j] == '
            temp = 1
            dd = [(1, 0), (-1, 0), (0, 1), (0, -1)]
            for ddd in dd:
                dx, dy = ddd
                nx, ny = i + dx, j + dy
                if nx >= 0 and nx < h and ny >= 0 and ny < w and field[nx][ny] == '
                    temp += 1
            if temp == 1:
                ans = False
                break

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

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

checked =[ [ 0 for i in range(W)   ] for j in range(H)]




def check(i,j):
    if checked[i][j] == 1:
        return True
    if s[i][j] == ".":
        return True
    if i == 0 and j == 0:
        if s[1][0] == "
            checked[1][0] = 1
            return True
        elif s[0][1] == "
            checked[0][1] = 1
            return True
        else:
            return False
    if i == 0 and j == W -1:
        if s[1][j] == "
            checked[i][j] == 1
            return True
        elif s[0][j-1] == "
            checked[0][j-1] = 1
            return True
        else:
            return False
    if i == H - 1 and j == 0:
        if s[i - 1][0] == "
            checked[i- 1][0] = 1
            return True
        elif s[i][1] == "
            checked[i][1] = 1
            return True
        else:
            return False
    if i == H -1 and j == W - 1:
        if s[i - 1][j] == "
            checked[i- 1][j] = 1
            return True
        elif s[i][j - 1] == "
            checked[i][j -1] = 1
            return True
        else:
            return False
    if  i == 0:
        if s[i + 1][j] == "
            checked[i+1][j] = 1
            return True
        if s[i][j -1] == "
            checked[i][j-1] = 1
            return True
        if s[i][j+1] == "
            checked[i][j+1] = 1
            return True
        else:
            return False
    if i == H - 1:
        if s[i - 1][j] == "
            checked[i-1][j] = 1
            return True
        if s[i][j -1] == "
            checked[i][j-1] = 1
            return True
        if s[i][j+1] == "
            checked[i][j+1] = 1
            return True
        else:
            return False
    if j == 0:
        if s[i - 1][j] == "
            checked[i- 1][j] = 1
            return True
        if s[i + 1][j] == "
            checked[i+ 1][j] = 1
            return True
        elif s[i][j + 1] == "
            checked[i][ j +1] = 1
            return True
        else:
            return False
    if j == W - 1:
        if s[i - 1][j] == "
            checked[i- 1][j] = 1
            return True
        if s[i + 1][j] == "
            checked[i+ 1][j] = 1
            return True
        elif s[i][j - 1] == "
            checked[i][ j -1] = 1
            return True
        else:
            return False
    else:
        if s[i - 1][j] == "
            checked[i- 1][j] = 1
            return True
        if s[i + 1][j] == "
            checked[i+ 1][j] = 1
            return True
        elif s[i][j - 1] == "
            checked[i][ j -1] = 1
            return True
        elif s[i][j + 1] == "
            checked[i][ j +1] = 1
            return True
        else:
            return False


for i,sw in enumerate(s):
    for j, sh in enumerate(sw):
        flag = check(i,j)
        if not flag:
            print("No")
            exit()

print("Yes")

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

kabe_up_down = []
for i in range(w+2):
    kabe_up_down.append('.')
pic.append(kabe_up_down)

for i in range(h):
    onelist = ['.']
    inp = list(str(input()))
    for mm in range(len(inp)):
        onelist.append(inp[mm])
    onelist.append('.')
    pic.append(onelist)
    
pic.append(kabe_up_down)    


flag = 1
a = 'a'
for i in range(1,h+1):
    for j in range(1,w+1):
        here = pic[i][j]
        if here =='
            pic[i][j] = a
            pic[i+1][j] = a
        elif here =='
            pic[i][j] = a
            pic[i][j+1] = a
        elif here =='
            pic[i][j] = a
            pic[i-1][j] = a
        elif here =='
            pic[i][j] = a
            pic[i][j+1] = a    
            
for i in range(1,h+1):
    for j in range(1,w+1):
        here = pic[i][j]
        if here == '
            pic[i][j] = a
            pic[i+1][j] = a
        elif here =='
            pic[i][j] = a
            pic[i][j+1] = a
        elif here =='
            pic[i][j] = a
            pic[i-1][j] = a
        elif here =='
            pic[i][j] = a
            pic[i][j+1] = a    
        
for i in range(1,h+1):
    for j in range(1,w+1):
        here = pic[i][j]
        if here == a and pic[i+1][j] == '
            pic[i][j] = a
            pic[i+1][j] = a
        elif here =='a' and pic[i][j+1] == '
            pic[i][j] = a
            pic[i][j+1] = a
        elif here =='a' and pic[i-1][j] == '
            pic[i][j] = a
            pic[i-1][j] = a
        elif here =='a' and pic[i][j+1] == '
            pic[i][j] = a
            pic[i][j+1] = a            
            
for i in range(1,h+1):
    for j in range(1,w+1):
        if pic[i][j] == '
            flag = 0
            

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

Solution (Python):

if __name__ == "__main__":
    H, W = list(map(int, input().split()))
    canvas = []
    for h in range(0, H):
        canvas.append(input())
    
    for i in range(H):
        for j in range(W):
            
            if canvas[i][j] == "
                if (i-1 >= 0) and (canvas[i-1][j] == "."):
                    if (i+1 < H) and (canvas[i+1][j] == "."):
                        if (j-1 >= 0) and (canvas[i][j-1] == "."):
                            if (j+1 < W) and (canvas[i][j+1] == "."):
                                print("No")
                                exit()
    print("Yes")

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

T.append(['.']*(W+2))

ans = 'Yes'
for y in range(1,H+1):
    for x in range(1,W+1):
        if ((T[y][x]=='
            and (T[y+1][x]=='.') and (T[y][x+1]=='.') and (T[y][x-1]=='.') ):
            ans = 'No'

print(ans)

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

h,w = na()
ar = []
for i in range(h):
    ar.append(ns())

safe = True
def ex():
    for i in range(len(ar)):
        for j in range(w):
            if ar[i][j] == '
                if i == 0:
                    if j == 0:
                        if ar[i][j+1] == "
                            continue
                        else:
                            return False
                    elif j == w-1:
                        if ar[i][j-1] == "
                            continue
                        else:
                            return False
                    else:
                        if ar[i][j-1] == "
                            continue
                        else:
                            return False
                elif i == len(ar)-1:
                    if j == 0:
                        if ar[i][j+1] == "
                            continue
                        else:
                            return False
                    elif j == w-1:
                        if ar[i][j-1] == "
                            continue
                        else:
                            return False
                    else:
                        if ar[i][j-1] == "
                            continue
                        else:
                            return False
                else:
                    if j == 0:
                        if ar[i][j+1] == "
                            continue
                        else:
                            return False
                    elif j == w-1:
                        if ar[i][j-1] == "
                            continue
                        else:
                            return False
                    else:
                        if ar[i][j-1] == "
                            continue
                        else:
                            return False
    return True
if ex() == True:
    print("Yes")
else:
    print("No")

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

Solution (Python):





if __name__ == '__main__':
    h, w = list(map(int, input().split()))
    board = [list(map(str, input())) for _ in range(h)]
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    for i in range(h):
        for j in range(w):
            if board[i][j] == '
                count = 0

                for k in range(len(dx)):
                    x = i + dx[k]
                    y = j + dy[k]

                    if (x >= 0) and (x < h) and (y >= 0) and (y < w) and (board[x][y] == "
                        count += 1

                if count == 0:
                    print('No')
                    exit()

    print('Yes')

Solution (Python):


import math
import sys
import itertools
import numpy as np

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

for i in range(1,h+1):
    temp = list(input())
    for j in range(1,w+1):
        a[i][j] = temp[j-1]


ok =1
for i in range(1,h+1):
    for j in range(1,w+1):
        if a[i][j]== "
            if a[i-1][j]=="." and a[i+1][j]=="." and a[i][j-1]=="." and a[i][j+1]==".":
                ok = 0
                break
    if ok == 0:
        break

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

Solution (Python):
import sys
sys.setrecursionlimit(100000)

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

canv=[]
for i in range(H):
    canv.append([])
    line_input=input() 
    for j in range(W):
        canv[i].append(line_input[j:j+1]) 

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

def dfs(x,y):
    for i in range(4):
        canv[x][y]="."
        nx = x + dx[i]
        ny = y + dy[i]
        if 0<=nx and nx<H and 0<=ny and ny<W:
            if canv[nx][ny]=="
                dfs(nx,ny)

for i in range(H):
    for j in range(W):
        for k in range(4):
            nx1 = i + dx[k]
            ny1 = j + dy[k]
            if 0<=nx1 and nx1<H and 0<=ny1 and ny1<W:
                if canv[i][j]=="
                    dfs(i,j)
flg = True
for i in range(H):
    for j in range(W):
        if canv[i][j]=="
            flg = False
if flg: print("Yes")
else: print("No")