Problem:
 Score: 300 points    Problem Statement  We have a canvas divided into a grid with H rows and W columns. The square at the i -th row from the top and the j -th column from the left is represented as (i, j) . Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}=  # , and to make Square (i, j) white when s_{i, j}=  . . However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black. Determine if square1001 can achieve his objective.      Constraints   H is an integer between 1 and 50 (inclusive).  W is an integer between 1 and 50 (inclusive).  For every (i, j)  (1 \leq i \leq H, 1 \leq j \leq W) , s_{i, j} is # or . .         Input  Input is given from Standard Input in the following format:  H  W  s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}  s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}  :  :  s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}       Output  If square1001 can achieve his objective, print Yes ; if he cannot, print No .        Sample Input 1 3 3
.#.
###
.#.      Sample Output 1 Yes  One possible way to achieve the objective is shown in the figure below. Here, the squares being painted are marked by stars.        Sample Input 2 5 5
#.#.#
.#.#.
#.#.#
.#.#.
#.#.#      Sample Output 2 No  square1001 cannot achieve his objective here.       Sample Input 3 11 11
...#####...
.##.....##.
#..##.##..#
#..##.##..#
#.........#
#...###...#
.#########.
.#.#.#.#.#.
##.#.#.#.##
..##.#.##..
.##..#..##.      Sample Output 3 Yes

Solution (Python):
import sys

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

dir = [(-1, 0), (1, 0), (0, -1), (0, 1)]
for i in range(h):
    for j in range(w):
        if s[i][j] == '
            flag = False
            for d in dir:
                x = j + d[0]
                y = i + d[1]
                if 0 <= x < w and 0 <= y < h and s[y][x] == '
                    flag = True
            if not flag:
                print 'No'
                sys.exit()
print 'Yes'

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

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

Solution (Python):


h, w = map(int, input().split())
cb = []

for _i in range(h):
    s = input()
    cb.append(s)




