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):
def main():
    H, W = list(map(int, input().split(' ')))
    S = [input() for _ in range(H)]
    for h in range(H):
        for w in range(W):
            if S[h][w] == '.':
                continue
            
            if h - 1 >= 0 and S[h - 1][w] == '
                continue
            if h + 1 <= H - 1 and S[h + 1][w] == '
                continue
            if w - 1 >= 0 and S[h][w - 1] == '
                continue
            if w + 1 <= W - 1 and S[h][w + 1] == '
                continue
            
            print('No')
            return
    print('Yes')


if __name__ == '__main__':
    main()

Solution (Python):


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

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

for y, r in enumerate(s):
    for x, c in enumerate(r):
        if c == '
            check_str = ''
            
            if x > 0:
                check_str+=r[x-1]
            if x < len(r) - 1:
                check_str+=r[x+1]
            if y > 0:
                check_str+=s[y-1][x]
            if y < len(s) - 1:
                check_str+=s[y+1][x]
            
            if not '
                print('No')
                exit()

print('Yes')

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

la = ["."] * (w+2)
lz = ["."] * (w+2)

l = list()
l.append(la)

for i in range(h):
    l.append(["."] + list(input()) + ["."])

l.append(lz)

for i in range(1, h+1):
    for j in range(1, w+1):
        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")
                exit()

print("Yes")

Solution (Python):
h, w = map(int, input().split(" "))
s = []
for row in range(h):
    line = input()
    tmp = []
    for column in range(w):
        tmp.append(line[column])
    s.append(tmp)

sx = [-1, 0, 0, 1]
sy = [0, 1, -1, 0]

res = True
for row in range(h):
    for column in range(w):
        if s[row][column] == "
            count = 0
            for i in range(len(sx)):
                row_target = row + sx[i]
                column_target = column + sy[i]
                if row_target < 0 or len(s) <= row_target:
                    continue
                if column_target < 0 or len(s[row]) <= column_target:
                    continue
                if s[row_target][column_target] == "
                    count += 1
            if count == 0:
                res = False

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

Solution (Python):
h, w = map(int, input().split(" "))
s = []
for row in range(h):
    line = input()
    tmp = []
    for column in range(w):
        tmp.append(line[column])
    s.append(tmp)

sx = [-1, 0, 0, 1]
sy = [0, 1, -1, 0]

res = True
for row in range(h):
    for column in range(w):
        if s[row][column] == "
            count = 0
            for i in range(len(sx)):
                if row + sx[i] < 0 or len(s) <= row + sx[i]:
                    continue
                if column + sy[i] < 0 or len(s[row]) <= column + sy[i]:
                    continue
                if s[row + sx[i]][column + sy[i]] == "
                    count += 1
            if count == 0:
                res = False

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

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

ans_list = []
for h in range(1, H+1):
    for w in range(1, W+1):
        if s_list[h][w]=='
            if s_list[h-1][w]=='
                ans = True
            elif s_list[h+1][w]=='
                ans = True
            elif s_list[h][w-1]=='
                ans = True
            elif s_list[h][w+1]=='
                ans = True
            else:
                ans = False
            ans_list.append(ans)

if len(ans_list)==sum(ans_list):
    print("Yes")
else:
    print("No")

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

campus = []

campus.append("."*(W+2))
for _ in range(H):
    s = list("."+input()+".")
    campus.append(s)
campus.append("."*(W+2))



flag = True
for i in range(1, H+1):
    for j in range(1, W+1):
        if campus[i][j] == "
            if campus[i-1][j] != "
                flag = False

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

Solution (Python):
h,w = map(int,input().split())
s_list = [list(input()) for nesya in range(h)]
for s in s_list:
  s.insert(0,'.')
  s.append('.')
a = ['.']*(w+2)
s_list.insert(0,a)
s_list.append(a)
c = 0
for i in range(1,w+1):
  for j in range(1,h+1):
    if c == 1:
      break
    if s_list[j][i] == '
      if s_list[j-1][i] == s_list[j+1][i] == s_list[j][i-1] == s_list[j][i+1] == '.':
        c += 1
        print('No')
        break
