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())
fi=[[False] * W for i in range(H)]
for i in range(H):
    s=input().strip()
    for j in range(W):
        fi[i][j]=s[j]
fl=True
for i in range(H):
    for j in range(W):
        if fi[i][j]=='
            if i-1>=0 and j-1>=0 and i+1<H and j+1<W:
                if fi[i+1][j]=='.' and fi[i][j+1]=='.' and fi[i-1][j]=='.' and fi[i][j-1]=='.':
                    fl=False
            elif i-1<0 and j-1>=0 and i+1<H and j+1<W:
                if fi[i+1][j]=='.' and fi[i][j+1]=='.' and fi[i][j-1]=='.':
                    fl=False
            elif i-1>=0 and j-1<0 and i+1<H and j+1<W:
                if fi[i+1][j]=='.' and fi[i][j+1]=='.' and fi[i-1][j]=='.':
                    fl=False
            elif i-1>=0 and j-1>=0 and i+1>=H and j+1<W:
                if fi[i][j+1]=='.' and fi[i-1][j]=='.' and fi[i][j-1]=='.':
                    fl=False
            elif i-1>=0 and j-1>=0 and i+1<H and j+1>=W:
                if fi[i+1][j]=='.' and fi[i-1][j]=='.' and fi[i][j-1]=='.':
                    fl=False
            elif i-1<0 and j-1<0 and i+1<H and j+1<W:
                if fi[i+1][j]=='.' and fi[i][j+1]=='.':
                    fl=False
            elif i-1<0 and j-1>=0 and i+1>=H and j+1<W:
                if fi[i][j+1]=='.' and fi[i][j-1]=='.':
                    fl=False
            elif i-1<0 and j-1>=0 and i+1<H and j+1>=W:
                if fi[i+1][j]=='.' and fi[i][j-1]=='.':
                    fl=False
            elif i-1>=0 and j-1<0 and i+1>=H and j+1<W:
                if fi[i][j+1]=='.' and fi[i-1][j]=='.':
                    fl=False
            elif i-1>=0 and j-1<0 and i+1<H and j+1>=W:
                if fi[i+1][j]=='.' and fi[i-1][j]=='.':
                    fl=False
            elif i-1>=0 and j-1>=0 and i+1>=H and j+1>=W:
                if  fi[i-1][j]=='.' and fi[i][j-1]=='.':
                    fl=False
            elif i-1>=0 and j-1<0 and i+1>=H and j+1>=W:
                if fi[i-1][j]=='.':
                    fl=False
            elif i-1<0 and j-1>=0 and i+1>=H and j+1>=W:
                if fi[i][j-1]=='.':
                    fl=False
            elif i-1<0 and j-1<0 and i+1<H and j+1>=W:
                if fi[i+1][j]=='.':
                    fl=False
            elif i-1<0 and j-1<0 and i+1>=H and j+1<W:
                if fi[i][j+1]=='.':
                    fl=False
            elif i-1<0 and j-1<0 and i+1>=H and j+1>=W:
                fl=False
                    


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

Solution (Python):
def inner(i, j):
    return 0 <= i and i < H and 0 <= j and j < W

def ok(s):
    for i in range(H):
         for j in range(W):
             if s[i][j] == '
                 if inner(i-1, j) and s[i-1][j] == '
                     continue
                 if inner(i+1, j) and s[i+1][j] == '
                     continue
                 if inner(i, j-1) and s[i][j-1] == '
                     continue
                 if inner(i, j+1) and s[i][j+1] == '
                     continue
                 return 'No'
    return 'Yes'


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

Solution (Python):
import sys
def 解():
    iH,iW = [int(_) for _ in input().split()]

    aS = ["."*(iW+2)]+["."+sLine+"." for sLine in sys.stdin.readlines()]+["."*(iW+2)]

    for i in range(1,iH+1):
        for j in range(1,iW+1):
            if aS[i][j] == "
                if "
                    print("No")
                    exit()
    print("Yes")
解()