def find_impossible_tile(cb, i, j, h, w):
    t = cb[i][j]
    
    if t == '.':
        return False
    
    is_black_u = (i > 0 and cb[i-1][j] == '
    is_black_d = (i < h - 1 and cb[i+1][j] == '
    is_black_l = (j > 0 and cb[i][j-1] == '
    is_black_r = (j < w - 1 and cb[i][j+1] == '
    
    return not (is_black_u or is_black_d or is_black_l or is_black_r)
    

found = False
for i in range(h):
    for j in range(w):
        if find_impossible_tile(cb, i, j, h, w):
            found = True
            break
    if found:
        break
        
if not found:
    ans = 'Yes'
else:
    ans = 'No'


print("{}".format(ans))

Solution (Python):
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
r = "Yes"
for i in range(1, h-1):
    for j in range(1, w-1):
        if s[i][j] == "
          r = "No"
print(r)

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

checkMap = [[1 for _ in range(W)] for _ in range(H)]

flag = False
end = False
for i in range(H):
    for j in range(W):
        flag = False
        if(checkMap[i][j] == 1):
            if(map[i][j] == "."):
                flag = True
                checkMap[i][j] = 0
            if(map[i][j] == "
                if(j < W-1 and map[i][j+1] == "
                    checkMap[i][j] = 0
                    checkMap[i][j+1] = 0
                    flag = True
                if(j > 0 and map[i][j-1] == "
                    checkMap[i][j] = 0
                    checkMap[i][j-1] = 0
                    flag = True
                if(i < H-1 and map[i+1][j] == "
                    checkMap[i][j] = 0
                    checkMap[i+1][j] = 0
                    flag = True
                if(i > 0 and map[i-1][j] == "
                    checkMap[i][j] = 0
                    checkMap[i-1][j] = 0
                    flag = True
            if(flag == False):
                print("No")
                end = True
                break
        else:
            flag = True
            continue
        if(flag == False):
            break
    if(flag == False):
        break

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

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

Solution (Python):

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


lonely_sharp = False
for idx in range(h):
    for jdx in range(w):
        
        if sij[idx][jdx] == '
                idx == 0 or sij[idx - 1][jdx] == '.',
                idx == h - 1 or sij[idx + 1][jdx] == '.',
                jdx == 0 or sij[idx][jdx - 1] == '.',
                jdx == w - 1 or sij[idx][jdx + 1] == '.']):
            lonely_sharp = True
            break
if lonely_sharp:
    print('No')
else:
    print('Yes')

Solution (Python):
import numpy as np
import sys
H,W = [int(i) for i in input().split()]

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


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

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

print('Yes')

Solution (Python):
"""
list(map(int,input().split()))
map(int,input().split())
"""
import numpy as np
N,M = map(int,input().split())

arr = [list(input())for i in range(N)]

for i in range(N):
    for j in range(M):

        if arr[i][j] == "
            arr[i][j] = 0
        else:
            arr[i][j] = 1

arr = np.array(arr)
arr = np.pad(arr,1,"constant",constant_values=1)
key = 0

for i in range(N):
    for j in range(M):
        if arr[i+1][j+1] == 0:
            if arr[i+1][j+1] + arr[i][j+1] + arr[i+1][j] + arr[i+2][j+1] + arr[i+1][j+2] >= 4:
                key+=1

if key>=1:
    print("No")
else:
    print("Yes")

Solution (Python):
dr = [-1, 0, 1, 0]
dc = [ 0, 1, 0,-1]

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

ok = True
for i in range(H):
	for j in range(W):
		if s[i][j] == '
			curr = False
			for k in range(4):
				nr = i + dr[k]
				nc = j + dc[k]
				if nr < 0 or nr >= H or nc < 0 or nc >= W:
					continue
				if s[nr][nc] == '
					curr = True
			if curr == False:
				ok = False

print("Yes" if ok == True else "No")

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    h,w = LI()
    a = [[c for c in S()] for _ in range(h)]
    ff = True
    for i in range(h):
        for j in range(w):
            if a[i][j] == '.':
                continue
            f = False
            if (i>0 and a[i-1][j] == '
                f = True
            if not f:
                ff = False
                break
        if not ff:
            break

    if ff:
        return 'Yes'
    return 'No'



print(main())

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

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

print(flag)

Solution (Python):
import sys
sys.setrecursionlimit(3000)
H, W = map(int, input().split())
s = ['.'*(W+2)] + [list('.'+input()+'.') for _ in range(H)] + ['.'*(W+2)]

def dfs(x, y):
  if s[y][x] == '.':
    return 0
  s[y][x] = '.'
  return 1+dfs(x+1,y)+dfs(x-1,y)+dfs(x,y+1)+dfs(x,y-1)

for y in range(1, H+1):
  for x in range(1, W+1):
    if dfs(x, y) == 1:
      print('No')
      exit()
print('Yes')

Solution (Python):
H, W = map(int, input().split(' '))
cells = [[False if tgt == '.' else True for tgt in list(input())] for i in range(H)]

paintable = True

for line in cells:
    line.append(False)
    line.insert(0, False)
cells.insert(0, [False for i in range(W + 2)])
cells.append([False for i in range(W + 2)])

for i in range(1, H + 1):
    for j in range(1, W + 1):
        if (cells[i][j] == True):
            if cells[i - 1][j] == False and cells[i][j - 1] == False and cells[i + 1][j] == False and cells[i][j + 1] == False:
                paintable = False
                break
    if not paintable:
        break

print ('Yes' if paintable else 'No')

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

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

Solution (Python):
h,w = map(int, raw_input().split())
c = [ raw_input() for i in range(h) ]
ans = True
for i in range(h):
    for j in range(w):
        if c[i][j] == '
            ans = False
            if (i > 0) and (c[i-1][j] == '
                ans = True
            if (j > 0) and (c[i][j-1] == '
                ans = True
            if (i < h-1) and (c[i+1][j] == '
                ans = True
            if (j < w-1) and (c[i][j+1] == '
                ans = True
        if not(ans):
            break
    if not(ans):
        break
if ans:
    print "Yes"
else:
    print "No"

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

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

flag = True

for x in range(1,h + 1):
  for y in range(1,w + 1):
    if lst[x][y] == "
      if lst[x - 1][y] == "." and lst[x + 1][y] == "." and lst[x][y + 1] == "." and lst[x][y - 1] == ".":
        flag = False
        break

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

Solution (Python):


n, m = map(int, input().split())

s = [ list(str(input())) for _ in range(n) ]
add = [[1, 0],[-1, 0],[0, 1],[0, -1]]
ans = 'Yes'
for i in range(n):
    for j in range(m):
        if s[i][j] == '.': continue
        mid = False
        for k in range(4):
            ii = i + add[k][0]
            jj = j + add[k][1]
            if ii >= 0 and jj < m and ii < n and jj >= 0:
                if s[ii][jj] == '
        if not mid: ans = 'No';break
print(ans)

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

for i in range(1,h):
    for j in range(1,w):
        base = arr[i][j]
        up = arr[i-1][j]
        down = arr[i + 1][j]
        right = arr[i][j + 1]
        left = arr[i][j - 1]
        if base == '
            flg = False
            print('No')
            break
    if not flg:
        break
if flg:
    print('Yes')

Solution (Python):
H,W = map(int,input().split())
ss=[]
for s in range(H):
    ss.append(input().strip())
flg=True
for i in range(H):
    for j in range(W):
        if ss[i][j]== "
            if not (j>0 and ss[i][j-1] == "
                flg=False
                break
    if not flg:
        break
print("No Yes".split()[int(flg)])

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

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

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

mx = [0, 1, 0, -1]
my = [1, 0, -1, 0]
for i in range(h):
  for  j in range(w):
    if table[i][j] == "
      for k in range(4):
        tx, ty = j + mx[k], i + my[k]
        if 0 <= tx < w and 0 <= ty < h and table[ty][tx] == "
          break
      else:
        print("No")
        exit(0)
print("Yes")

Solution (Python):
H, W = map(int, input().split())
S = [input() for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            continue
        k = 0
        for x, y in [(i-1, j), (i+1, j), (i, j-1), (i, j+1)]:
            if x < 0 or x >= H:
                continue
            if y < 0 or y >= W:
                continue
            if S[x][y] == "
                k += 1
        if k == 0:
            print("No")
            exit()
print("Yes")

Solution (Python):



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

cnt = 0
for i in range(0, H):
    for j in range(0, W):
        if i == 0 and j == 0 or i == 0 and j == W-1 or \
            i == H-1 and j == 0 or i == H-1 and j == W-1:
            continue
        if S[i][j] == "
            if i == 0:
                if S[i][j+1] != "
                    cnt += 1
            elif i == H-1:
                if S[i][j+1] != "
                    cnt += 1
            elif j == 0:
                if S[i][j+1] != "
                    cnt += 1
            elif j == W-1:
                if S[i][j-1] != "
                    cnt += 1
            else:
                if S[i][j+1] != "
                    and S[i+1][j] != "
                    cnt += 1
if cnt == 0:
    print("Yes")
else:
    print("No")

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

cnt = 0

if H >= 2 and W >= 3:
	if s[0][0] == "
		cnt += 1

	for w in range(1, W - 1):
		if s[0][w] == "
			cnt += 1

	if s[0][W - 1] == "
		cnt += 1 

	if H >= 3:
		for h in range(1, H - 1):
			if s[h][0] == "
				cnt += 1

			for w in range(1, W - 1):
				if s[h][w] == "
					cnt += 1

			if s[h][W - 1] == "
				cnt += 1 

	if s[H - 1][0] == "
		cnt += 1

	for w in range(1, W - 1):
		if s[H - 1][w] == "
			cnt += 1

	if s[H - 1][W - 1] == "
		cnt += 1

elif H == 1:
	if s[0][0] == "
		cnt += 1

	for w in range(1, W - 1):
		if s[0][w] == "
			cnt += 1

	if s[0][W - 1] == "
		cnt += 1

elif W == 1:
	if s[0][0] == "
		cnt += 1

	for h in range(1, H - 1):
		if s[h][0] == "
			cnt += 1

	if s[H - 1][0] == "
		cnt += 1

else: 
	if s[0][0] == "
		cnt += 1

	if s[0][1] == "
		cnt += 1

	if H >= 3:
		for h in range(1, H - 1):
			if s[h][0] == "
				cnt += 1

			if s[h][1] == "
				cnt += 1 

	if s[1][0] == "
		cnt += 1

	if s[1][1] == "
		cnt += 1


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

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

Solution (Python):
h, w = map(int, input().split())
s = [['.' for i in range(w+2)]]
for i in range(h):
    s.append(list('.' + input() + '.'))
s.append(['.' for i in range(w+2)])
ans = 'Yes'
for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j] == '
            if s[i-1][j] != '
                ans = 'No'
                break
    else:
        continue
    break

print(ans)

Solution (Python):
h, w = map(int, input().split())
board = ['
for i in range(h):
    board.append('
board.append('
flag = True
dy = [-1, 0, 0, 1]
dx = [0, -1, 1, 0]
for i in range(1, h):
    for j in range(1, w):
        if board[i][j] == '
            ok = False
            for k in range(4):
                if board[i+dy[k]][j+dx[k]] == '
                    ok = True
            if ok == False:flag = False
if flag == False:print("No")
else:print("Yes")

Solution (Python):
import numpy as np
h, w = map(int, input().split())
s = np.array([list(input()) for _ in range(h)])
w1, w2 = np.array(["."]*h), np.array(["."]*(w+2))
s = np.hstack((w1.reshape(len(w1),1), s))
s = np.hstack((s, w1.reshape(len(w1),1)))
s = np.vstack((w2, s))
s = np.vstack((s, w2))
dx, dy = [1, 0, -1, 0], [0, 1, 0, -1]
for i in range(1, h+1, 1):
    for j in range(1, w+1, 1):
        now = s[i][j]
        c = 0
        if now == ".":
            continue
        for d in range(4):
            x = j + dx[d]
            y = i + dy[d]
            if now == s[y][x]:
                c += 1
        if c == 0:
            print("No")
            exit()
print("Yes")

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

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

print(judge)

Solution (Python):
import sys

def get_value_by_lists(values_list, pos):
    h, w = len(values_list), len(values_list[0])
    if 0 <= pos[1] < h and 0 <= pos[0] < w:
        return values_list[pos[1]][pos[0]]
    else:
        return None

def is_black_in_four_dir(cells_list, pos):
    for p in ((0, 1), (0, -1), (1, 0), (-1, 0)):
        if get_value_by_lists(cells_list, (pos[0]+p[0], pos[1]+p[1])) == "
            return True
    return False

h, w = map(lambda x: int(x), input().split(" "))
cells_list = [input() for _ in range(h)]

for y, cells in enumerate(cells_list):
    for x, cell in enumerate(cells):
        if cell == "
            print("No")
            sys.exit()
print("Yes")

Solution (Python):
import sys
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
t=[[(0 if i == 0 or j == 0 or i == (h+1) or j == (w+1) or s[i-1][j-1]=='.' else 1) for j in range(w+2)] for i in range(h+2)]
for i in range(1,h+1):
	for j in range(1,w+1):
		if t[i][j] == 0:
			continue
		if t[i-1][j] == 0 and t[i][j-1] == 0 and t[i][j+1] == 0 and t[i+1][j] == 0:
			print("No")
			sys.exit()
print("Yes")

Solution (Python):




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


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


ans = True  

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

for i in range(H):
    for j in range(W):
        if paint_map[i][j] == "
            found = False  

            for k in range(4):
                ii = i + dx[k]
                jj = j + dy[k]

                if (H > ii >= 0) & (W > jj >= 0):  
                    if paint_map[ii][jj] == "
                        found = True

            if not found:  
                ans = False

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

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

S = [list(map(lambda x: x == "

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

ans = True
for j in range(H):
    for i in range(W):
        if S[j][i]:
            ok = False
            for x, y in zip(dx, dy):
                if i+x < 0 or i+x >= W or j+y < 0 or j+y >= H:
                    continue
                ok = ok or S[j+y][i+x]
            if not ok:
                ans = False
                break
        if not ans:
            break
    if not ans:
        break
print("Yes" if ans else "No")

Solution (Python):
H, W = map(int, input().split())
S = [list(input()) for i in range(H)]
 
 
def enclose_field(field, outline="
    """
    迷路等の外周をoutlineで埋めることで、IndexErrorを回避できます。
    [0, 0] → [1, 1]、[H-1, W-1] → [H, W]となります。
    """
    for i in range(len(field)):
        field[i] = [outline] + field[i] + [outline]
    field.append([outline] * (len(field[0])))
    field.insert(0, [outline] * (len(field[0])))
    return field
 
 
S = enclose_field(S, outline="a")
 
for i in range(H):
    for j in range(W):
        if S[i][j] == "
            adj = [S[i+1][j], S[i-1][j], S[i][j+1], S[i][j-1]]
            if "
                print("No")
                exit()
else:
    print("Yes")

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

for i in range(h):
    for j in range(w):
        if picture[i][j] == "
            if i == 0:
                if j == 0:
                    if picture[i+1][j] != "
                        flag = False
                        break
                elif j == w-1:
                    if picture[i+1][j] != "
                        flag = False
                        break
                else:
                    if picture[i+1][j] != "
                        flag = False
                        break
            elif i == h-1:
                if j == 0:
                    if picture[i-1][j] != "
                        flag = False
                        break
                elif j == w-1:
                    if picture[i-1][j] != "
                        flag = False
                        break
                else:
                    if picture[i-1][j] != "
                        flag = False
                        break
            else:
                if j == 0:
                    if picture[i+1][j] != "
                        flag = False
                        break
                elif j == w-1:
                    if picture[i+1][j] != "
                        flag = False
                        break
                else:
                    if picture[i+1][j] != "
                        flag = False
                        break

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

Solution (Python):
def readQuestion():
    import sys
    h, w = map(int, sys.stdin.readline().split(' '))
    p = [[] for i in range(h)]
    for (i, line) in enumerate(sys.stdin):
        p[i] = list(map(lambda x:line[x] == '
    return h, w, p

def mkNbr(s):
    nb = [[i-1,i+1] for i in range(s)]
    nb[0] = [1] if s > 1 else []
    nb[s-1] = [s-2] if s > 1 else []
    return nb

def solve(h, w, p):
    def hasNbr(i, j):
        return any((p[y][j] for y in nbH[i])) or \
               any((p[i][x] for x in nbW[j]))

    nbH = mkNbr(h)
    nbW = mkNbr(w)
    return 'Yes' if all((not p[i][j] or hasNbr(i,j)
                         for i in range(h) for j in range(w))) \
                 else 'No'

def main():
    h, w, p = readQuestion()
    print(solve(h, w, p))

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    """
    1<=H,W<=50

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

    s = [
        input()
        for _ in range(H)
    ]

    f(H, W, s)


def f(H, W, s):
    d = list(zip(
        (0, 0, 1, -1),
        (1, -1, 0, 0)
    ))
    for h in range(H):
        for w in range(W):
            if s[h][w] == ".":
                continue

            ok = False
            for dy, dx in d:
                ny, nx = h+dy, w+dx
                if 0 <= ny < H and 0 <= nx < W and s[ny][nx] == "
                    ok = True
            if not ok:
                print("No")
                return

    print("Yes")


if __name__ == '__main__':
    main()

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

for i in range(h):
    s.append(input())

aaaaa=0
for i in range(h):
  for j in range(w):
     count=0

     if s[i][j]=="
        try:
            if s[i][j+1]=="
                count=1
        except: pass

        try:
            if s[i+1][j]=="
                count=1
        except: pass

        try:
            if s[i-1][j]=="
                count=1
        except: pass

        try:
            if s[i][j-1]=="
                count=1
        except: pass

        if count==0: aaaaa=1

if aaaaa==1:
    print("No")
else:
    print("Yes")

Solution (Python):

import sys

h,w=map(int,raw_input().split())
s=['.'*(w+2)]
for i in xrange(h):
 t='.'
 t+=raw_input()
 t+='.'
 s.append(t)
s.append('.'*(w+2))
for i in xrange(1,h+1):
 for j in xrange(1,w+1):
  if s[i][j]=='
   if s[i-1][j]=='
    continue
   else:
    print 'No'
    sys.exit()
print 'Yes'

Solution (Python):
def ok(h, w, grid):
    for r in range(h):
        for c in range(w):
            if grid[r][c] == '
                cnt = 0
                for dr, dc in [(1,0),(0,1),(-1,0),(0,-1)]:
                    nr, nc = r+dr, c+dc
                    if (0 <= nr < h) and (0 <= nc < w) and (grid[nr][nc] == '
                        cnt += 1
                if cnt == 0:
                    return False
    return True
h, w = map(int, raw_input().split())
grid = [raw_input() for r in range(h)]
print "Yes" if ok(h, w, grid) else "No"

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] == '
            temp = 0
            if j-1>=0 and s[i][j-1] == '
                temp =1        
            if i+1<w and s[i+1][j] == '
                temp = 1
            if j+1<h and s[i][j+1] == '
                temp = 1
            if i-1 >=0 and s[i-1][j] == '
                temp = 1  
            if temp == 0:
                print("No")
                exit()        

print("Yes")

Solution (Python):
H, W = map(int, input().split())
S = [input() for i in range(H)]
dd = [(0, -1), (-1, 0), (0, 1), (1, 0)]
for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            continue
        for dx, dy in dd:
            nx = j + dx; ny = i + dy
            if 0 <= nx < W and 0 <= ny < H:
                if S[ny][nx] == '
                    break
        else:
            print("No")
            exit()
print("Yes")

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

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

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

for i in range(H):
    s[i].append(".")
    s[i].insert(0,".")

add_list = ["." for _ in range(W+2)]
s.append(add_list)
s.insert(0,add_list)

Flag = "Yes"

for i in range(H):
    for j in range(W):
        if (s[i][j]=="
            Flag = "No"
            break
print(Flag)

Solution (Python):
h, w = map(int, input().split())
grid = []
ans = "Yes"
for i in range(h):
    grid.append(list(input()))
command = [(-1, 0), (1, 0), (0, -1), (0, 1)]

for x in range(h):
    for y in range(w):
        if grid[x][y] == "
            flag = "No"
            for m, n in command:
                try:
                    if grid[x + m][y + n] == "
                        flag = "Yes"
                except:
                    None
            if flag == "No":
                ans = flag
print(ans)

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

Solution (Python):
h,w=map(int,input().split())
t=[list(input())for i in range(h)]
ans=True
dx=[1,-1,0,0]
dy=[0,0,1,-1]
for i in range(h):
    for j in range(w):
        if t[i][j]=="
            found=False
            for k in range(4):
                i2=i+dx[k]
                j2=j+dy[k]
                if 0<=i2 and i2<h and 0<=j2 and j2<w and t[i2][j2]=="
                    found=True
            if found==False:
                ans=False
if ans:
    print("Yes")
else:
    print("No")

Solution (Python):
H, W = map(int, input().split())
s = []
for i in range(H):
    s.append(input())
for y in range(H-1):
    for x in range(W):
        if(s[y][x] == "
            if(s[y-1][x] == "
                pass
            else:
                print("No")
                exit()
print("Yes")

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

    
for i in range(0,H):
    for j in range(0,W):
        if S[i][j] == "
            if i != 0 and S[i-1][j] == "
            elif i != H-1 and S[i+1][j] == "
            elif j != 0 and S[i][j-1] == "
            elif j != W-1 and S[i][j+1] == "
            else: flag = "No"
            
print(flag)