if c == 0:
  print('Yes')

Solution (Python):
from itertools import product
H, W = list(map(int, input().split()))
board = [['.'] * W] + [list(input()) for _ in range(H)] + [['.'] * W]
board = [['.'] + b + ['.'] for b in board]
dhw = [[1, 0], [-1, 0], [0, 1], [0, -1]]
for h, w in product(range(1, H + 1), range(1, W + 1)):
    if board[h][w] == '
        can = False
        for dh, dw in dhw:
            if board[h + dh][w + dw] == '
                can = True
                break
        if not can:
            print('No')
            exit()
print('Yes')

Solution (Python):
import sys
H, W = map(int, input().split())
s = [input() for i in range(H)]
S = []
S.append('.' * (W + 2))
for i in range(H):
    S.append('.' + s[i] + '.')
S.append('.' * (W + 2))
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if S[i][j] == '
            if S[i + 1][j] == '
                continue
            else:
                print('No')
                sys.exit()
print('Yes')

Solution (Python):

import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left 
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pri = lambda x: print(*x, sep='\n')

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

def check(ny, nx):
    if 0<=ny<H and 0<=nx<W and S[ny][nx]=='
        return True
    else:
        return False

ddy = [-1, 0, 1, 0]
ddx = [0, -1, 0, 1]

def dfs(y, x, S):
    deq = deque()
    deq.append([(y, x)]) 
    S[y][x] = '.'
    found = False
    while deq[0]:
        nqueue = []
        cqueue = deq.pop()
        for val in cqueue:
            y, x = val
            for dy, dx in zip(ddy, ddx):
                ny, nx = y+dy, x+dx
                if check(ny, nx):
                    found = True
                    S[ny][nx] = '.'
                    nqueue.append((ny, nx))
        if found == False:
            print('No')
            exit()
        deq.append(nqueue)

for y in range(H):
    for x in range(W):
        if S[y][x] == '
            dfs(y, x, S)
else:
    print('Yes')