Solution (Python):
h,w = map(int,input().split())
field = []
xx = [-1, 0, 0, 1]
yy = [0, -1, 1, 0]

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

for i in range(h):
    for j in range(w):
        if field[i][j] == '
            flag = False
            for x,y in zip(xx,yy):
                if i+x < 0 or i+x > h-1:
                    continue
                elif j+y < 0 or j+y > w-1:
                    continue
                elif field[i+x][j+y] == '
                    flag = True     
                    break
            if flag == False:
                print('No')
                exit()

print('Yes')

Solution (Python):
flag = 1
H,W = map(int,input().split())
L = []
for i in range(H) :
    L.append(input())
dxy = [(1,0),(-1,0),(0,1),(0,-1)]

for x in range(W) :
    for y in range(H) :
        if L[y][x] == "
            for dx,dy in dxy :
                nx,ny = x+dx,y+dy
                if (0 <= nx <= W-1) and (0 <= ny <= H-1) :
                    if L[ny][nx] == "
                        flag = 1
                        break
                    else :
                        flag = 0
if flag == 1 :
    print("Yes")
else :
    print("No")

Solution (Python):
H,W = map(int,input().split())
L = [input() for i in range(H)]
dxy = [[1,0],[-1,0],[0,1],[0,-1]]
flag = 1

for y in range(H) :
    for x in range(W) :
        if L[y][x] == "
            for dx,dy in dxy :
                nx = x+dx
                ny = y+dy
                if (0 <= nx <= W-1) and (0 <= ny <= H-1) :
                    if L[ny][nx] == "
                        flag = 1
                        break
                    else :
                        flag = 0
if flag == 1 :
    print("Yes")
else :
    print("No")

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

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

print("Yes")

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

for y in range(H):
    for x in range(W):
        if S[y][x] == "
            f = 1
            if y+1 < H:
                if S[y+1][x] == "
                    f = 0
            if x+1 < W:
                if S[y][x+1] == "
                    f = 0
            if 0 <= y-1:
                if S[y-1][x] == "
                    f = 0
            if 0 <= x-1:
                if S[y][x-1] == "
                    f = 0
            if f:
                print("No")
                exit(0)

print("Yes")

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

for i in range(1,H+1):
    for j in range(1,W+1):
        if s[i][j]=="
            if s[i-1][j]!="
                
                check=0

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

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

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

h,w = li()

grid = [list(lc()) for _ in range(h)]

dhs = [-1,0,1,0]
dws = [0,-1,0,1]

achive = True

for hi in range(h):
    for wj in range(w):
        ok = False
        if grid[hi][wj] == ".":
            continue
        
        for dh,dw in zip(dhs,dws):
            if 0 <= hi+dh < h and 0 <= wj+dw < w:
                if grid[hi+dh][wj+dw] == "
                    ok = True
                    
        if not ok:
            achive = False

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

Solution (Python):
H,W = map(int,input().split())
src = [input() for i in range(H)]
dxy = [(0,1),(1,0),(0,-1),(-1,0)]
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] == '
        else:
            print('No')
            exit()
print('Yes')

Solution (Python):

H, W = map(int, input().split())
s = [0]*H

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

def test(x, y):
    if check(x, y):
        return s[y][x]
    else:
        return "."

for i in range(H):
    s[i] = input()
ans = "Yes"
for y in range(H):
    for x in range(W):
        if s[y][x] == "
            l = list(map(lambda p: test(p[0], p[1]), [(x-1, y),(x+1, y),(x, y-1),(x, y+1)]))
            if "
               ans = "No"
               break
print(ans)

