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())
t=[list(input())for i in range(h)]
def check(x,y):
    dx=[0,0,1,-1]
    dy=[1,-1,0,0]
    for k in range(4):
        x=i+dx[k]
        y=j+dy[k]
        if 0<=x and x<h and 0<=y and y<w and t[x][y]=="
            return True
for i in range(h):
    for j in range(w):
        if t[i][j]=="
            if check(i,j):
                pass
            else:
                print("No")
                exit()
print("Yes")

Solution (Python):

H,W = map(int,input().split())
mtrx = []
for i in range(H):
    col = list(input())
    mtrx.append(col)
    
cross = [[0,1],[-1,0],[0,-1],[1,0]]

def check(i,j):
    if mtrx[i][j] == "
        for ij in cross:
            [im,jm] = ij
            iNew = i + im
            jNew = j + jm
            if 0 <= iNew < H and 0 <= jNew <W:
                if mtrx[iNew][jNew] == "
                    return
        else:
            return True
    

for i in range(H):
    for j in  range(W):
        if check(i,j):
            print("No")
            break
    else:
        continue
    break
else:
    print("Yes")

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

def solve(h,w):
    for i in range(1, h - 1):
        for j in range(1, w - 1):
            if s[i][j] == "
                if s[i - 1][j] == "
                    continue
                elif s[i + 1][j] == "
                    continue
                elif s[i][j - 1] == "
                    continue
                elif s[i][j + 1] == "
                    continue
                else:
                    return "No"
    return "Yes"

print(solve(h,w))

Solution (Python):
h,w=map(int,input().split())
t=[list(input())for i in range(h)]
def check(x,y):
    dx=[0,0,1,-1]
    dy=[1,-1,0,0]
    jugde=False
    for k in range(4):
        i=x+dx[k]
        j=y+dy[k]
        if 0<=i and i<h and 0<=j and j<w and t[i][j]=="
            jugde=True
    if jugde==False:
        return False
    return True
for i in range(h):
    for j in range(w):
        if t[i][j]=="
            if check(i,j):
                jugde=True
            else:
                print("No")
                exit()
print("Yes")

Solution (Python):

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


masu = [['.' for i in range(W+2)] for j in range(H+2)]
for h in range(H):
    s = "."+input()+"."
    masu[h+1] = s



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

print("Yes")

Solution (Python):
H, W = map(int, input().split())
 
x = ["."*(W+2)]
for k in range(H):
    x.append("."+input()+".")
x.append("."*(W+2))
 
for k in range(1,W+1):
    for l in range(1,H+1):
        if x[l][k]=="
            if x[l+1][k]=="
                pass
            else:
                print("No")
                exit()
print("Yes")