Solution (Python):
H,W = list(map(int,input().split()))
S = [list(input()) for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == '
            if not (i == 0 or S[i-1][j] == '.'):
                continue
            if not (i == H-1 or S[i+1][j] == '.'):
                continue
            if not (j == 0 or S[i][j-1] == '.'):
                continue
            if not (j == W-1 or S[i][j+1] == '.'):
                continue
            print('No')
            exit()
print('Yes')

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



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

if flg==0:
    print("Yes")

Solution (Python):
import sys

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


li = []
for i in range(H+2):
    li.append(["."]*(W+2))


for i in range(1, H+1):
    li[i][1:-1] = S[i-1]


for h in range(1, H+1):
    for w in range(1, W+1):
        tmp = 0
        if li[h][w]=='
            if li[h - 1][w]=="
                tmp += 1
            if li[h + 1][w]=="
                tmp += 1
            if li[h][w - 1]=="
                tmp += 1
            if li[h][w + 1]=="
                tmp += 1
            if tmp==0:
                print("No")
                sys.exit()

print("Yes")

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



data = [ [0 for _ in range(w)] for _ in range(h) ]
data2 = [ [0 for _ in range(w+2)] for _ in range(h+2) ]

for i in range(h):
  for j in range(w):
    if s[i][j] == '
      data[i][j] = 1

for i in range(h+2):
  if i == 0 or i == h+1:
    continue 
  for j in range(w+2):
    if j == 0 or j == w+1:
      continue
    data2[i][j] = data[i-1][j-1]

ck = 1
for i in range(1,h+1):
  for j in range(1,w+1):
    if data2[i][j] :
      if not (data2[i-1][j] or data2[i][j+1] or data2[i+1][j] or data2[i][j-1]) :
        ck = 0
        break
  if not ck :
    break

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

Solution (Python):
dy = [1, -1, 0, 0]
dx = [0, 0, 1, -1]

def resolve():
	h, w = map(int, input().split())
	pic = []
	for i in range(h):
		r = list(input())
		pic.append(r)
	for i in range(h):
		for j in range(w):
			if pic[i][j] == '
				ok = False
				for k in range(4):
					ny = i + dy[k]
					nx = j + dx[k]
					if ny >= h or nx >= w:
						continue
					if pic[ny][nx] == '
						ok = True
				if not ok:
					print('No')
					return
	print('Yes')
resolve()

Solution (Python):
h, w = map(int, input().split())
s = [input() for _ in range(h)]
dx = [-1, 0, 0, 1]
dy = [0, -1, 1, 0]
for i in range(h):
    for j in range(w):
        if s[i][j] == '
            flag = 0
            for k in range(4):
                ny = i + dy[k]
                nx = j + dx[k]
                if nx < 0 or w <= nx:
                    continue
                if ny < 0 or h <= ny:
                    continue
                if s[ny][nx] == '
                    flag = 1
            if flag == 0:
                print('No')
                exit()
else:
    print('Yes')

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

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

s = []
check = 0

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

for i in range(h):
    for j in range(w):
        up = 0
        left = 0
        right = 0
        down = 0

        if s[i][j] == ".":
            pass
        else:
            if i == 0:
                up = 0
                if s[i+1][j] == "
                    down = 1
            elif i == h-1:
                down == 0
                if s[i-1][j] == "
                    up = 1
            else:
                if s[i-1][j] == "
                    up = 1
                if s[i+1][j] == "
                    down = 1
            if j == 0:
                left = 0
                if s[i][j+1] == "
                    right = 1
            elif j == w-1:
                right = 0
                if s[i][j-1] == "
                    left = 1
            else:
                if s[i][j-1] == "
                    left = 1
                if s[i][j+1] == "
                    right = 1

            if up+left+right+down == 0:
                check = 1

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

Solution (Python):
from collections import defaultdict

H, W = map(int, input().split())
pict = defaultdict(lambda: "
for i in range(H):
    S = input()
    for j in range(len(S)):
        pict[i, j] = S[j]

ans = "Yes"
for i, j in pict.keys():
    if pict[i, j] == "
        (i - 1 >= 0 and pict[i - 1, j] != "
        and (j - 1 >= 0 and pict[i, j - 1] != "
        and (i + 1 < H and pict[i + 1, j] != "
        and (j + 1 < W and pict[i, j + 1] != "
    ):
        ans = "No"
        break

print(ans)

Solution (Python):
h, w = map(int, input().split())
s = [input().strip() for _ in range(h)]
for i in range(h):
    for j in range(w):
        flg = False
        if s[i][j] == '
            if 0 < i and s[i - 1][j] == '
                flg = True
            if i < (h - 1) and s[i + 1][j] == '
                flg = True
            if 0 < j and s[i][j - 1] == '
                flg = True
            if j < (w - 1) and s[i][j + 1] == '
                flg = True
            if not flg:
                print('No')
                exit()
print('Yes')

Solution (Python):

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

def grid_search(x,y,grid):
    now = grid[x][y]
    flg = True
    
    if now == '
        flg = False
        
        if x+1<=h-1 and grid[x+1][y] == '
            flg = True
        elif x-1 >= 0 and grid[x-1][y] == '
            flg = True
        elif y+1 <= w-1 and grid[x][y+1] == '
            flg = True
        elif y-1 >= 0 and grid[x][y-1] == '
            flg = True
        else:
            flg = False
            
        if not flg:
            return False
        
    return True
flg = True    
for i in range(h):
    for j in range(w):
        if not grid_search(i,j,grid) and flg:
            print('No')
            flg = False
            break
if flg:
    print('Yes')

Solution (Python):
import itertools,sys
def S(): return sys.stdin.readline().rstrip()
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
H,W = LI()
s = [S() for _ in range(H)]
ans = 1
for i,j in itertools.product(range(H),range(W)):
    if s[i][j]=='.':
        continue
    if i-1>=0 and s[i-1][j]=='
        continue
    if j-1>=0 and s[i][j-1]=='
        continue
    ans = 0
    break
print({1:'Yes',0:'No'}[ans])

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

canvas = [' ' + input() + ' ' for _ in range(H)]
canvas.insert(0, ' ' * (W + 2))
canvas.append(' ' * (W + 2))

for y in range(1, H + 1):
    for x in range(1, W + 1):
        if canvas[y][x] == '
            if '
                print('No')
                break
    else:
        continue
    break
else:
    print('Yes')

Solution (Python):
import itertools,sys
def S(): return sys.stdin.readline().rstrip()
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
H,W = LI()
s = [S() for _ in range(H)]
ans = 1
for i,j in itertools.product(range(H),range(W)):
    if s[i][j]=='.':
        continue
    try:
        if s[i-1][j]=='
            continue
    except:
        continue
    else:
        ans = 0
        break
print({1:'Yes',0:'No'}[ans])

Solution (Python):
import itertools,sys
def S(): return sys.stdin.readline().rstrip()
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
H,W = LI()
s = [S() for _ in range(H)]
ans = 1
for i,j in itertools.product(range(H),range(W)):
    if s[i][j]=='.':
        continue
    uh,uw,dh,dw = i-1,j,i+1,j
    lh,lw,rh,rw = i,j-1,i,j+1
    if not (0<=uh<=H-1) or not (0<=dh<=H-1) or not (0<=lh<=H-1) or not (0<=rh<=H-1):
        continue
    if not (0<=uw<=W-1) or not (0<=dw<=W-1) or not (0<=lw<=W-1) or not (0<=rw<=W-1):
        continue
    if s[uh][uw]=='
        continue
    else:
        ans = 0
        break
print({1:'Yes',0:'No'}[ans])

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]





H, W = mi()
S = [input() for _ in range(H)]

dij = [[0, 1], [1, 0], [0, -1], [-1, 0]]
for i in range(H):
    for j in range(W):
        if S[i][j] == '
            for dj, di in dij:
                if -1 < i + di < H and -1 < j + dj < W:
                    if S[i + di][j + dj] == '
                        break
            else:
                print('No')
                exit()
print('Yes')

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]





H, W = mi()
S = [input() for _ in range(H)]

dij = [[0, 1], [1, 0], [0, -1], [-1, 0]]
for i in range(H):
    for j in range(W):
        if S[i][j] == '
            flag = 0
            for dj, di in dij:
                if -1 < i + di < H and -1 < j + dj < W:
                    if S[i + di][j + dj] == '
                        flag = 1
                        break
            if not flag:
                print('No')
                exit()
print('Yes')

Solution (Python):
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
h, w = map(int, input().split())
tmp = [None]*h
for i in range(h):
    tmp[i] = input()

for i in range(h):
    for j in range(w):
        if tmp[i][j] == '
            if (i != 0 and tmp[i-1][j] == '
                continue
            print('No')
            exit()
print('Yes')

Solution (Python):
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor



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















H, W = map(int, input().split())
s = [None]*H
for i in range(H):
    s[i] = input()
    
for i in range(H):
    for j in range(W):
        if s[i][j] == '
            
            if (i != 0 and s[i-1][j] == '
                continue
            else:
                print('No')
                exit()
print('Yes')

Solution (Python):
dxdy = ((0,1),(0,-1),(1,0),(-1,0))

H, W = map(int,input().split())
S = []

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



for h in range(1,H+1):
    for w in range(1,W+1):
        if S[h][w] == '.':
            continue
        ok = False
        for dx,dy in dxdy:
            if S[h+dx][w+dy] == '
                ok = True
                break
        if ok == False:
            print ('No')
            exit()
print ('Yes')

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

for _ in range(h):
    ma.append(list(str(input())))

add = ['.'] * w

ma.insert(0, add)
ma.insert(h+1, add)


for ad in range(h+1):
    ma[ad].insert(0, '.')
    ma[ad].insert(w+1, '.')

for high in range(1, h):
    for wid in range(1, w) :
        j_1 = False
        j_2 = False
        if ma[high][wid] == '
            j_1 = True

        if j_1 == True :
            if ma[high][wid-1] == '
                j_2=True
            if j_2 == False :
                print('No')
                exit()

print('Yes')

Solution (Python):

import re
import math
from collections import defaultdict
from collections import deque
import itertools
from copy import deepcopy
import random
import time
import os
import queue
import sys
import datetime
from functools import lru_cache

readline=sys.stdin.readline
sys.setrecursionlimit(2000000)

alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_pow(a,b):
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def get_primes(n,type="int"):
    if n==0:
        if type=="int":return []
        else:return [False]
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=""):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
    return ret
def seifu(x):
    return x//abs(x)

def main():
    H,W=map(int,input().split())
    S=[input() for a in range(H)]
    ans="Yes"
    for a in range(H):
        for b in range(W):
            if S[a][b]=="
                dx=[-1,1,0,0]
                dy=[0,0,-1,1]
                for c in range(4):
                    x=b+dx[c]
                    y=a+dy[c]
                    if x<0 or W<=x or y<0 or H<=y: continue
                    if S[y][x]=="
                else:
                    ans="No"
    print(ans)
main()

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

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

for i in range(h):
    for j in range(w):
        if s[i][j]!="
            continue

        count=0
        for k in range(4):
            di=i+dy[k]
            dj=j+dx[k]

            if (di<0)|(di>h-1):
                continue
            if (dj<0)|(dj>w-1):
                continue

            if s[di][dj]=="
                count+=1
        if count==0:
            print("No")
            exit()

print("Yes")

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

flag = 1
for i in range(H):
    for j in range(W):
        if s[i][j] == '
            if not i:
                if not j:
                    if s[i+1][j] == '.' and s[i][j+1] == '.':
                        flag = 0
                        break
                elif j == W - 1:
                    if s[i+1][j] == '.' and s[i][j-1] == '.':
                        flag = 0
                        break
                else:
                    if s[i+1][j] == '.' and s[i][j+1] == '.' and s[i][j-1] == '.':
                        flag = 0
                        break
            elif i == H - 1:
                if not j:
                    if s[i-1][j] == '.' and s[i][j+1] == '.':
                        flag = 0
                        break
                elif j == W - 1:
                    if s[i-1][j] == '.' and s[i][j-1] == '.':
                        flag = 0
                        break
                else:
                    if s[i-1][j] == '.' and s[i][j+1] == '.' and s[i][j-1] == '.':
                        flag = 0
                        break
            else:
                if not j:
                    if s[i+1][j] == '.' and s[i][j+1] == '.' and s[i-1][j] == '.':
                        flag = 0
                        break
                elif j == W - 1:
                    if s[i+1][j] == '.' and s[i][j-1] == '.' and s[i-1][j] == '.':
                        flag = 0
                        break
                else:
                    if s[i+1][j] == '.' and s[i][j+1] == '.' and s[i][j-1] == '.' and s[i-1][j] == '.':
                        flag = 0
                        break

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

Solution (Python):


h, w = map(int,input().split())




field = []

for _ in range(h):
    ii = list(input())   
    field.append(ii)



dxdy = [[1,0],[0,1],[0,-1],[-1,0]]

result = 'Yes'
for i in range(h):
    for j in range(w):
        countOK = 0
        countNG = 0
        cell1 = field[i][j]

        if cell1 == '

            
            
            for k in range(4):
                dx = dxdy[k][0]
                dy = dxdy[k][1]
                if i+dx <0:
                    continue
                if i+dx >h-1 :
                    continue
                if j+dy <0:
                    continue
                if j+dy >w-1:
                    continue

                cell2 = field[i+dx][j+dy]

                if cell2 == '
                    countOK += 1
                else:
                    countNG += 1

            
            if countOK == 0:
                result = 'No'


print(result)

Solution (Python):
def main():
    H, W = map(int, input().split())
    S = [input() for _ in range(H)]
    for r in range(H):
        for c in range(W):
            if S[r][c] == '.': continue
            bl = False
            if r > 0:
                bl |= (S[r - 1][c] == S[r][c])
            if r < H - 1:
                bl |= (S[r + 1][c] == S[r][c])
            if c > 0:
                bl |= (S[r][c - 1] == S[r][c])
            if c < W - 1:
                bl |= (S[r][c + 1] == S[r][c])
            if not bl:
                print('No')
                return
    print('Yes')


if __name__ == '__main__':
    main()