Solution (Python):
h,w=map(int,input().split())
l=[list(input()) for i in range(h)]
c=0
for j in range(h):
  for k in range(w):
    if l[j][k]=='
      if j!=0 and j!=h-1 and k!=0 and k!=w-1:
        if l[j-1][k]=='.' and l[j][k-1]=='.' and l[j][k+1]=='.' and l[j+1][k]=='.':
          c+=1
      elif j==0 and k!=0 and k!=w-1:
        if  l[j][k-1]=='.' and l[j][k+1]=='.' and l[j+1][k]=='.':
          c+=1
      elif j==h-1 and k!=0 and k!=w-1:
        if l[j-1][k]=='.' and l[j][k-1]=='.' and l[j][k+1]=='.':
          c+=1
      elif j!=0 and j!=h-1 and k==0:
        if l[j-1][k]=='.' and  l[j][k+1]=='.' and l[j+1][k]=='.':
          c+=1
      elif j!=0 and j!=h-1 and k==w-1:
        if l[j-1][k]=='.' and l[j][k-1]=='.' and l[j+1][k]=='.':
          c+=1
      elif j==0 and k==0:
        if l[j][k+1]=='.' and l[j+1][k]=='.':
          c+=1
      elif j==0 and k==w-1:
        if l[j][k-1]=='.' and l[j+1][k]=='.':
          c+=1
      elif j==h-1 and k==0:
        if l[j-1][k]=='.' and l[j][k+1]=='.':
          c+=1
      else:
        if l[j-1][k]=='.' and l[j][k-1]=='.':
          c+=1
if c!=0:print('No')
else:print('Yes')

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

for i in range(H):
  for j in range(W):
    if s[i][j] == '
      count = 0
      for k in [[1,0], [0, 1], [-1, 0], [0, -1]]:
        if 0 <= i+k[1] < H and 0 <= j+k[0] < W:
          if s[i+k[1]][j+k[0]] == '
            count += 1
          else:
            pass
      if count == 0:
        print('No')
        exit()
      else:
        pass
    else:
      pass

print('Yes')

Solution (Python):
H, W = map(int, input().split())
C = [''.join(['.' for j in range(W + 2)]) for i in range(H + 2)]
for i in range(1, H + 1):
  C[i] = '.' + input() + '.'
drawable = True
for i in range(1, H + 1):
  for j in range(1, W + 1):
    if C[i][j] == '
      drawable = False
print('Yes' if drawable else 'No')

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

for i in range(h):
    a = input()
    s.append([str(m) for m in list(str(a))])


p = 0
for i in range(h):
    for j in range(w):
        if i > 0 and j > 0 and i < h - 1 and j < w - 1:
            if s[i][j] == "
                print("No")
                p = 1
                break
        if i == 0 and j != 0 and j != w - 1:
            if s[i][j] == "
                print("No")
                p = 1
                break
        if i == h - 1 and j != 0 and j != w - 1:
            if s[i][j] == "
                print("No")
                p = 1
                break
        if j == 0 and i != 0 and i != h - 1:
            if s[i][j] == "
                print("No")
                p = 1
                break
        if j == w - 1 and i != 0 and i != h - 1:
            if s[i][j] == "
                print("No")
                p = 1
                break
        if i == 0 and j == 0:
            if s[i][j] == "
                print("No")
                p = 1
                break
        if i == 0 and j == w - 1:
            if s[i][j] == "
                print("No")
                p = 1
                break
        if i == h - 1 and j == 0:
            if s[i][j] == "
                print("No")
                p = 1
                break
        if i == h - 1 and j == w - 1:
            if s[i][j] == "
                print("No")
                p = 1
                break

    else:  
        continue  
    break  

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

Solution (Python):
h,w = map(int,input().split())
ls = []
ans = 0
for i in range(h):
    ls.append(input())
for i in range(w):
    for j in range(h):
        if ls[j][i] == '.':
            pass
        elif j == h-1 and i == w-1:
            if ls[j-1][i] == '
                pass
            else:
                ans = 1
                break
        elif j == h-1 and i == 0:
            if ls[j-1][i] == '
                pass
            else:
                ans = 1
                break
        elif j == 0 and i == w-1:
            if ls[j+1][i] == '
                pass
            else:
                ans = 1
                break
        elif j == 0 and i == 0:
            if ls[j-1][i] == '
                pass
            else:
                ans = 1
                break
        elif j == 0:
            if ls[j+1][i] == '
                pass
            else:
                ans = 1
                break
        elif i == 0:
            if ls[j-1][i] == '
                pass
            else:
                ans = 1
                break
        elif j == h-1:
            if ls[j-1][i] == '
                pass
            else:
                ans = 1
                break
        elif i == w-1:
            if ls[j-1][i] == '
                pass
            else:
                ans = 1
                break
        
        
        else:
            if ls[j-1][i] == '
                pass
            else:
                ans = 1
                break
    if ans == 1:
        break
