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())
c = []
for _ in range(h):
    c.append(input())
for i in range(h):
    for j in range(w):
        if c[i][j] == '.':
            continue
        if i == 0:
            if j == 0:
                if c[i][j+1] == '.' and c[i+1][j] == '.':
                    print('No')
                    exit(0)
            elif j == w-1:
                if c[i][j-1] == '.' and c[i+1][j] == '.':
                    print('No')
                    exit(0)
            else:
                if c[i][j-1] == '.' and c[i+1][j] == '.' and c[i][j+1] == '.':
                    print('No')
                    exit(0)
        elif i == h-1:
            if j == 0:
                if c[i][j+1] == '.' and c[i-1][j] == '.':
                    print('No')
                    exit(0)
            elif j == w-1:
                if c[i][j-1] == '.' and c[i-1][j] == '.':
                    print('No')
                    exit(0)
            else:
                if c[i][j-1] == '.' and c[i-1][j] == '.' and c[i][j+1] == '.':
                    print('No')
                    exit(0)
        else:
            if j == 0:
                if c[i][j+1] == '.' and c[i-1][j] == '.' and c[i+1][j] == '.':
                    print('No')
                    exit(0)
            elif j == w-1:
                if c[i][j-1] == '.' and c[i-1][j] == '.' and c[i+1][j] == '.':
                    print('No')
                    exit(0)
            else:
                if c[i][j-1] == '.' and c[i-1][j] == '.' and c[i][j+1] == '.' and c[i+1][j] == '.':
                    print('No')
                    exit(0)
print('Yes')

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

s.append(['.']*(w+2))
for i in range(1,h+1):
    s[i].insert(0,'.')
    s[i].append('.')


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

print("Yes")

Solution (Python):
h, w = list(map(int, input().split()))
graph = []
def check(s,t):
    if (0 <=  s <= w - 1) and (0 <= t <= h - 1):
        return True
    else:
        return False
def check_around(x,y):
    if check(x+1,y) and graph[y][x+1] == '
        return True
    if check(x,y+1) and graph[y+1][x] == '
        return True
    if check(x-1,y) and graph[y][x-1] == '
        return True
    if check(x,y-1) and graph[y-1][x] == '
        return True
    return False
for i in range(h):
    graph.append(list(input()))
for i in range(h):
    for j in range(w):
        if graph[i][j] == '
            if  not check_around(j,i):
                print("No")
                exit()
print("Yes")

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

Solution (Python):
H, W = map(int,input().split())
S = [input() for i in range(H)]
ok = True
def check(i,j,H,W,S):
    flag = False
    if i+1 <= H-1:
        if S[i+1][j] == "
            flag = True
    if i-1 >= 0:
        if S[i-1][j] == "
            flag = True
    if j+1 <= W-1:
        if S[i][j+1] == "
            flag = True
    if j-1 >= 0:
        if S[i][j-1] == "
            flag = True
    return flag
for i in range(H):
    for j in range(W):
        if S[i][j] == "
            ch = check(i,j,H,W,S)
            if not ch:
                ok = False
                break
    if not ok:
        break
if ok:
    print("Yes")
else:
    print("No")

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

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

Solution (Python):
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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

H,W = two_int()

maps = [list(input()) for i in range(H)]

import copy 
temp_maps = copy.deepcopy(maps)


def solve(W,H,maps):
    start_X=0
    start_Y=0
    for x in range(W):
        for y in range(H):
            count=0

            if maps[y][x]=="
                count += 1

                if x+1 < W:
                    if maps[y][x+1]=="
                        count += 1     

                if y+1 < H:
                    if maps[y+1][x]=="
                        count += 1     

                if x-1 >= 0:
                    if maps[y][x-1]=="
                        count += 1     


                if y-1 >= 0:
                    if maps[y-1][x]=="
                        count += 1     

                if count==1:
                    return "No"
    return "Yes"

ans = solve(W,H,maps)
print(ans)

Solution (Python):
h, w = map(int, input().split())
table = [list(input()) for i in range(h)]
mask = [[1,0], [0,1], [-1, 0], [0, -1]]
flag = True

for i in range(h):
  for j in range(w):
    if table[i][j] == '
      count = 0
      for k in range(len(mask)):
        if (i + mask[k][0]) >= 0 and (i + mask[k][0]) < h and (j + mask[k][1]) >= 0 and (j + mask[k][1]) < w:
          if table[i+mask[k][0]][j+mask[k][1]] == '
            count+=1
     
      if count == 0:
        flag = False
  if flag == False:
    break
       
