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_list = list()
for _ in range(H):
    s_list.append(list(input()))

res = "Yes"

for i in range(H):
    for j in range(W):
        
        if s_list[i][j] == "
            res_temp = "No"
        else:
            res_temp = "Yes"
        
        if i > 0:
            if s_list[i-1][j] == "
                res_temp = "Yes"
        
        if i+1 < H:
            if s_list[i+1][j] == "
                res_temp = "Yes"      
        
        if j > 0:
            if s_list[i][j-1] == "
                res_temp = "Yes"
        
        if j+1 < W:
            if s_list[i][j+1] == "
                res_temp = "Yes"   
        
        if res_temp == "No":
            res = "No"
print(res)

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

for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            continue
        flag=False
        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
        break
    else:
        continue
    break
else:
    print('Yes')
    quit()
print('No')

Solution (Python):
def solve(field):
    for i in range(1, h + 1):
        for j in range(1, w + 1):
            if field[i][j] == '.':
                continue
            if field[i - 1][j] == field[i + 1][j] == field[i][j - 1] == field[i][j + 1] == '.':
                return False
    return True


h, w = list(map(int, input().split()))
field = ['.' + input() + '.' for _ in range(h)]
field = ['.' * (w + 2)] + field + ['.' * (w + 2)]
print('Yes' if solve(field) else 'No')

Solution (Python):
import sys
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 not ((s[i-1][j]=="
                print("No")
                sys.exit(0)
print("Yes")

Solution (Python):




h,w = map(int,input().split())
m = []
m.append('.'*(w+2))
for i in range(h):
    m.append('.'+input()+'.')
m.append('.'*(w+2))
for i in range(1,h+1):
    for j in range(1,w+1):
        if m[i][j]=='.':
            continue
        if (m[i][j]=='
            pass
        else:
            print("No")
            exit(0)
print("Yes")

Solution (Python):
h, w=map(int, input().split())
s=[input() for i in range(h)]
ans=0
for i in range(h):
    for j in range(w):
        if s[i][j]=='
            t=0
            try:
                if s[i+1][j]=='
                    t=1
            except:
                pass
            try:
                if s[i-1][j]=='
                    t=1
            except:
                pass
            try:
                if s[i][j+1]=='
                    t=1
            except:
                pass
            try:
                if s[i][j-1]=='
                    t=1
            except:
                pass
            if t==0:
                ans+=1
print('Yes') if ans==0 else print('No')

Solution (Python):
H,W = map(int,input().split())
S = []
for i in range(H):
    S.append(input())
Ans = "Yes"
for i in range(H):
    for j in range(W):
        check = ""
        if j-1 >= 0:
            check += S[i][j-1]
        if j+1 <= W-1:
            check += S[i][j+1]
        if i-1 >= 0:
            check += S[i-1][j]
        if i+1 <= H-1:
            check += S[i+1][j]
        if S[i][j]=="
            Ans = "No"
print(Ans)

Solution (Python):
h, w = map(int, input().split())
wall = []
for i in range(h):
    wall.append(list(input()))
for i in range(h):
    for j in range(w):
        if wall[i][j] == "
            try:
                if wall[i+1][j]=="
                    continue
            except:
                pass
            try:
                if wall[i][j+1]=="
                    continue
            except:
                pass
            try:
                if wall[i-1][j]=="
                    continue
            except:
                pass
            try:
                if wall[i][j-1]=="
                    continue
            except:
                pass
            print("No")
            exit()
print("Yes")

Solution (Python):
H,W = map(int,input().split())
g = [input() for i in range(H)]
dr = [-1, 1, 0, 0]
dc = [0, 0, -1, 1]
for i in range(H):
    for j in range(W):
        if g[i][j] == '
            ok = False
            for k in range(4):
                x = i + dr[k]
                y = j + dc[k]
                if 0 <= x < H and 0 <= y < W:
                    ok = ok or g[x][y] == '
            if not ok:
                print('No')
                exit(0);
print('Yes')

Solution (Python):
h, w = map(int, input().split())
s = [input() for _ in range(h)]
s = ['.'*(w+2)] + ['.'+l+'.' for l in s] + ['.'*(w+2)]
d = [0,1,0,-1,0]
check = True
for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j] == '
            f = False
            for k in range(4):
                di = i+d[k+1]
                dj = j+d[k]
                if s[di][dj] == '
                    f = True
                    break
            if not f:
                check = False
                break
    if not check:
        break
print('Yes' if check else 'No')

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

dxy = [(-1,0),(0,-1),(1,0),(0,1)]
for y in range(H):
    for x in range(W):
        if src[y][x] == '.': continue
        for dx,dy in dxy:
            nx,ny = x+dx,y+dy
            if not 0 <= nx < W: continue
            if not 0 <= ny < H: continue
            if src[ny][nx] == '
                break
        else:
            print('No')
            exit()
print('Yes')

Solution (Python):

h,w=map(int,input().split())
t=[]
for i in range(h):
    t.append(list(input()))
for i in range(h):
    for j in range(w):
        if t[i][j]=='
            tmp=0
            if i+1<h and t[i+1][j]=='
                tmp+=1
            if i-1>=0 and t[i-1][j]=='
                tmp+=1
            if j+1<w and t[i][j+1]=='
                tmp+=1
            if j-1>=0 and t[i][j-1]=='
                tmp+=1
            if tmp==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(0)
print("Yes")

Solution (Python):
import sys

stdin = sys.stdin

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

n, m = na()

b = []
for i in range(n):
    b.append(ns())

for i in range(n):
    for j in range(m):
        if b[i][j] == "
            yes = 0
            if j-1 >= 0 and b[i][j-1] == "
                yes = 1
            if i-1 >= 0 and b[i-1][j] == "
                yes = 1
            if j+1 < m and b[i][j+1] == "
                yes = 1
            if i+1 < n and b[i+1][j] == "
                yes = 1
            if yes == 0:
                print("No")
                sys.exit(0)
print("Yes")