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):
n,m=map(int,input().split())
l1="."*(m+2)
l2="."+input()+"."
b=True
for i in range(n-1):
  l3="."+input()+"."
  for j in range(1,1+m):
    if l2[j]=="
      b=False
      break
  l1,l2=l2,l3
l3=="."*(m+2)
for j in range(m):
    if l2[j]=="
      b=False
      break
if b:
  print("Yes")
else:
  print("No")

Solution (Python):
def tonari(h,w):
    kuro = False
    if h != 0:
        if S[h-1][w] == '
            kuro = True
    if h != H-1:
        if S[h+1][w] == '
            kuro = True
    if w != 0:
        if S[h][w-1] == '
            kuro = True
    if w != W-1:
        if S[h][w+1] == '
            kuro = True
    if kuro == False:
        print('No')
        exit()

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

for h in range(H):
    for w in range(W):
        if S[h][w] == '
            tonari(h,w)

print('Yes')

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

flag = True
for i in range(h):
    for j in range(w):
        if s[i][j] == '
            neighbors = []
            if i != 0:
                neighbors.append([i-1, j])
            if i != h-1:
                neighbors.append([i+1, j])
            if j != 0:
                neighbors.append([i, j-1])
            if j != w-1:
                neighbors.append([i, j+1])
            neighbors_colors = []
            for n in neighbors:
                neighbors_colors.append(s[n[0]][n[1]])
            if '
                flag = False
if flag:
    print('Yes')
else:
    print('No')

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

datas = [input() for i in range(0, H, 1)]

array = []

cnt1 = 0
cnt2 = 0

for data in datas:
  tmp = [x for x in list(data)]
  array.append(tmp)

for i in range(0, H, 1):
  
  a1=0
  a2=0
  a3=0
  a4=0
  
  for j in range(0, W, 1):
    
    if array[i][j] == "

      cnt1 += 1
      
      try:
        if array[i][j-1] == "
          a1 = 1
        else:
          a1 = 0
      except:
        a1 = 0
        
      try:
        if array[i][j+1] == "
          a2 = 1
        else:
          a2 = 0
      except:
        a2 = 0
        
      try:
        if array[i-1][j] == "
          a3 = 1
        else:
          a3 = 0
      except:
        a3 = 0
        
      try:
        if array[i+1][j] == "
          a4 = 1
        else:
          a4 = 0
      except:
        a4 = 0
        
      if (a1 + a2 + a3 + a4) > 0:
        cnt2 += 1
     
    else:
      continue

if cnt1 == cnt2:
  print("Yes")
else:
  print("No")

Solution (Python):
import numpy as np

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

isPaintable = [[1]*w for _ in range(h)]

predList = [[0,1],[0,-1],[1,0],[-1,0]]

for i in range(h):
  for j in range(w):
    if hw[i][j] == "
      for x, y in predList:
        if i+y in range(h) and j+x in range(w):

          if hw[i+y][j+x]=="
            isPaintable[i][j] = 0
            break
    elif hw[i][j] == ".":
      isPaintable[i][j] = 0

if np.array(isPaintable).sum() == 0:
  print("Yes")
else:
  print("No")

Solution (Python):
import sys
input = sys.stdin.readline

H, W = map(int, input().split())
L = [list(input().strip()) for _ in range(H)]
NL = [["."] * W for _ in range(H)]

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

Solution (Python):


def read_input():
    h, w = map(int, input().split())
    board = []

    for i in range(h):
        s = [c for c in input().strip()]
        board.append(s)

    return h, w, board



def check_neighbor(board, i, j):
    if i - 1 >= 0:
        if board[i - 1][j] == '
            return True
    if i + 1 < len(board):
        if board[i + 1][j] == '
            return True

    if j - 1 >= 0:
        if board[i][j - 1] == '
            return True
    if j + 1 < len(board[i]):
        if board[i][j + 1] == '
            return True
    return False


def submit():
    h, w, board = read_input()

    for i in range(h):
        for j in range(w):
            if board[i][j] == '
                print('No')
                return

    print('Yes')


if __name__ == '__main__':
    submit()

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))
H+=1
W+=1
for h in range(H):
    for w in range(W):
        g = s[h][w]
        if g == ".":
            continue
        if '
            continue
        print("No")
        exit()

print("Yes")