if flag:
  print("Yes")
else:
  print("No")

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

ok = True
def check(i,j,H,W,s):
    flag = False
    if (i+1) <= (H-1):
        if s[i+1][j] == "
            flag = True
    if (i-1) >= 0:
        if s[i-1][j] == "
            flag = True
    if (j+1) <= (W-1):
        if s[i][j+1] == "
            flag = True
    if (j-1) >= 0:
        if s[i][j-1] == "
            flag = True
    return flag

for i in range(H):
    for j in range(W):
        if s[i][j] == "
            ch = check(i,j,H,W,s)
            if not ch:
                ok = False
                break
    if not ok:
        break



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

Solution (Python):
H, W = map(int, input().split())
s = [input() for i 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 = False
            for k in range(4):
                if s[i][j] == '
                    nx = j + dx[k]
                    ny = i + dy[k]
                    if nx < 0 or nx >= W or ny < 0 or ny >= H:
                        continue
                if s[ny][nx] == '
                    flag = True
            if flag == False:
                print('No')
                exit()        

print('Yes')

Solution (Python):
def solve(h, w, S):
    A = [[s == '
    for y in range(h):
        for x in range(w):
            if A[y][x] and \
                (y == 0 or not A[y - 1][x]) and (y == h - 1 or not A[y + 1][x]) and \
                (x == 0 or not A[y][x - 1]) and (x == w - 1 or not A[y][x + 1]):
                return 'No'
    return 'Yes'

_h, _w = map(int, input().split())
_S = [input() for _ in range(_h)]
print(solve(_h, _w, _S))

Solution (Python):
N, M = map(int,input().split()) 
p = [input() for i in range(N)]

ans = "Yes"
for n in range(1,N-1):
    for m in range(1,M-1):
        if p[n][m] == '
            if p[n-1][m] != "
                ans = "No"
                break
print(ans)

Solution (Python):
n,m = map(int,input().split())
l = [list(input()) for i in range(n)]
for i in range(n):
    for j in range(m):
        if l[i][j] == "
            count = 0
            if 0 < i and l[i-1][j] == "
                count += 1
            if 0 < j and l[i][j-1] == "
                count += 1
            if i != n-1 and l[i+1][j] == "
                count += 1
            if j != m-1 and l[i][j+1] == "
                count += 1
            if count == 0:
                print("No")
                exit()
print("Yes")

Solution (Python):
from itertools import product

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

ans = "Yes"
for y, x in product(range(H), range(W)):
    if grid[y][x] != "
        continue
    for dy, dx in ((0, -1), (0, 1), (-1, 0), (1, 0)):
        ny, nx = y + dy, x + dx
        if not (0 <= ny < H and 0 <= nx < W):
            continue
        if grid[ny][nx] == "
            break
    else:
        ans = "No"
print(ans)

Solution (Python):
N,M = map(int, input().split())
boards = [None] * N
passed = [[False] * M for i in range(N)]
for i in range(N):
    boards[i] = list(input())
for i in range(N):
    for j in range(M):
        if boards[i][j] == '
            if ((i < N - 1 and boards[i+1][j] == '
                (i >= 1 and boards [i-1][j] == '
                (j < M - 1 and boards[i][j+1] == '
                (j >= 1 and boards[i][j-1] == '
                    continue
            else:
                print('No')
                exit()
print('Yes')

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

dh = (-1, 0, 0, 1)
dw = (0, -1, 1, 0)
for i in range(h):
    for j in range(w):
        if s[i][j] == '
            for y, x in zip(dh, dw):
                if 0 <= i+y < h and 0 <= j+x < w:
                    if s[i+y][j+x] == '
                        break
            else:
                break
    else:
        continue
    print('No')
    break
else:
    print('Yes')

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

can_draw = True

for i in range(h):
    for j in range(w):
        if s_input[i][j] == '
            if i - 1 >= 0:
                if s_input[i - 1][j] == '
                    
                    continue
            if j - 1 >= 0:
                if s_input[i][j - 1] == '
                    
                    continue
            if j + 1 < w:
                if s_input[i][j + 1] == '
                    
                    continue
            if i + 1 < h:
                if s_input[i + 1][j] == '
                    
                    continue
            can_draw = False
            break
    if not can_draw:
        break

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

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

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

print("Yes")

Solution (Python):

import sys
import math
import os
import itertools

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]

class Util():
    def round_up(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x

H,W = cin.mapInt()
S = cin.stringList(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 w - 1 >= 0 and S[h][w - 1] == "
            continue
        if h + 1 < H and S[h + 1][w] == "
            continue
        if w + 1 < W and S[h][w + 1] == "
            continue
        print("No")
        sys.exit()
print("Yes")

Solution (Python):
H,W=map(int,input().split())
graph=[list(input()) for _ in range(H)]
onesteps=((-1,0),(0,-1),(1,0),(0,1))
for x in range(H):
    for y in range(W):
        if graph[x][y]=="
            flag=0
            for dx,dy in onesteps:
                if (0<=x+dx<H) and (0<=y+dy<W):
                    if graph[x+dx][y+dy]=="
                        flag+=1
            if flag==0:
                print('No')
                exit(0)
print('Yes')

Solution (Python):
h,w = map(int,input().split())
s = [list("."+input()+".") for _ in range(h)]
s=["."*(w+2)]+s+["."*(w+2)]
flg = 0
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]==".":
        flg = 1
print("Yes" if flg == 0 else "No")

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

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

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


fill_l = []
for i in range(-1,h+1):
    if i == -1 or i == h:
        fill_l.append(['?' for _ in range(w+2)])
    else:
        ext = ['?']
        ext.extend(l[i])
        ext.append('?')
        fill_l.append(ext)
        
flg = True
for i in range(1,h):
    for j in range(1,w):
        if fill_l[i][j] == '
            flg = False
            break
        
print('Yes' if flg else 'No')

Solution (Python):
def main():
    
    dyx = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if "." == s[y][x]:
                continue
            for dy, dx in dyx:
                if "
                    break
            else:
                print("No")
                return
    print("Yes")
    return


main()

Solution (Python):
def main():
    
    dyx = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s.extend(["." + input() + "." for i in range(H)])
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if "." == s[y][x]:
                continue
            for dy, dx in dyx:
                if "
                    break
            else:
                print("No")
                return
    print("Yes")
    return


main()

Solution (Python):
def main():
    
    dyx = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s += ["." * (W + 2)]
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if "." == s[y][x]:
                continue
            for dy, dx in dyx:
                if "
                    break
            else:
                print("No")
                return
    print("Yes")
    return


main()

Solution (Python):
def main():
    
    dy = (1, 0, -1, 0)
    dx = (0, 1, 0, -1)
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s += ["." * (W + 2)]
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if "." == s[y][x]:
                continue
            if "
                continue
            if "
                continue
            if "
                continue
            if "
                continue
            print("No")
            return
    print("Yes")
    return


main()

Solution (Python):
def main():
    
    dyx = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if "." == s[y][x]:
                continue
            for dy, dx in dyx:
                if "
                    break
            else:
                print("No")
                return
    print("Yes")
    return


main()

Solution (Python):
def main():
    
    dy = (1, 0, -1, 0)
    dx = (0, 1, 0, -1)
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if "." == s[y][x]:
                continue
            if "
                continue
            if "
                continue
            if "
                continue
            if "
                continue
            print("No")
            return
    print("Yes")
    return


main()

Solution (Python):
def main():
    
    dy = [1, 0, -1, 0]
    dx = [0, 1, 0, -1]
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if "." == s[y][x]:
                continue
            if "
                continue
            if "
                continue
            if "
                continue
            if "
                continue
            print("No")
            return
    print("Yes")
    return


main()

Solution (Python):
def main():
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if "." == s[y][x]:
                continue
            if "
                continue
            if "
                continue
            if "
                continue
            if "
                continue

            print("No")
            return
    print("Yes")
    return


main()

Solution (Python):
def main():
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if s[y][x] == ".":
                continue
            if "...." == s[y + 1][x]\
                    + s[y][x + 1]\
                    + s[y - 1][x]\
                    + s[y][x - 1]:
                print("No")
                return
    print("Yes")
    return


main()

Solution (Python):
def main():
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if s[y][x] == ".":
                continue
            if "." == s[y + 1][x]\
                    == s[y][x + 1]\
                    == s[y - 1][x]\
                    == s[y][x - 1]:
                print("No")
                return
    print("Yes")
    return


main()

Solution (Python):
def main():
    
    dyx = ((1, 0), (0, 1), (-1, 0), (0, -1))
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if s[y][x] == ".":
                continue
            if "." == s[y + dyx[0][0]][x + dyx[0][1]]\
                    == s[y + dyx[1][0]][x + dyx[1][1]]\
                    == s[y + dyx[2][0]][x + dyx[2][1]]\
                    == s[y + dyx[3][0]][x + dyx[3][1]]:
                print("No")
                return
    print("Yes")
    return


main()

Solution (Python):
def main():
    
    dy = [1, 0, -1, 0]
    dx = [0, 1, 0, -1]
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if s[y][x] == ".":
                continue
            elif "." == s[y + dy[0]][x + dx[0]]\
                    == s[y + dy[1]][x + dx[1]]\
                    == s[y + dy[2]][x + dx[2]]\
                    == s[y + dy[3]][x + dx[3]]:
                print("No")
                return
    print("Yes")
    return


main()

Solution (Python):
def main():
    
    dy = [1, 0, -1, 0]
    dx = [0, 1, 0, -1]
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if s[y][x] == ".":
                continue
            if "." == s[y + dy[0]][x + dx[0]]\
                    == s[y + dy[1]][x + dx[1]]\
                    == s[y + dy[2]][x + dx[2]]\
                    == s[y + dy[3]][x + dx[3]]:
                print("No")
                return
    print("Yes")
    return


main()

Solution (Python):
def main():
    
    dy = (1, 0, -1, 0)
    dx = (0, 1, 0, -1)
    H, W, *s = open(0).read().split()
    H = int(H)
    W = int(W)
    s = ["." + si + "." for si in s]
    s.insert(0, "." * (W + 2))
    s.insert(-1, "." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if s[y][x] == "
                    "." == s[y + dy[0]][x + dx[0]]\
                    == s[y + dy[1]][x + dx[1]]\
                    == s[y + dy[2]][x + dx[2]]\
                    == s[y + dy[3]][x + dx[3]]:
                print("No")
                return
    print("Yes")
    return


main()

Solution (Python):
def main():
    
    dy = (1, 0, -1, 0)
    dx = (0, 1, 0, -1)
    H, W = map(int, input().split())
    s = ("." * (W + 2),)
    for i in range(H):
        s += ("." + input() + ".",)
    s += ("." * (W + 2),)
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if s[y][x] == "
                    "." == s[y + dy[0]][x + dx[0]]\
                    == s[y + dy[1]][x + dx[1]]\
                    == s[y + dy[2]][x + dx[2]]\
                    == s[y + dy[3]][x + dx[3]]:
                print("No")
                return
    print("Yes")
    return


main()

Solution (Python):
def main():
    
    dy = (1, 0, -1, 0)
    dx = (0, 1, 0, -1)
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if s[y][x] == "
                    "." == s[y + dy[0]][x + dx[0]]\
                    == s[y + dy[1]][x + dx[1]]\
                    == s[y + dy[2]][x + dx[2]]\
                    == s[y + dy[3]][x + dx[3]]:
                print("No")
                return
    print("Yes")
    return


main()

Solution (Python):
def main():
    
    dy = (1, 0, -1, 0)
    dx = (0, 1, 0, -1)
    H, W = map(int, input().split())
    dot = "." * (W + 2)
    s = [dot]
    s += ["." + input() + "." for i in range(H)]
    s.append(dot)
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if s[y][x] == "
                    "." == s[y + dy[0]][x + dx[0]]\
                    == s[y + dy[1]][x + dx[1]]\
                    == s[y + dy[2]][x + dx[2]]\
                    == s[y + dy[3]][x + dx[3]]:
                print("No")
                return
    print("Yes")
    return


main()

Solution (Python):
def main():
    
    dy = [1, 0, -1, 0]
    dx = [0, 1, 0, -1]
    H, W = map(int, input().split())
    dot = "." * (W + 2)
    s = [dot]
    s += ["." + input() + "." for i in range(H)]
    s.append(dot)
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if s[y][x] == "
                    "." == s[y + dy[0]][x + dx[0]]\
                    == s[y + dy[1]][x + dx[1]]\
                    == s[y + dy[2]][x + dx[2]]\
                    == s[y + dy[3]][x + dx[3]]:
                print("No")
                return
    print("Yes")
    return


main()

Solution (Python):
def main():
    
    dy = [1, 0, -1, 0]
    dx = [0, 1, 0, -1]
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if s[y][x] == "
                    "." == s[y + dy[0]][x + dx[0]]\
                    == s[y + dy[1]][x + dx[1]]\
                    == s[y + dy[2]][x + dx[2]]\
                    == s[y + dy[3]][x + dx[3]]:
                print("No")
                return
    print("Yes")
    return


main()

Solution (Python):
def main():
    
    dy = [1, 0, -1, 0]
    dx = [0, 1, 0, -1]
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s.extend(["." + input() + "." for i in range(H)])
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if s[y][x] == "
                    and s[y + dy[1]][x + dx[1]] == "."\
                    and s[y + dy[2]][x + dx[2]] == "."\
                    and s[y + dy[3]][x + dx[3]] == ".":
                print("No")
                return
    print("Yes")
    return


main()

Solution (Python):
def main():
    
    dy = [1, 0, -1, 0]
    dx = [0, 1, 0, -1]
    H, W = map(int, input().split())
    s = ["." * (W + 2)]
    s += ["." + input() + "." for i in range(H)]
    s.append("." * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if s[y][x] == "
                    and s[y + dy[1]][x + dx[1]] == "."\
                    and s[y + dy[2]][x + dx[2]] == "."\
                    and s[y + dy[3]][x + dx[3]] == ".":
                print("No")
                return
    print("Yes")
    return


main()

Solution (Python):
def main():
    
    dy = [1, 0, -1, 0]
    dx = [0, 1, 0, -1]
    H, W = map(int, input().split())
    s = [["."] * (W + 2)]
    s += [["."] + list(input()) + ["."] for i in range(H)]
    s.append(["."] * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if s[y][x] == "
                    and s[y + dy[1]][x + dx[1]] == "."\
                    and s[y + dy[2]][x + dx[2]] == "."\
                    and s[y + dy[3]][x + dx[3]] == ".":
                print("No")
                return
    print("Yes")
    return


main()

Solution (Python):
def main():
    
    dy = [1, 0, -1, 0]
    dx = [0, 1, 0, -1]
    H, W = map(int, input().split())
    s = [["."] * (W + 2)]
    s.extend([["."] + list(input()) + ["."] for i in range(H)])
    s.append(["."] * (W + 2))
    for y in range(1, H + 1):
        for x in range(1, W + 1):
            if s[y][x] == "
                    and s[y + dy[1]][x + dx[1]] == "."\
                    and s[y + dy[2]][x + dx[2]] == "."\
                    and s[y + dy[3]][x + dx[3]] == ".":
                print("No")
                return
    print("Yes")
    return


main()

Solution (Python):
def main():
    
    dy = [1, 0, -1, 0]
    dx = [0, 1, 0, -1]
    H, W = map(int, input().split())
    s = [input() for i in range(H)]
    for y in range(H):
        for x in range(W):
            if s[y][x] == '.':
                continue
            cnt = 0
            for i, j in zip(dy, dx):
                ny = y + i
                nx = x + j
                if ny < 0 or H <= ny\
                        or nx < 0 or W <= nx\
                        or s[ny][nx] == '.':
                    continue
                cnt += 1
            if cnt == 0:
                print("No")
                return
    print("Yes")
    return


main()

Solution (Python):

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

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


def main():
    for y in range(H):
        for x in range(W):

            if s[y][x] == '.':
                continue

            cnt = 0

            for i, j in zip(dy, dx):
                ny = y + i
                nx = x + j

                if ny < 0 or H <= ny\
                        or nx < 0 or W <= nx\
                        or s[ny][nx] == '.':
                    continue

                cnt += 1

            if cnt == 0:
                print("No")
                return

    print("Yes")
    return


main()

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

ans = 'Yes'
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]

for i in range(1, h+1):
   for j in range(1, w+1):
      if (s[i][j] == '
         ok = False
         for k in range(4):
            if (s[i+dx[k]][j+dy[k]] == '
               ok = True
         if not ok:
            ans = 'No'

print(ans)

Solution (Python):
def paint(s, i, j):
    check = 0
    for jj in range(-1,2,2):
        if s[i][j+jj] == "
            check += 1
    for ii in range(-1,2,2):
        if s[i+ii][j] == "
            check += 1

    return check

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][j] == "
            if paint(s, i, j) == 0:
                print("No")
                exit()
print("Yes")

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    H, W = [int(x) for x in input().split()]

    s = []
    s.append(['.' for i in range(W + 2)])
    for _ in range(H):
        S = input().strip()
        s.append(list('.' + S + '.'))

    s.append(['.' for i in range(W + 2)])

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

    print("Yes")


if __name__ == '__main__':
    main()