Solution (Python):
h,w=map(int,input().split());m=["."];l=[m*(w+2)];p=l+[m+list(map(str,input()))+m for i in range(h)]+l
print("Yes"if all([any([p[i+x[0]][I+x[1]]=="

Solution (Python):
h,w=map(int,input().split());p=[["."]*(w+2)]+[["."]+list(map(str,input()))+["."]for i in range(h)]+[["."]*(w+2)]
print("Yes"if all([any([p[i+x[0]][I+x[1]]=="

Solution (Python):
h,w=map(int,input().split())
p=[["."]*(w+2)]+[["."]+list(map(str,input()))+["."]for i in range(h)]+[["."]*(w+2)]
print(["No","Yes"][int(all([any([p[i+x[0]][I+x[1]]=="

Solution (Python):


def main():
    H, W = list(map(int, input().split()))
    grid = [[0 for i in range(W+2)] for j in range(H+2)]

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

if __name__ == '__main__':
    main()

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

ans='Yes'
for i in range(1,H-1):
    for j in range(1,W-1):
        if cambas[i][j]=='
            ans='No'
            break
                
print(ans)

Solution (Python):
import sys
h,w = map(int,raw_input().split())

arr = []

for i in range(h):
	arr.append(list(raw_input()))

field = [['.' for i in range(w)] for j in range(h)]

direct = [[0,-1],[1,0],[0,1],[-1,0]]

for i in range(h):
	for j in range(w):
		for k in range(4):
			dx = j + direct[k][1] 
			dy = i + direct[k][0]
			if -1 < dx and dx < w and -1 < dy and dy < h :
				if arr[i][j] == '
					field[i][j] = '
					field[dy][dx] = '

for i in range(h):
	for j in range(w):
		if arr[i][j] != field[i][j]:
			print 'No'
			sys.exit()

print 'Yes'

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

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

Solution (Python):
def m():
    h, w = map(int, input().split())
    a = [list(("."+input()+".")) for _ in range(h)]
    a.insert(0, ['.' for _ in range(w+2)])
    a.insert(h+1, ['.' for _ in range(w+2)])
    for i in range(1,h+1):
        for j in range(1,w+1):
            if a[i][j] != "
                continue
            if a[i+1][j] == "
                continue
            if a[i][j+1] == "
                continue
            if a[i-1][j] == "
                continue
            if a[i][j-1] == "
                continue
            return "No"
    return "Yes"

print(m())

Solution (Python):
H, W = map(int, input().split())
matrix = []
for _ in range(H):
    row = input()
    matrix.append(row)
no_flag = False
for i, row in enumerate(matrix):
    for j, y in enumerate(row):
        if y == '
            if j != 0 and matrix[i][j - 1] == '
                continue
            elif j != W - 1 and matrix[i][j + 1] == '
                continue
            elif i != 0 and matrix[i - 1][j] == '
                continue
            elif i != H - 1 and matrix[i + 1][j] == '
                continue
            else:
                no_flag = True
                break
    if no_flag == True:
        print('No')
        break
else:
    print('Yes')

Solution (Python):
H,W = map(int, input().split())
A = [list(input()) for i in range(H)]
Flag = True
for i in range(H):
    for j in range(W):
        if A[i][j] == '
            if A[max(0, i-1)][j] == '
                pass
            else:
                Flag = False
                break
    if Flag == False:
        break
if H == 1 and W == 1 and A[0][0] == '
    Flag = False
if Flag == True:
    print('Yes')
else:
    print('No')

Solution (Python):
H, W = map(int, input().split())
s_list = [input() for _ in range(H)]
ans = 'Yes'
for i in range(1, H - 1):
	for j in range(1, W - 1):
		if s_list[i][j] == '
			ans = 'No'
			break
print(ans)

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

row = []
for x in range(h):
    col = list(input())
    row.append(col)

out = "Yes"

for x in range(h):
    for y in range (w):
        if row[x][y] == "
           
            if  x > 0 and row[x-1][y] == "
                pass
            elif x < h-1 and row[x+1][y] == "
                pass
            elif y > 0 and row[x][y-1] == "
                pass
            elif y < w-1  and row [x][y+1] == "
                pass
            else:
                out = "No"
                break
        pass

print(out)

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


s.append('.'*(W+2))
for i in range(H):
  s.append('.'+input()+'.')
s.append('.'*(W+2))


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

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

b.append(list('.'*(w*2)))

for y in range(1,h+1):
    for x in range(1,w+1):
        if b[y][x]=='
            up   = b[y-1][x]
            down = b[y+1][x]
            left = b[y][x-1]
            right= b[y][x+1]

            if up=='.' and down=='.' and left=='.' and right=='.':
                print('No')
                exit()

print('Yes')

Solution (Python):
x=input().split()
h=int(x[0])
w=int(x[1])
s=['']*h*w
for i in range(h):
    row=input()
    for j in range(w):
        s[i*w+j]=row[j]
i=0
boo=True

while i<h*w:
    if i<w:
        if i==0:
            if s[i]=='
                boo=False
                break
        elif i==w-1:
            if s[i]=='
                boo=False
                break
        else:
            if s[i]=='
                boo=False
                break
    elif i%w==0:
        if i==w*(h-1):
            if s[i]=='
                boo=False
                break
        else:
            if s[i]=='
                boo=False
                break
    elif i%w==w-1:
        if i==h*w-1:
            if s[i]=='
                boo=False
                break
        else:
            if s[i]=='
                boo=False
                break
    elif i>w*(h-1):
        if s[i]=='
            boo=False
            break
    else:
        if s[i]=='
            boo=False
            break
    i+=1
if boo:
    print('Yes')
else:
    print('No')

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

for y in range(1, h + 1):
    for x in range(1, w + 1):
        if field[y][x] == "
                if("
                    pass
                else:
                    print("No")
                    quit()

print("Yes")

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

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

Solution (Python):
H, W = map(int, input().split())
s_list = [input() for _ in range(H)]
ans = 'Yes'
for i in range(1, H - 1):
	for j in range(1, W - 1):
		if s_list[i][j] == '
			ans = 'No'
			break
print(ans)

Solution (Python):
import sys

H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
for i in S:
    i.insert(0, '.')
    i.append('.')
S.insert(0, ['.' for _ in range(W+2)])
S.append(['.' for _ in range(W+2)])
DI = [-1, 0, 0, 1]
DJ = [0, -1, 1, 0]
count = 0

for i in range(1, H+1):
    for j in range(1, W+1):
        if S[i][j] == '
            
            for di, dj in zip(DI, DJ):
                if S[i+di][j+dj] == '
                    count += 1
            if count == 0:
                print('No')
                sys.exit()
            count = 0
print('Yes')

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

for i in range(h):
  for j in range(w):
    f = 0
    if s[i][j] == "
      for dx_ in dx:
        for dy_ in dy:
          if (dx_==0 and dy_!=0) or (dx_!=0 and dy_==0):
            nx, ny = j+dx_, i+dy_
            if 0<=nx<w and 0<=ny<h:
              if s[ny][nx] == "
                f = 1
      if f == 0:
        flag = 1
if flag:
  print("No")
else:
  print("Yes")

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

ssum = 0
ssum2 = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == "
            
            if 0 < i:
                
                if s[i-1][j] == "
                    s2[i][j] = True
            if i < h-1:
                
                if s[i+1][j] == "
                    s2[i][j] = True
            if 0 < j:
                
                if s[i][j-1] == "
                    s2[i][j] = True
            if j < w-1:
                
                if s[i][j+1] == "
                    s2[i][j] = True
            if s2[i][j]:
                ssum2 += 1
            ssum += 1
if ssum == ssum2:
    print('Yes')
else:
    print('No')

Solution (Python):

def main():
    y, x = [int(i) for i in input().split()]
    a = []
    for i in range(y):
        a.append(input().strip())

    for i in range(x):
        for j in range(y):
            link = False
            if a[j][i] == '
                if i-1 >= 0 and a[j][i-1] == '
                    link = True
                if i+1 < x and a[j][i+1] == '
                    link = True
                if j-1 >= 0 and a[j-1][i] == '
                    link = True
                if j+1 < y and a[j+1][i] == '
                    link = True

                if not link:
                    print('No')
                    return

    print('Yes')

if __name__ == '__main__':
    main()

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

for i in range(1, h+1):
    line = input()
    for j in range(1, w+1):
        s[i][j] = line[j-1]

flag = True

for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j] == '
            if s[i-1][j] == '
                pass
            else:
                flag = False
                break

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

Solution (Python):

I = raw_input().split(" ")
H = int(I[0])
W = int(I[1])
A = [list(raw_input()) for i in range(H)]
ans = 0
for X in range(H):
    for Y in range(W):
        counter = 0
        if A[X][Y] == "
            if X != 0 and A[X][Y] == A[X - 1][Y]:
                counter += 1
            if X != H - 1 and A[X][Y] == A[X + 1][Y]:
                counter += 1
            if Y != 0 and A[X][Y] == A[X][Y - 1]:
                counter += 1
            if Y != W - 1 and A[X][Y] == A[X][Y + 1]:
                counter += 1
            if counter == 0:
                ans += 1
if ans == 0:
    print "Yes"
else:
    print "No"

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

s.append(['.']*W)
s.insert(0, ['.']*W)
for i in range(H+2):
  s[i].append('.')
  s[i].insert(0, '.')


ans='Yes'
for i in range(1,H+1):
  for j in range(1,W+1):
    if s[i][j] == '.':
      continue
    if s[i-1][j] == '
      continue
    else:
      ans='No'
      break

print(ans)

Solution (Python):
y,x=map(int,input().split())
g=[input() for i in range(y)]
flag=True
for yy in range(1,y-1):
    for xx in range(1,x-1):
        if g[yy][xx]=='
            if g[yy-1][xx]==g[yy+1][xx]==g[yy][xx-1]==g[yy][xx+1]=='.':
                flag=False
if(flag):
    print("Yes")
else:
    print("No")

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

table = []

for i in range(H):
	table.append(list(input()))

counter = 0
	
def check(x,y):
	counter = 0
			
	if x > 0:
		if table[y][x-1] == '
			counter += 1
			
	if x < W-1:
		if table[y][x+1] == '
			counter += 1
	
	if y > 0:
		if table[y-1][x] == '
			counter += 1
	
	if y < H-1:
		if table[y+1][x] == '
			counter += 1
	
	if counter == 0:
		print('No')
		quit()
			
	

for y in range(H):
	for x in range(W):
		if table[y][x] == '
			check(x,y)

print ('Yes')

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

for i in range(1, H - 1):
	for j in range(1, W - 1):
		if s_list[i][j] == "
			if s_list[i-1][j] == "." and s_list[i+1][j] == "." and s_list[i][j-1] == "." and s_list[i][j+1] == ".":
				flag = False
				break
if flag:
	print("Yes")
else:
	print("No")

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

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

for i in range(H):
    for j in range(W):
        if not check(i,j):
            print('No')
            exit()
print('Yes')

Solution (Python):
h,w=map(int,input().split())
lis = []
for _ in range(h):
 lis.append(input())
for i in range(h):
 for j in range(w):
  if lis[i][j] == "
    if (i == 0 or lis[i-1][j] == ".") and (j==0 or lis[i][j-1] == ".")  and (i == h-1 or lis[i+1][j] == ".") and (j == w-1 or lis[i][j+1] == "."):
      print("No")
      quit()
print("Yes")

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

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

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

list_masu = []

for i in range(H):
	str1 = str(input())
	charlist = list(str1)
	list_masu.append(charlist)

blacklist = []
for n in range(H):
	for m in range(W):
		if(list_masu[n][m]=="
			blacklist.append((n,m))

blacklist.sort()

count = 0

for b in range(0,len(blacklist)):
	for i in range(0,len(blacklist)):
		if(b!=i and blacklist[b][0] == blacklist[i][0]):
			if((blacklist[b][1] == blacklist[i][1]+1) or (blacklist[b][1] == blacklist[i][1]-1)):
				count += 1
				break
		elif(b!=i and blacklist[b][1] == blacklist[i][1]):
			if((blacklist[b][0] == blacklist[i][0]+1) or (blacklist[b][0] == blacklist[i][0]-1)):
				count += 1
				break


if(count==len(blacklist)):
	print("Yes")
else:
	print("No")

Solution (Python):

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

c = []


for i in range(H):
    s = list(input())
    c.append(s)



count = 0


for i in range(H):
    for j in range(W):
        
        try:
            if (c[i][j] == '
                
                count += 1
        except IndexError:
            if i == W - 1 and i == H - 1:
                if (c[i][j] == '
                    count += 1

            elif i == W - 1:
                if (c[i][j] == '
                    count += 1

            elif i == H - 1:
                if (c[i][j] == '
                    count += 1

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

Solution (Python):

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

c = []


for i in range(H):
    s = list(input())
    c.append(s)



count = 0


for i in range(H):
    for j in range(W):
        
        try:
            if (c[i][j] == '
                
                count += 1
        except IndexError:
            if i == W - 1 and i == H - 1:
                if (c[i][j] == '
                    count += 1

            elif i == W - 1:
                if (c[i][j] == '
                    count += 1

            elif i == H - 1:
                if (c[i][j] == '
                    count += 1

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

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

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

Solution (Python):
r,c=[int(x) for x in str(input()).split()]
image=[[0 for x in range(0,c+2)]]
for i in range(1,r+1):
  x=list(str(input()))

  d=[0]
  for i in range(0,c):
    if x[i]=='.':
      d.append(0)
    else:
      d.append(1)
  d.append(0)

  image.append(d)
image+=[[0 for x in range(0,c+2)]]

counter=0
for x in range(1,r+1):
  for y in range(1,c+1):
    if image[x][y]==1:
      s=image[x-1][y]
      t=image[x+1][y] 
      u=image[x][y-1] 
      v=image[x][y+1]
      if s+t+u+v==0:

        counter=-1
if counter==-1:
  print('No')
else:
  print('Yes')

Solution (Python):
H, W = map(int, input().split())
S = ['a' * (W+2)] + [list('a' + input() + 'a') for i in range(H)] + ['a' * (W+2)]
for i in range(H):
    for j in range(W):
        if S[i+1][j+1] == '
            if [S[i][j+1], S[i+1][j], S[i+1][j+2], S[i+2][j+1]].count('
                print('No')
                exit()
print('Yes')

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

for i in range(h):
    l2 = list(input())
    l1.append(l2)

is_no = 0
for i in range(h):
    if is_no:
        break
    for j in range(w):
        if is_no:
            break
        if l1[i][j] == '
            if i == 0:
                if j == 0:
                    if l1[i][j + 1] == '.' and l1[i + 1][j] == '.':
                        is_no = 1
                        
                elif j == w - 1:
                    if l1[i][j - 1] == '.' and l1[i + 1][j] == '.':
                     is_no = 1

                else:
                    if l1[i][j - 1] == '.'  and l1[i][j + 1] == '.' and l1[i + 1][j] == '.':
                        is_no = 1


            elif i == h - 1:
                if j == 0:
                    if l1[i][j + 1] == '.' and l1[i - 1][j] == '.':
                        is_no = 1

                elif j == w - 1:
                    if l1[i][j - 1] == '.' and l1[i - 1][j] == '.':
                        is_no = 1

                else:
                    if l1[i][j - 1] == '.'  and l1[i][j + 1] == '.' and l1[i - 1][j] == '.':
                        is_no = 1


            else:
                if j == 0:
                    if l1[i][j + 1] == '.' and l1[i - 1][j] == '.' and l1[i + 1][j] == '.':
                        is_no = 1

                elif j == w - 1:
                    if l1[i][j - 1] == '.' and l1[i - 1][j] == '.' and l1[i + 1][j] == '.':
                        is_no = 1

                else:
                    if l1[i][j - 1] == '.'  and l1[i][j + 1] == '.' and l1[i - 1][j] == '.' and l1[i + 1][j] == '.':
                        is_no = 1


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

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

d = {(i, j):c for i, row in enumerate(s) for j, c in enumerate(row)}

def next_to_black(i, j):
    directions = ((-1, 0), (1, 0), (0, -1), (0, 1))
    surroundings = ((i + a, j + b) for a, b in directions)
    colors = (d.get(cell, '.') for cell in surroundings)
    return any(color == '

black_coords = (coord for coord, c in d.items() if c == '
paintable = all(next_to_black(*coord) for coord in black_coords)
print('Yes' if paintable else 'No')

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

d = {(i, j):c for i, row in enumerate(s) for j, c in enumerate(row)}

surrounds = ((-1, 0), (1, 0), (0, -1), (0, 1))
def black_in_surrounds(i, j):
    return any(d.get((i+a, j+b), '.') == '

if all(black_in_surrounds(i, j) for (i, j), c in d.items() if c == '
    print('Yes')
else:
    print('No')

Solution (Python):
import sys

h, w = map(int, input().split())
canvas = [list([i for i in input()]) for j in range(h)]
for i in range(h):
    for j in range(w):
        if canvas[i][j] == '
            if i == 0 and j == 0:
                if canvas[0][1] == '.' and canvas[1][0] == '.':
                    print('No')
                    sys.exit()
            elif i == 0 and j == w-1:
                if canvas[0][w-2] == '.' and canvas[1][w-1] == '.':
                    print('No')
                    sys.exit()
            elif i == h-1 and j == 0:
                if canvas[h-1][1] == '.' and canvas[h-2][0] == '.':
                    print('No')
                    sys.exit()
            elif i == h-1 and j == w-1:
                if canvas[h-1][w-2] == '.' and canvas[h-2][w-1] == '.':
                    print('No')
                    sys.exit()
            elif i == 0:
                if canvas[0][j-1] == '.' and canvas[0][j+1] == '.' and canvas[1][j] == '.':
                    print('No')
                    sys.exit()
            elif j == 0:
                if canvas[i-1][0] == '.' and canvas[i+1][0] == '.' and canvas[i][1] == '.':
                    print('No')
                    sys.exit()
            elif i == h-1:
                if canvas[h-1][j-1] == '.' and canvas[h-1][j+1] == '.' and canvas[h-2][j] == '.':
                    print('No')
                    sys.exit()
            elif j == w-1:
                if canvas[i-1][w-1] == '.' and canvas[i+1][w-1] == '.' and canvas[i][w-2] == '.':
                    print('No')
                    sys.exit()
            else:
                if canvas[i][j-1] == '.' and canvas[i][j+1] == '.' and canvas[i-1][j] == '.' and canvas[i+1][j] == '.':
                    print('No')
                    sys.exit()
print('Yes')

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

def search_around(i, j):
    ret = False
    if 0 <= i+1 < H and 0 <= j < W:
        if s[i+1][j] == '
            ret = True
    if 0 <= i < H and 0 <= j+1 < W:
        if s[i][j+1] == '
            ret = True
    if 0 <= i-1 < H and 0 <= j < W:
        if s[i-1][j] == '
            ret = True
    if 0 <= i < H and 0 <= j-1 < W:
        if s[i][j-1] == '
            ret = True
    return ret
    
ans = True
for i in range(H):
    s.append(input())
for i in range(H):
    for j in range(W):
        if s[i][j] == '
            if not search_around(i, j):
                ans = False
                break
if ans:
    print('Yes')
else:
    print('No')

Solution (Python):
H, W = map(int, input().split())
cam = [input() for i in range(H)]
ans = 'Yes'
for i in range(1, H-1):
	for j in range(1, W-1):
		if cam[i][j] == "
			if cam[i-1][j] == cam[i+1][j] == cam[i][j-1] == cam[i][j+1] == ".":
				ans = 'No'
				break
print(ans)

Solution (Python):
H, W = map(int, input().split())
a = []
tmp = []
for i in range(H):
    tmp = list(map(str,input().split()))
    a.append(list(tmp[0]))

for i in range(H):
    for j in range(W):
        if a[i][j] == '
            if j - 1 >= 0 and a[i][j - 1] == "
                continue
            elif j + 1 < W and a[i][j + 1] == "
                continue
            elif i + 1 < H and a[i + 1][j] == "
                continue
            elif i - 1 >= 0 and a[i - 1][j] == "
                continue
            else:
                print("No")
                exit()
 
print("Yes")

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

for i in range(H):
    line = input()
    lis = []
    for str in line:
        lis.append(str)
    s.append(lis)


def drawable(h,w):
    for i in [-1,1]:
        if 0 <= w+i < W:

            if s[h][w+i] =='
                return True
    for i in [-1,1]:
        if 0 <= h+i < H:
            if s[h+i][w] =='
                return True

    return False

flag = True
for i in range(H):
    for j in range(W):

        if s[i][j]=='
           flag = False 

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

Solution (Python):
import numpy
import re
import math

def main():
	"""
	テストコード実行
	:return:
	"""
	h, w = map(int, input().split())
	src = [list(input()) for i in range(h)]
	dxy = [(-1, 0), (1, 0), (0, -1), (0, 1)]  

	for y in range(h):
		for x in range(w):
			if src[y][x] is "
				for dx, dy in dxy:
					
					if 0 <= x + dx < w and 0 <= y < h and src[y + dy][x + dx] is "
				else:
					print("No")
					exit()
	print("Yes")



if __name__ == '__main__':
	main()

Solution (Python):
import sys


X = [int(i) for i in input().split()]
H, W = X
grid = []
for row in range(H):
    grid.append([char for char in input()])




if H == 1 and W == 1:
    print('No')
    exit(0)
elif H == 1:
    for w in range(W):
        if grid[0][w] == "
            if w == 0:
                if not(grid[0][w+1] == '
                    print("No")
                    exit(0)
            elif w == W-1:
                if not(grid[0][w-1] == '
                    print("No")
                    exit(0)
            else:
                if not (grid[0][w - 1] == '
                    print("No")
                    exit(0)
elif W == 1:
    for h in range(H):
        if grid[h][0] == "
            if h == 0:
                if not(grid[h+1][0] == '
                    print("No")
                    exit(0)
            elif h == H-1:
                if not(grid[h-1][0] == '
                    print("No")
                    exit(0)
            else:
                if not (grid[h-1][0] == '
                    print("No")
                    exit(0)
else:
    for h in range(H):
        for w in range(W):
            if grid[h][w] == "
                
                if h != 0 and h != H-1 and w != 0 and w != W-1:
                    if not(grid[h+1][w] == "
                        print("No")
                        exit(0)
                
                elif h == 0:
                    if w == 0:
                        if not(grid[h+1][w] == "
                            print("No")
                            exit(0)
                    elif w == W-1:
                        if not(grid[h+1][w] == "
                            print("No")
                            exit(0)
                    else:
                        if not (grid[h + 1][w] == "
                            print("No")
                            exit(0)
                
                elif h == H-1:
                    if w == 0:
                        if not (grid[h - 1][w] == "
                            print("No")
                            exit(0)
                    elif w == W-1:
                        if not (grid[h - 1][w] == "
                            print("No")
                            exit(0)
                    else:
                        if not (grid[h - 1][w] == "
                            print("No")
                            exit(0)
                
                elif w == 0:
                    if not (grid[h + 1][w] == "
                        print("No")
                        exit(0)
                
                elif w == W-1:
                    if not (grid[h + 1][w] == "
                        print("No")
                        exit(0)
print('Yes')