Solution (Python):
H, W = map(int, input().split())
S =['.'*(W+2)]+ ['.'+input()+'.' for i in range(H)]+['.'*(W+2)]
flag = True
for i in range(1, H+1):
    for k in range(1, W+1):
        if S[i][k] == '
            if S[i-1][k] == '.' and S[i+1][k] == '.' and S[i][k+1] == '.' and S[i][k-1] == '.':
                flag = False
                break
    if not flag:
        break
if flag:
    print('Yes')
else:
    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][j-1] == field[i][j+1] == field[i+1][j] == '.':
      
      
        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):
h, w = map(int, input().split())
s = ['.' * (w+2)]
for i in range(h):
    s.append('.' + input() + '.')
s.append('.' * (w+2))
from itertools import product
for y, x in product(range(1, h + 1), range(1, w + 1)):
    if s[y][x] == '
        if True in [s[y + i][x + j] == '
            continue
        print('No')
        import sys
        sys.exit()
print('Yes')

Solution (Python):
H, W = map(int, input().split())
s = []
for i in range(-1, H+1):
	if i < 0 or i >= H:
		tmp = ["."] * (W + 1)
	else:
		tmp = ["."]
		for t in input():
			tmp.append(t)
	tmp.append(".")
	s.append(tmp)


for h in range(1, H+1):
	judge = True
	for w in range(1, W+1):
		if s[h][w] != "
			continue
		judge = False
		if s[h+1][w] == "
			judge = True
		if s[h-1][w] == "
			judge = True
		if s[h][w+1] == "
			judge = True
		if s[h][w-1] == "
			judge = True
		if not judge:
			break
	if not judge:
		break

ret = 'Yes' if judge else 'No'
print(ret)

Solution (Python):

BLACK = '
WHITE = '.'

def can_paint(arr, H, W, i, j):
    if (i > 0 and arr[i-1][j] == BLACK):
        return True
    elif (i < H - 1 and arr[i+1][j] == BLACK):
        return True
    elif (j > 0 and arr[i][j-1] == BLACK):
        return True
    elif (j < W - 1 and arr[i][j+1] == BLACK):
        return True
    else:
        return False

def solve():
    
    H, W = [int(_) for _ in raw_input().split()]
    arr = []
    for i in range(H):
        row = raw_input() 
        arr.append(row)
    
    for i in range(H):
        for j in range(W):
            if arr[i][j] == BLACK and not can_paint(arr, H, W, i, j):
                return False
    return True

if __name__ == '__main__':
    ret = solve()
    if ret:
        print 'Yes'
    else:
        print 'No'

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


def can_paint():
    for i in range(h):
        for j in range(w):
            if s[i][j] == '.':
                continue

            ns = []
            if i != 0:
                ns.append(s[i-1][j])
            if i != h-1:
                ns.append(s[i+1][j])
            if j != 0:
                ns.append(s[i][j-1])
            if j != w-1:
                ns.append(s[i][j+1])

            if ns.count('
                return False

    return True


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

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

c = 0
b = 0

def sirabe(t,i,j):
    if t[i-1][j] != "
        return False
    else:
        return True


for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == "
            if sirabe(s,i,j):
                continue
            else:
                c = 1
                break
    if c == 1:
        break


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

Solution (Python):
import  numpy as np
h,w=map(int,input().split())
s = [[0]*(w+2)]
for i in range(h):
    s.append([0]+list(input())+[0])
s.append([0]*(w+2))

t = np.array(s)
c = 0
b = 0

def sirabe(t,i,j):
    if t[i-1][j] != "
        return False
    else:
        return True


for i in range(1,h+1):
    for j in range(1,w+1):
        if t[i][j] == "
            if sirabe(t,i,j):
                continue
            else:
                c = 1
                break
    if c == 1:
        break


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

Solution (Python):
import itertools
H,W = map(int,input().split())
mas = [input() for _ in range(H)]
ans = 0
for i, j in itertools.product(range(H), range(W)):
    if mas[i][j] == '.':
        pass
    else :
        if i == 0 : 
            if j == W - 1 : 
                if mas[i][j-1] == '.' and mas[i][j+1] == '.' :
                    print('No')
                    
                    ans = 1
                    break
            elif j == 0 : 
                if mas[i+1][j] == '.' and mas[i][j+1] == '.' :
                    print('No')
                    
                    ans = 1
                    break
            else :
                if mas[i][j - 1] == '.' and mas[i + 1][j] == '.' and mas[i][j + 1] == '.':
                    print('No')
                    
                    ans = 1
                    break
        elif i == H - 1 : 
            if j == W - 1 : 
                if mas[i-1][j] == '.' and mas[i][j-1] == '.' :
                    print('No')
                    
                    ans = 1
                    break
            elif j == 0 : 
                if mas[i-1][j] == '.' and mas[i][j-1] == '.' :
                    print('No')
                    
                    ans = 1
                    break
            else :
                if mas[i-1][j] == '.' and mas[i][j + 1] == '.' and mas[i][j - 1] == '.':
                    print('No')
                    
                    ans = 1
                    break
        else : 
            if j == W - 1 : 
                if mas[i-1][j] == '.' and mas[i][j-1] == '.' and mas[i+1][j] == '.' :
                    print('No')
                    
                    ans = 1
                    break
            elif j == 0 : 
                if mas[i+1][j] == '.' and mas[i][j-1] == '.' and mas[i][j+1] == '.' :
                    print('No')
                    
                    ans = 1
                    break
            else :
                if mas[i-1][j] == '.' and mas[i + 1][j] == '.' and mas[i][j - 1] == '.' and mas[i][j + 1] == '.':
                    print('No')
                    
                    ans = 1
                    break
if ans == 0 :
    print('Yes')

Solution (Python):
h,w = map(int,input().split())
m = [list(str(input())) for i in range(h)]
for i in range(h):
    for j in range(w):
        if m[i][j] == "
            if i == 1:
                if j == 0:
                    obj = [m[i][j+1],m[i+1][j]]
                elif j == w - 1:
                    obj = [m[i][j-1],m[i+1][j]]
                else:
                    obj = [m[i][j-1],m[i][j+1],m[i+1][j]]
            elif i == h - 1:
                if j == 0:
                    obj = [m[i-1][j],m[i][j+1]]
                elif j == w - 1:
                    obj = [m[i-1][j],m[i][j-1]]
                else:
                    obj = [m[i-1][j],m[i][j-1],m[i][j+1]]
            else:
                if j == 0:
                    obj = [m[i-1][j],m[i][j+1],m[i+1][j]]
                elif j == w - 1:
                    obj = [m[i-1][j],m[i][j-1],m[i+1][j]]
                else:
                    obj = [m[i-1][j],m[i][j-1],m[i][j+1],m[i+1][j]]
            
            if "
                print("No")
                exit()
print("Yes")

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


f1 = True
for i in range(H):
  if not f1:
    break
  for j in range(W):
    if not f1:
      break
    if s[i][j] == '.':
      continue
    f = False
    if i >= 1 and s[i-1][j] == '
      f = True
    if j <= W-2 and s[i][j+1] == '
      f = True
    if i <= H-2 and s[i+1][j] == '
      f = True
    if j >= 1 and s[i][j-1] == '
      f = True
    if not f:
      f1 = False


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

Solution (Python):
H,W=map(int,input().split())
S=[]
for i in range(H):
    s=input()
    S.append(s)
for i in range(H):
    for j in range(W):
        if S[i][j]==".":
            continue
        l=[(j-1,i),(j+1,i),(j,i+1),(j,i-1)]
        koritu=True
        for x,y in l:
            if 0<=y<=H-1 and  0<=x<=W-1:
                koritu=koritu and S[y][x]=="."
        if koritu:
            print("No")
            quit()
print("Yes")

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

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

for i in range(H):
    for j in range(W):
        if S[i][j] == "
            if i == 0 and j == 0:
                if S[0][1] == "." and S[1][0] == ".":
                    print("No")
                    exit()
            elif i == 0 and j == W-1:
                if S[0][W-2] == "." and S[1][W-1] == ".":
                    print("No")
                    exit()
            elif i == H-1 and j == 0:
                if S[H-1][1] == "." and S[H-2][0] == ".":
                    print("No")
                    exit()
            elif i == H-1 and j == W-1:
                if S[H-1][W-2] == "." and S[H-2][W-1] == ".":
                    print("No")
                    exit()
            elif i == 0 and j >= 1:
                if S[i][j-1] == "." and S[i][j+1] == "." and S[i+1][j] == ".":
                    print("No")
                    exit()
            elif i == H-1 and j >=1:
                if S[i][j-1] == "." and S[i][j+1] == "." and S[i-1][j] == ".":
                    print("No")
                    exit()
            elif i >= 1 and j == 0:
                if S[i][j+1] == "." and S[i-1][j] == "." and S[i+1][j] == ".":
                    print("No")
                    exit()
            elif i >= 1 and j == W-1:
                if S[i][j-1] == "." and S[i-1][j] == "." and S[i+1][j] == ".":
                    print("No")
                    exit()
            elif i >=1 and j >= 1:
                if S[i][j-1] == "." and S[i][j+1] == "." and S[i-1][j] == "." and S[i+1][j] == ".":
                    print("No")
                    exit()
print("Yes")

Solution (Python):
H, W = map(int, input().split())
sw = [list(str(input())) for i in range(H)]
dx = [1,0,-1,0]
dy = [0,1,0,-1]

for i in range(H):
  for j in range(W):
    if sw[i][j] == "
      counter = 0
      for k in range(4):
        if i+dx[k] < 0 or i+dx[k] >= H or j+dy[k] < 0 or j+dy[k] >= W:
          counter += 1
        elif sw[i+dx[k]][j+dy[k]] == ".":
          counter += 1
      if counter == 4:
        print("No")
        exit()
print("Yes")

Solution (Python):
def calc(x, y):
    x2 = x
    y2 = y - 1
    x4 = x - 1
    y4 = y
    x5 = x + 1
    y5 = y
    x7 = x
    y7 = y + 1
    return x2, y2, x4, y4, x5, y5, x7, y7

h, w = map(int, input().split())
s = []
for _ in range(h):
    s.append(list(input()))
ans = "Yes"
for i in range(h * w):
    x = i // h
    y = i % h
    c = 0
    if s[y][x] == "
        x2, y2, x4, y4, x5, y5, x7, y7 = calc(x, y)
        aaa = [[x2, y2], [x4, y4], [x5, y5], [x7, y7]]
        for (xx, yy) in aaa:
            if ((xx >= 0) & (xx < w) & (yy >= 0) & (yy < h)):
                if s[yy][xx] == "
                    c += 1
        if c == 0:
            ans = "No"
            break
print(ans)

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

H,W = [int(x) for x in input().split()]
S = [list('.'*(W+2))]+[list('.'+input()+'.') for _ in range(H)]+[list('.'*(W+2))]
lix = [-1,0,1,0]
liy = [0,-1,0,1]
flag = True
def dfs(x,y):
    cnt = 0
    if(S[x][y]=='.'):
        return 0
    else:
        cnt += 1
        S[x][y]='.'
        for i in range(4):
            if(S[x+lix[i]][y+liy[i]]!='.'):
                cnt += dfs(x+lix[i],y+liy[i])
        return cnt

for i in range(1,H+1):
    for j in range(1,W+1):
          if(dfs(i,j)==1):
              flag = False
if(flag):
    print('Yes')
else:
    print('No')

Solution (Python):
def main():
	H, W = map(int, input().split())
	S = [""]*H
	for i in range(H):
		S[i] = input()

	for i in range(H):
		for j in range(W):
			if S[i][j] == ".":
				continue
			if (
				(i > 0 and S[i-1][j] == "
				or (j > 0 and S[i][j-1] == "
				or (i < H-1 and S[i+1][j] == "
				or (j < W-1 and S[i][j+1] == "
				):
				continue
			print("No")
			return

	print("Yes")


if __name__ == '__main__':
    main()

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


pics = []
tmp = ["."] * (w+2)
pics.append(tmp)
for i in range(h):
  tmp = list(input())
  tmp.insert(0,".")
  tmp.append(".")
  pics.append(tmp)
  
tmp = ["."] * (w+2) 
pics.append(tmp)
ans = "Yes"  

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

Solution (Python):
h,w=map(int,input().split())
l=[]
for i in range(h):
    li=[]
    for j in input():
        if j==".":li.append(0)
        elif j=="
    l.append(li)
for i in range(h):
    for j in range(w):
        if l[i][j]==1:
            x=0
            if i>0:x+=l[i-1][j]
            if i<h-1:x+=l[i+1][j]
            if j>0:x+=l[i][j-1]
            if j<w-1:x+=l[i][j+1]
            if x==0:
                print("No")
                break
    else:continue
    break
else:print("Yes")

Solution (Python):
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter

def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)


h,w= (int(i) for i in input().split())       





a=[input() for i in range(h)]    



for i in range(h):
    for k in range(w):
        if a[i][k] == '
            fail = 1
            if i:
                if a[i - 1][k] == '
            if i != h-1:
                if a[i + 1][k] == '

            if k:
                if a[i][k - 1] == '
            if k != w-1:
                if a[i][k + 1] == '
            if fail:j(0)
j(1)

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


for i in range(1,H,1):
    for j in range(1,W,1):
        if map[i][j] == "
            if map[i-1][j] != "
                print("No")
                exit()
print("Yes")

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

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

flg = True


def check(h, w):
    if h == 0:
        if w == 0:
            if HW[h + 1][w] == "
                return True
        elif w == W - 1:
            if HW[h + 1][w] == "
                return True
        else:
            if HW[h + 1][w] == "
                return True
    elif h == H - 1:
        if w == 0:
            if HW[h - 1][w] == "
                return True
        elif w == W - 1:
            if HW[h - 1][w] == "
                return True
        else:
            if HW[h - 1][w] == "
                return True
    else:
        if w == 0:
            if HW[h - 1][w] == "
                return True
        elif w == W-1:
            if HW[h - 1][w] == "
                return True
        else:
            if HW[h - 1][w] == "
                    HW[h][w-1] == "
                return True
    return False


for i in range(0, H):

    if flg is False:
        break
    for j in range(0, W):
        if HW[i][j] == "
            flg = check(i, j)
            
        if flg is False:
            break

if flg is True:
    print("Yes")
else:
    print("No")

Solution (Python):


















import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque

from itertools import product

from itertools import permutations

from itertools import combinations
from bisect import bisect_left, bisect_right


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


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

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")



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

flag = True

for y in range(H):
    for x in range(W):
        if f[y][x] == ".":
            continue
        tmp = False
        for i in range(4):
            ny = y + dy[i]
            nx = x + dx[i]
            if inside(ny, nx, H, W) and f[ny][nx] == "
                tmp = True
                break
        if not tmp:
            flag = False
            break

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

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

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

for i in range(h):
  for j in range(w):
    if j > 0 and a[i][j-1] != "." and a[i][j] == "
      a[i][j] = "*"
    elif j < w - 1 and a[i][j+1] != "." and a[i][j] == "
      a[i][j] = "*"
    elif i > 0 and a[i-1][j] != "." and a[i][j] == "
      a[i][j] = "*"
    elif i < h - 1 and a[i+1][j] != "." and a[i][j] == "
      a[i][j] = "*"

print("No" if sum([row.count("

Solution (Python):

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

campus = []

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


def search_lonely_sharp(l :list) -> list:
    _lonely_sharps = []
    ls = ['.'] + l + ['.']
    for i in range(1, len(ls)-1):
        if ls[i] == '
            _lonely_sharps.append(i-1)
    return _lonely_sharps


for i in range(1, H-1):
    before_line = campus[i-1]
    line = campus[i]
    after_line = campus[i+1]
    lonely_sharps = search_lonely_sharp(line)
    for j in lonely_sharps:
        if before_line[j] != '
            print('No')
            exit()

print('Yes')

Solution (Python):
H, W = map(int, input().split())
s = [['.'] * (W + 2)] + [list('.' + input() + '.') for _ in range(H)] + [['.'] * (W + 2)]
for h in range(1, H + 1):
    for w in range(1, W + 1):
        if s[h][w] == '.':
            continue
        if s[h - 1][w] == s[h + 1][w] == s[h][w - 1] == s[h][w + 1] == '.':
            print('No')
            exit()
print('Yes')

Solution (Python):
H, W = map(int, input().split())
s = [['.'] * (W + 2)] + [list('.' + input() + '.') for _ in range(H)] + [['.'] * (W + 2)]
for h in range(1, H + 1):
    for w in range(1, W + 1):
        if s[h][w] == '.':
            continue
        bcell = 0
        for x, y in ((-1, 0), (1, 0), (0, -1), (0, 1)):
            if s[h + x][w + y] == '
                bcell += 1
        if bcell < 1:
            print('No')
            exit()
print('Yes')

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

for h in range(H):
    for w in range(W):
        if data[h][w] == '
            if h - 1 >= 0:
                if data[h-1][w] == '
                    continue
            if w - 1 >= 0:
                if data[h][w-1] == '
                    continue
            if h + 1 <= H - 1:
                if data[h+1][w] == '
                    continue
            if w + 1 <= W - 1:
                if data[h][w+1] == '
                    continue
            print('No')
            exit()
print('Yes')

Solution (Python):
h,w=map(int,input().split())
l=["."*(w+2)]
for i in range(h):
  l+=["."+input()+"."]
l+=["."*(w+2)]
ans=0
for i in range(1,h+1):
  for j in range(1,w+1):
    if l[i][j]==".":
      continue
    if l[i+1][j]=="
      continue
    ans=1
print("YNeos"[ans::2])

Solution (Python):

import sys
INF = float("inf")


def yes():
    print("Yes")  


def no():
    print("No")  


def solve(H: int, W: int, s: "List[str]"):
    n = [[0]*(W+2) for _ in range(H+2)]
    for i in range(H):
        for j in range(W):
            if s[i][j] == "
                n[i+1][j+1] = 1  

    flag = True
    for i in range(1, H+1):
        for j in range(1, W+1):
            
            if n[i][j] == 1 and n[i-1][j]+n[i+1][j]+n[i][j-1]+n[i][j+1] == 0:
                flag = False
                break
        if flag == False:
            break
    if flag == False:
        no()
    else:
        yes()

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  
    W = int(next(tokens))  
    s = [next(tokens) for _ in range(H)]  
    solve(H, W, s)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

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

for i in range(H):
    for j in range(W):
        flg = 0
        if s[i][j] == '
            for k in range(4):
                x = i + [1, 0, -1, 0][k]
                y = j + [0, 1, 0, -1][k]
                if x < 0 or x >= H or y < 0 or y >= W:
                    continue
                if s[x][y] == '
                    flg = 1
            if flg == 0:
                print('No')
                sys.exit()

print('Yes')

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

ans="Yes"
for h in range(H):
	for w in range(W):
		if m[h][w] == "
			ok = False
			if h-1 >= 0 and m[h-1][w] == "
				ok = True
			if w-1 >= 0 and m[h][w-1] == "
				ok = True
			if h+1 < H and m[h+1][w] == "
				ok = True
			if w+1 < W and m[h][w+1] == "
				ok = True
			if not ok:
				ans="No"
print(ans)

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


picture = []
diff = [-1, 1]

for i_h in range(h):
    row = ''
    for i_w in range(w):
        can_draw = False
        if S[i_h][i_w] == '.': row = row + '.';continue
        else:
            for dh in diff:
                if (i_h+dh<0) or (i_h+dh>h-1):continue
                if S[i_h+dh][i_w] == '
                    can_draw = True
            for dw in diff:
                if (i_w+dw<0) or (i_w+dw>w-1):continue
                if S[i_h][i_w+dw] == '
                    can_draw = True
                    
        if can_draw:
            row = row + '
        else:
            row = row + '.'
    picture.append(row)
    
if picture == S:
    print('Yes')
else:
    print('No')

Solution (Python):
import sys
from sys import stdin
H, W = [int(_) for _ in stdin.readline().rstrip().split()]
data = [list(stdin.readline().rstrip()) for _ in range(H)]
for i in range(H):
    for j in range(W):
        if data[i][j] == '
            if i==0:
                if j==0:
                    if data[i][j+1] == '.' and data[i+1][j] == '.':
                        print('No')
                        sys.exit()
                elif j==W-1:
                    if data[i][j-1] == '.' and data[i+1][j] == '.':
                        print('No')
                        sys.exit()
                else:
                    if data[i][j+1] == '.' and data[i][j-1] == '.' and data[i+1][j] == '.':
                        print('No')
                        sys.exit()
            elif i==H-1:
                if j==0:
                    if data[i][j+1] == '.' and data[i-1][j] == '.':
                        print('No')
                        sys.exit()
                elif j==W-1:
                    if data[i][j-1] == '.' and data[i-1][j] == '.':
                        print('No')
                        sys.exit()
                else:
                    if data[i][j+1] == '.' and data[i][j-1] == '.' and data[i-1][j] == '.':
                        print('No')
                        sys.exit()
            else:
                if j==0:
                    if data[i][j+1] == '.' and data[i+1][j] == '.' and data[i-1][j] == '.':
                        print('No')
                        sys.exit()
                elif j==W-1:
                    if data[i+1][j] == '.' and data[i][j-1] == '.' and data[i-1][j] == '.':
                        print('No')
                        sys.exit()
                else:
                    if data[i][j+1] == '.' and data[i][j-1] == '.' and data[i-1][j] == '.' and data[i+1][j] == '.':
                        print('No')
                        sys.exit()
print('Yes')

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

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

for i in range(H):
    for j in range(W):
        if grid[i][j] == '
            if i > 0:
                if grid[i-1][j] == '
                    continue
            if i < H-1:
                if grid[i+1][j] == '
                    continue
            if j > 0:
                if grid[i][j-1] == '
                    continue
            if j < W-1:
                if grid[i][j+1] == '
                    continue
            print('No')
            quit()
print('Yes')