if ans == 0:
    print('Yes')
else:
    print('No')

Solution (Python):
H, W = map(int, input().split())
s = [[] for i in range(H)]
num = 0
judge = 0
start = []
for i in range(H):
    s[i] = input()
    if '
        num += s[i].count('

if num == 0:
    print('Yes')
else:
    for y in range(H):
        for x in range(W):
            flag = False
            if s[y][x] == '
                for dy, dx in [1, 0], [-1, 0], [0, 1], [0, -1]:
                    if 0 <= y + dy <= H-1 and 0 <= x+dx <= W-1:
                        if s[y+dy][x+dx] != '
                            continue
                        else:
                            flag = True
                if flag == True:
                    judge += 1
                    
    if num == judge:
        print('Yes')
    else:
        print('No')

Solution (Python):
import sys
(h, w) = map(int, input().split())
D = '.'
sw = []
sw.append([D for i in range(w + 2)])
for i in range(h):
    sw.append([D] + list(input()) + [D])
sw.append([D for i in range(w + 2)])

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if sw[i][j] == D:
            continue
        ok = False
        for dir in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
            if sw[i + dir[0]][j + dir[1]] == '
                ok = True
                break
        if ok == False:
            print('No')
            sys.exit(0)
print('Yes')

Solution (Python):

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

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

    field=[]
    field.append("."*(W+2))
    for i in range(H):
        field.append("." + input() + ".")
    field.append("."*(W+2))
    for i in range(1,H+1):
        for j in range(1,W+1):
            if(field[i][j]=="
                if(field[i-1][j]=="
                    pass
                else:
                    print("No")
                    return 0
    print("Yes")


judge()

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

def singleB(i, j):
    search = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    single = True
    for s in search:
        if 0 <= i+s[0] <= H-1 and 0 <= j+s[1] <= W-1:
                if S[i+s[0]][j+s[1]] == "
                        single = False
    return single

Success = True
for i in range(H):
    for j in range(W):
        if S[i][j] == "
            if singleB(i, j):
                Success = False
print("Yes" if Success else "No")

Solution (Python):
def run(H, W, s):
    for y in range(H):
        for x in range(W):
            if check(s, H, W, y, x):
                continue
            else:
                return 'No'
    return 'Yes'


def check(s, H, W, y, x):
    '''
    sの(x, y)座標から見て、4方向をチェックする
    (x, y)が'
    (x, y)が'.'の場合は、True
    '''
    ret = False
    if s[y][x] == '.':
        ret = True
    if x - 1 >= 0:
        if s[y][x-1] == '
            ret = True
    if x + 1 < W:
        if s[y][x+1] == '
            ret = True
    if y - 1 >= 0:
        if s[y-1][x] == '
            ret = True
    if y + 1 < H:
        if s[y+1][x] == '
            ret = True
    return ret


def main():
    H, W = map(int, input().split())
    s = []
    for i in range(H):
        s.append(input())
    print(run(H, W, s))


if __name__ == '__main__':
    main()

Solution (Python):
H, W = map(int, input().split())
S = [['.' for _ in range(W + 2)]]
for i in range(H):
    S.append(['.'] + list(input()) + ['.'])
S.append(['.' for _ in range(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] == '.' and S[i][j - 1] == '.' and S[i][j + 1] == '.' and S[i + 1][j] == '.':
                print('No')
                exit()
print('Yes')

Solution (Python):
h, w = [int(_) for _ in input().split()]
s = [[_ for _ in list(input())] for _ in range(h)]
l = [['.' for i in range(w + 2)] for j in range(h + 2)]
ans = 'Yes'
for i in range(h):
    for j in range(w):
        if s[i][j] == '
            l[i+1][j+1] = '
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] == '.':
                ans = "No"
print(ans)

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

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

for i in range(H):
    for j in range(W):
        if s[i][j] =='
            flag = 0
            if i-1 >= 0 and s[i-1][j] == '
                flag = 1
            if j-1 >= 0 and s[i][j-1] == '
                flag = 1
            if j+1 < W and s[i][j+1] == '
                flag = 1
            if i+1 < H and s[i+1][j] == '
                flag = 1
            if flag == 0:
                print('No')
                exit()
                
print('Yes')

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

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

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

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):
        OK_cnt = 0
        if s[i][j] == '
            
            if j > 0 and s[i][j-1] == '
                OK_cnt += 1
            
            if i+1 < H and s[i+1][j] == '
                OK_cnt += 1
            
            if j+1 < W and s[i][j+1] == '
                OK_cnt += 1
            
            if i > 0 and s[i-1][j] == '
                OK_cnt += 1
            if OK_cnt == 0:
                print('No')
                exit()

print('Yes')

Solution (Python):
h,w=map(int, input().split())
s = ["."*(w+2)]+["."+input()+"." for i in range(h)]+["."*(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'
                break
print(ans)

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

for h in range(H):
    for w in range(W):
        if S[h][w] == '
            flag = False
            for i in [-1, 0, 1]:
                for j in [-1, 0, 1]:
                    if not i+j in [-1, 1]:
                        continue
                    if 0 <= h+i < H and 0 <= w+j < W:
                        if S[h+i][w+j] == '
                            flag = True
            if not flag:
                print('No')
                exit()
print('Yes')

Solution (Python):
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] == '
            flag = False
            for i in [-1, 0, 1]:
                for j in [-1, 0, 1]:
                    if not i+j in [-1, 1]:
                        continue
                    if 0 <= h+i < H and 0 <= w+j < W:
                        if S[h+i][w+j] == '
                            flag = True
            if not flag:
                print('No')
                exit()
print('Yes')

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

adj = [(1, 0), (0, 1), (-1, 0), (0, -1)]
non_adj = 0
for y in range(h):
    for x in range(w):
        if s[y][x] == '.':
            continue
        n_adj = 0
        for dx, dy in adj:
            i, j = y+dy, x+dx
            if i < 0 or i >= h or j < 0 or j >= w:
                continue
            if s[i][j] == '
                n_adj += 1
        if n_adj == 0:
            non_adj += 1

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

Solution (Python):
import sys


H, W = map(int, input().split())
ss = ['.' + input() + '.' for i in range(H)]
ss = ['.' * (W + 2)] + ss + ['.' * (W + 2)]

dijs = [(-1, 0), (1, 0), (0, -1), (0, 1)]
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if ss[i][j] == '.': continue
        for di, dj in dijs:
            if ss[i + di][j + dj] == '
                break
        else:
            print('No')
            sys.exit(0)

print('Yes')

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

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

xy=[(1,0),(-1,0),(0,1),(0,-1)]


for i in range(h):
  for j in range(w):
    if area[i][j] == '
      f = 0
      for x, y in xy:
        if 0 <= i + y < h and 0 <= j + x < w and area[i+y][j+x]=="
          f=1
      if f == 0:
        print('No')
        exit()

print('Yes')

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

h,w=map(int,input().split())
l=[]
for i in range(h):
    l.append(input())
for i in range(h):
    for j in range(w):
        if l[i][j]=="
            f=0
            for x,y in xy:
                if 0<=(i+y)<h and 0<=(j+x)<w and l[i+y][j+x]=="
            if f==0:
                print("No")
                exit()
                

print("Yes")

Solution (Python):
H,W = map(int,raw_input().split())
 
s = []
for i in range(H):
	s.append(raw_input())
 
flag=True
for i in range(H):
	for j in range(W):
		if s[i][j]=='
			local_flag=False
			if i+1<H:
				if s[i+1][j]=='
					local_flag=True
			if j+1<W:
				if s[i][j+1]=='
					local_flag=True
			if i-1>=0:
				if s[i-1][j]=='
					local_flag=True
			if j-1>=0:
				if s[i][j-1]=='
					local_flag=True
			if local_flag==False:
				flag=False
if flag:
	print 'Yes'
else:
	print 'No'

Solution (Python):
h,w = map(int, input().split())
list_pic = []
for i in range(h):
    list_pic.append(list(str(input())))
ans = "Yes"
for i in range(h):
    for j in range(w):
        if list_pic[i][j] == "
            check = "NO"
            try:
                if list_pic[i+1][j] == "
                    check = "OK"
            except IndexError:
                pass
            try:
                if list_pic[i-1][j] == "
                    check = "OK"
            except IndexError:
                pass
            try:
                if list_pic[i][j+1] == "
                    check = "OK"
            except IndexError:
                pass
            try:
                if list_pic[i][j-1] == "
                    check = "OK"
            except IndexError:
                pass

            if check != "OK":
                ans = "No"
                break
        else:
            pass
    else:
        continue
    break

print(ans)

Solution (Python):
hw_list = list(map(int, input().split()))
h = hw_list[0]
w = hw_list[1]
row_list = ['.'*(w+2)]

def impossible_check(area, x, y):
    impossible = True
    if area[y-1][x] == '
        impossible = False
    if area[y][x-1] == '
        impossible = False
    if area[y][x+1] == '
        impossible = False
    if area[y+1][x] == '
        impossible = False
    return impossible

for i in range(h):
    row_list.append('.'+ input()+ '.')
row_list.append('.'*(w+2))

for y in range(1, h+1):
    for x in range(1, w+1):
        if row_list[y][x] == '
            print('No')
            exit()

print('Yes')

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))


    

no=0
for i in range(h):
    for j in range(w):
        
        if S[i][j]=="
            no=1

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

Solution (Python):
H,W=list(map(int,input().split()))
img=[[0 for _ in range(W+2)] for _ in range(H+2)]
for y in range(H):
    for x,c in enumerate(input()):
        if c=='
            img[y+1][x+1]=1
ans='Yes'
for y in range(1,H+1):
    for x in range(1,W+1):
        if img[y+1][x+1]==1:
            if img[y][x+1]+img[y+2][x+1]+img[y+1][x+2]+img[y+1][x]==0:
                ans='No'
                break
    if ans=='No':
        break
print(ans)

Solution (Python):
def is_success(s, h, w):
    for i in range(h):
        for j in range(w):
            if s[i][j] != '
                continue
            if i >= 1 and s[i-1][j] == '
                continue
            if i <= h-2 and s[i+1][j] == '
                continue
            if j >= 1 and s[i][j-1] == '
                continue
            if j <= w-2 and s[i][j+1] == '
                continue
            return 'No'

    return 'Yes'


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

print(is_success(s, h, w))

Solution (Python):
height, width = map(int, input().split())

matrix = []
for h in range(height):
    matrix.append(input())

for h in range(height):
    for w in range(width):
        
        able = False
        if matrix[h][w] == "
            try:
                if matrix[h+1][w] == "
                    able = True
            except:
                pass
            
            try:
                if matrix[h-1][w] == "
                    able = True
            except:
                pass
            
            try:
                if matrix[h][w+1] == "
                    able = True
            except:
                pass
            
            try:
                if matrix[h][w-1] == "
                    able = True
            except:
                pass
        
            if able is False:
                print("No")
                exit(0)

print("Yes")

Solution (Python):
h, w = map(int, input().split())
s = [["."] * (w + 1)]
for i in range(h):
    s.append(["."] + list(input()) + ["."])
s.append(["."] * (w + 1))
for i in range(h):
    for j in range(w):
        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")
                exit()
print("Yes")