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):
import numpy as np
import sys

h, w = map(int, sys.stdin.readline().strip().split(" "))

a = np.zeros((h,w), dtype=int)

for i in range(h):
    l = sys.stdin.readline().strip()
    for j in range(w):
        a[i, j] = (l[j] == "

for i in range(h):
    for j in range(w):
        if a[i, j] == 0:
            continue
        check = True
        if i >= 1:
            check &= a[i-1, j] == 0
        if i < h-1:
            check &= a[i+1, j] == 0
        if j >= 1:
            check &= a[i, j-1] == 0
        if j < w-1:
            check &= a[i, j+1] == 0
        if check:
            print("No")
            quit()
print("Yes")

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

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

for i in range(H):
    for j in range(W):
        if grids[i][j] == '.':
            continue

        if i == 0 and j == 0:
            if grids[i][j + 1] == '.' and grids[i + 1][j] == '.':
                print("No")
                exit()

        elif i == 0 and j == W - 1:
            if grids[i][j - 1] == '.' and grids[i + 1][j] == '.':
                print("No")
                exit()

        elif i == 0:
            if grids[i][j - 1] == '.' and grids[i][j + 1] == '.' and grids[i + 1][j] == '.':
                    print("No")
                    exit()

        elif i == H - 1 and j == 0:
            if grids[i][j + 1] == '.' and grids[i - 1][j] == '.':
                print("No")
                exit()

        elif i == H - 1 and j == W - 1:
            if grids[i][j - 1] == '.' and grids[i - 1][j] == '.':
                print("No")
                exit()

        elif i == H - 1:
            if grids[i][j - 1] == '.' and grids[i][j + 1] == '.' and grids[i - 1][j] == '.':
                print("No")
                exit()

        elif j == 0:
            if grids[i - 1][j] == '.' and grids[i][j + 1] == '.' and grids[i + 1][j] == '.':
                    print("No")
                    exit()

        elif j == W - 1:
            if grids[i - 1][j] == '.' and grids[i][j - 1] == '.' and grids[i + 1][j] == '.':
                    print("No")
                    exit()

        else:
            if grids[i - 1][j] == '.' and grids[i + 1][j] == '.' and grids[i][j - 1] == '.' and grids[i][j + 1] == '.':
                    print("No")
                    exit()

print("Yes")

Solution (Python):
def c_grid_repainting(H, W, Grid):
    is_visited = [[False] * W for h in range(H)]
    delta = [(-1, 0), (1, 0), (0, -1), (0, 1)]  

    def bfs(r, c):
        if Grid[r][c] == '.':
            return
        if is_visited[r][c]:
            return
        q = [(r, c)]
        while q:
            h, w = q.pop()
            for dh, dw in delta:
                nh, nw = h + dh, w + dw
                if 0 <= nh < H and 0 <= nw < W and Grid[nh][nw] == '
                    is_visited[r][c] = True
                    is_visited[nh][nw] = True
                    q.insert(0, (nh, nw))
    for h in range(H):
        for w in range(W):
            bfs(h, w)
    for h in range(H):
        for w in range(W):
            if Grid[h][w] == '
                return 'No'
    return 'Yes'

H,W = [int(i) for i in input().split()]
Grid = [input().strip() for _ in range(H)]
print(c_grid_repainting(H, W, Grid))

Solution (Python):






li = list()

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

flag = False

def isField(i, j):
    if i >= 0 and j >= 0 and i < h and j < w:
        return True
    else:
        False

for i in xrange(h):
    a = list(raw_input())
    li.append(a)

for (i,hh) in enumerate(li):
    for (j,ww) in enumerate(hh):
        flag = False
        if ww == "
            if isField(i-1, j):
                if li[i-1][j] == "
                    flag = True
            if isField(i, j-1):
                if li[i][j-1] == "
                    flag = True
            if isField(i+1, j):
                if li[i+1][j] == "
                    flag = True
            if isField(i, j+1):
                if li[i][j+1] == "
                    flag = True
            if flag == False:
                print "No"
                exit(0)
print "Yes"

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

h, w = list(map(int, input().split()))
g = [['.']*(w+2)]
g += [['.'] + list(input()) + ['.'] for i in range(h)]
g.append(['.']*(w+2))

if solve(g):
    print('Yes')
else:
    print('No')

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


def able_black(line, row):
    if data[line][row] == '.':
        return True
    else:
        for dx in range(-1, 2):
            for dy in range(-1, 2):
                if 0 <= line+dx <= h-1 and 0 <= row+dy <= w-1 and not ((dx == 0 and dy == 0) or (abs(dx) == 1 and abs(dy) == 1)):
                    if data[line+dx][row+dy] == '
                        return True
        return False


for i in range(h):
    for j in range(w):
        if not able_black(i, j):
            print('No')
            exit()
print('Yes')

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

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

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

print("Yes")

Solution (Python):
def main():
  H, W = [int(i) for i in input().split()]
  matrix = [input() for i in range(H)]
  for i in range(H):
    for j in range(W):
      if matrix[i][j] == '
        neighbors = [
          matrix[i-1][j] if i > 0 else '.',
          matrix[i+1][j] if i < H-1 else '.',
          matrix[i][j-1] if j > 0 else '.',
          matrix[i][j+1] if j < W-1 else '.',
        ]
        if '
          print('No')
          return
  print('Yes')

main()

Solution (Python):
import sys
H, W = [int(i) for i in input().split(" ")]
board = [["0" for w in range(W+2)] for h in range(H+2)]

for h in range(H):
    tmp = list(input())
    for w in range(W):
        board[h+1][w+1] = tmp[w]

def printBoard():
    for h in range(H+2):
        for w in range(W+2):
            sys.stdout.write(board[h][w])
            sys.stdout.write(" ")
        sys.stdout.write("\n")

def check(h,w):
    if board[h][w-1] == "
        return True
    if board[h][w+1] == "
        return True
    if board[h-1][w] == "
        return True
    if board[h+1][w] == "
        return True
    return False

def solve():
    flag = True
    for h in range(1, H+1):
        for w in range(1, W+1):
            if board[h][w] == "
                flag = check(h, w)
            else:
                pass
            if not flag:
                return flag
    return flag

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

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

Solution (Python):
h, w = map(int, input().split())
masu = [[0 for x in range(w)] for y in range(h)]
for y in range(0, h):
    z = list(input())
    for x in range(0, w):
        masu[y][x] = z[x]
hantei = "Yes"
for y in range(0, h):
    for x in range(0, w):
        if (masu[y][x] == "
            if (not((y > 0 and masu[y - 1][x] == "
                hantei = "No"
print (hantei)

Solution (Python):
H, W = map(int, input().split(' '))
matrix = []
for _ in range(H):
    tmp = [0 if j == '.' else 1 for j in input()]
    matrix.append(tmp)

flag = 'Yes'
for i, row in enumerate(matrix):
    for j, s in enumerate(row):
        if s == 1:
            if (j > 0 and row[j-1] == 0) and (j < W - 1 and row[j+1] == 0):
                if (i > 0 and matrix[i-1][j] == 0) and (i < H - 1 and matrix[i+1][j] == 0):
                    flag = 'No'
                    break

print(flag)

Solution (Python):
uu = list(map(int,input().split()))
h = uu[0]
w = uu[1]
arr = []
for i in range(0, h):
    arr.append(list(map(lambda x: x == "
res = True
for i in range(0, (h - 1)):
    for j in range (0, (w - 1)):
        if arr[i][j]:
            if not(arr[i + 1][j] or arr[i][j + 1] or arr[i - 1][j] or arr[i][j - 1]):
                res = False
                break
    if not res:
        break
if res:
    print("Yes")
else:
    print("No")

Solution (Python):


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

b=['.'*(w+2)]
for _ in range(h):
    b.append('.'+input()+'.')
b.append('.'*(w+2))


ok = 1
for i in range(1,h+1):
    for j in range(1,w+1):

        if b[i][j] == '
            ok=0
            break
    if ok==0:
        break

if ok==1:
    print('Yes')
else:
    print('No')

Solution (Python):
s = list(map(int, input().split()))
n, m = int(s[0]), int(s[1])
cl = []
for i in range(n):
  cl.append(input())
  
for i in range(n):
  for j in range(m):
    if cl[i][j]=='
      st = False
      if i>0 and cl[i-1][j]=='
        st = True
        continue
      elif i<n-1 and cl[i+1][j]=='
        st = True
        continue
      elif j>0 and cl[i][j-1]=='
        st = True
        continue
      elif j<m-1 and cl[i][j+1]=='
        st = True
        continue
      if st:
        continue
      else:
        print('No')
        exit()

print('Yes')

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

def check(x, y, board, h, w):
  if x > 0:
    if board[x-1][y] == '
      return True

  if y > 0:
    if board[x][y-1] == '
      return True

  if y != w-1:
    if board[x][y+1] == '
      return True

  if x != h-1:
    if board[x+1][y] == '
      return True

  return False

board = []
answer = 'Yes'

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

for i in range(h):
  for j in range(w):
    if board[i][j] == '
      if check(i, j, board, h, w) == False:
        answer = 'No'

print(answer)

Solution (Python):
h, w = map(int, input().split())
a = [[i for i in input()] for j in range(h)]
for i in range(h):
  a[i].insert(0,'.')
  a[i].append('.')
b = ['.' for i in range(w+2)]
a.insert(0, b)
a.append(b)
flag = 0
for i in range(h):
  for j in range(w):
    if a[i][j] == '
      if a[i-1][j] == '.' and a[i+1][j] == '.' and a[i][j-1] == '.' and a[i][j+1] == '.':
        flag = 1
        break
  if flag == 1:
    print('No')
    exit()
print('Yes')

Solution (Python):
def main():
    H, W = map(int, input().split())
    S = tuple(input() for _ in [0] * H)

    grid = ['.' * (W + 2)]
    apnd = grid.append
    for s in S:
        apnd('.' + s + '.')
    apnd('.' * (W + 2))

    for i in range(1, H + 2):
        idx = [i for i, s in enumerate(grid[i]) if s == '
        for j in idx:
            if grid[i-1][j] == grid[i+1][j] == grid[i][j-1] == grid[i][j+1] == '.':
                print('No')
                return
    print('Yes')

main()

Solution (Python):
h,w = map(int,input().split())
A = []
A.append('.'*(w+2))
for _ in range(h):
    A.append('.'+input()+'.')
A.append('.' * (w+2))
flag = 0

for i in range(h+2):
    for j in range(w+2):
        if A[i][j] == '
            if A[i][j -1] == '.' and A[i][j + 1] == '.' and A[i-1][j] == '.' and A[i+1][j] == '.':
                flag = 1
if flag == 0:
    print('Yes')
else:
    print('No')

Solution (Python):

N = list(map(int, input().split()))
x = [input() for i in range(N[0])]
xi=[]
cnt=0

for i in x:
    
    xi.append([])
    for j in i:

        if j=='.':
            xi[cnt].append(0)
        else:
            xi[cnt].append(1)
    cnt+=1


for i in range(N[0]):
    for j in range(N[1]):
        if xi[i][j]==0:
            continue
        if i!=0 and j!=0 and i!=N[0]-1 and j!=N[1]-1 :
            xi[i][j]+=xi[i+1][j]+xi[i-1][j]+xi[i][j+1]+xi[i][j-1]
        if i==0 and j!=0 and i!=N[0]-1 and j!=N[1]-1 :
            xi[i][j]+=xi[i+1][j]+xi[i][j+1]+xi[i][j-1]
        if i!=0 and j!=0 and i==N[0]-1 and j!=N[1]-1 :
            xi[i][j]+=xi[i-1][j]+xi[i][j+1]+xi[i][j-1]      
        if i!=0 and j==0 and i!=N[0]-1 and j!=N[1]-1 :
            xi[i][j]+=xi[i+1][j]+xi[i-1][j]+xi[i][j+1]
        if i!=0 and j!=0 and i!=N[0]-1 and j==N[1]-1 :
            xi[i][j]+=xi[i+1][j]+xi[i-1][j]+xi[i][j-1]

        if i==0 and j==0 and i!=N[0]-1 and j!=N[1]-1 :
            xi[i][j]+=xi[i+1][j]+xi[i][j+1]
        if i!=0 and j==0 and i==N[0]-1 and j!=N[1]-1 :
            xi[i][j]+=xi[i-1][j]+xi[i][j+1]
        if i==0 and j!=0 and i!=N[0]-1 and j==N[1]-1 :
            xi[i][j]+=xi[i+1][j]+xi[i][j-1]
        if i!=0 and j!=0 and i==N[0]-1 and j==N[1]-1 :
            xi[i][j]+=xi[i-1][j]+xi[i][j-1]


for i in range(N[0]):
    for j in range(N[1]):
        if xi[i][j]==1:
            print('No')
            quit()

print('Yes')

Solution (Python):
h,w=map(int,input().split())
canvas=['.'+input()+'.'  for i in range(h)]
canvas.append('
canvas.insert(0,'

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

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

cnt = 0
for i in range(h):
    cnt += s[i].count('
if cnt == 0:
    print('Yes')
    exit()

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

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

Solution (Python):
a= input()
a=a.rstrip().split(" ")
tate = a[0]
yoko = a[1]

e =[]
for i in range(int(tate)):
    b=input()
    e.append(b)

era=0
for j in range(int(tate)):
    
    for k in range(int(yoko)):
        if e[j][k]==".":
            k +=1
        elif e[j][k]=="
            if k>1 and k<int(yoko)-1 and j>1 and j<int(tate)-1:
                if e[j-1][k]=="
                    k +=1
                else:
                    era = era+1
                    k +=1
            elif k==0 and j>1 and j<int(tate)-1:
                if e[j-1][k]=="
                    k +=1
                else:
                    era = era+1
                    k +=1
            elif k==int(yoko)-1 and j>1 and j<int(tate)-1:
                if e[j-1][k]=="
                    k +=1
                else:
                    era = era+1
                    k +=1
            elif j==0 and k>1 and k<int(tate)-1:
                if e[j+1][k]=="
                    k +=1
                else:
                    era = era+1
                    k +=1
            elif j==int(tate)-1 and k>1 and k<int(yoko)-1:
                if e[j-1][k]=="
                    k +=1
                else:
                    era = era+1
                    k +=1
if era ==0:
    print("Yes")
elif era >=1:
    print("No")

Solution (Python):
from itertools import product

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

for i in range(h):
    slili[i].insert(0,'.')
    slili[i].append('.')

slili.insert(0,['.']*(w+1))
slili.append(['.']*(w+1))


def srinsetsu(i,j):
    if slili[i][j] == '.':
        return True
    elif slili[i-1][j]=='
        return True
    else: 
        False

ans = True
for i,j in product(range(1,h+1) , range (1,w+1)):
    ans = ans and srinsetsu(i,j)

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

Solution (Python):


import numpy as np

h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == '
            s[i][j] = 1
        else:
            s[i][j] = 0

no_flg = 0
s = np.array(s)
for i in range(h):
    for j in range(w):
        check = []
        if s[i, j] != 0:
            if i != 0:
                if s[i-1, j] == 1:
                    check.append(1)
            if j != 0:
                if s[i, j-1] == 1:
                    check.append(1)
            if i != h-1:
                if s[i+1, j] == 1:
                    check.append(1)
            if j != w-1:
                if s[i, j+1] == 1:
                    check.append(1)
            if sum(check) == 0:
                no_flg = 1
                break

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

Solution (Python):
H, W = list(map(int, input().split(' ')))
import numpy as np
import sys
grid = np.zeros((H, W))
for h in range(H):
  grid[h,:] = [0 if g == '.' else 1 for g in input()]
  

for h in range(H):
  for w in range(W):
    if grid[h, w] == 0:
      continue
    
    around = []
    if h > 0:
      around.append(grid[h-1, w])
    if w > 0:
      around.append(grid[h, w-1])
    if h < H-1:
      around.append(grid[h+1, w])
    if w < W-1:
      around.append(grid[h, w+1])
    if 1 in around:
      pass
    else:
      
      print('No')
      sys.exit()
print('Yes')

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

for i in range(H):
    s[i].append(".")
    s[i].insert(0,".")

add_list = ["." for _ in range(W+2)]
s.append(add_list)
s.insert(0,add_list)

Flag = "Yes"

for i in range(H):
    for j in range(W):
        if (s[i][j]=="
            Flag = "No"
            break
print(Flag)

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

Solution (Python):
def solve(table, H, W):
    def is_ok(row, col):
        if not table[row][col]:
            return True

        if row > 0 and table[row - 1][col] or row + 1 < H and table[row + 1][col]:
            return True
        if col > 0 and table[row][col - 1] or col + 1 < W and table[row][col + 1]:
            return True
        return False

    for row in range(H):
        for col in range(W):
            if not is_ok(row, col):
                return False
    return True


H, W = map(int, input().split())
table = []
for r in range(H):
    table.append(list(map(lambda x: x == "

print("Yes" if solve(table, H, W) else "No")

Solution (Python):
import sys

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


def judge_black(y, x):
    if 0 <= y - 1 < H:
        if s_list[y - 1][x] == '
            return True
    if 0 <= x - 1 < W:
        if s_list[y][x - 1] == '
            return True
    if 0 <= x + 1 < W:
        if s_list[y][x + 1] == '
            return True
    if 0 <= y + 1 < H:
        if s_list[y + 1][x] == '
            return True
    return False


for i in range(H):
    for j in range(W):
        if s_list[i][j] == '
            if judge_black(i, j) is False:
                print('No')
                sys.exit()
print('Yes')

Solution (Python):
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
dx = [0, 1, 0, -1]
dy = [-1, 0, 1, 0]
s.insert(0, ['
s.append(['

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

for i in range(1, h+1):
    for j in range(1, w+1):
        b = 0
        for k in range(4):
            if s[i+dy[k]][j+dx[k]] == '
        if b == 0 and s[i][j] == '
            print('No')
            exit()
print('Yes')

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

for h in range(H):
    for w in range(W):
        if grid[h][w] == ".":
            continue

        nearby_sharp_counter = 0

        for a, b in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
            if h+a < 0 or h+a >= H or w+b < 0 or w+b >= W:
                continue
            elif grid[h+a][w+b] == "
                nearby_sharp_counter += 1
        
        if nearby_sharp_counter == 0:
            print("No")
            exit()

print("Yes")

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

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


def is_exits(row, col):

    for i in range(len(dx)):
        n_row = dy[i] + row
        n_col = dx[i] + col
        if (n_row >= 0 and n_row <= h-1) and (n_col >= 0 and n_col <= w-1):
            if s[n_row][n_col] == "

                return True
        else:
            continue
    return False


for row in range(h):
    
    for col in range(w):

        if s[row][col] == "
            if is_exits(row, col):
                continue
            else:
                f = False
                break


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

Solution (Python):
from sys import stdin


def main():
    H, W = [int(x) for x in stdin.readline().rstrip().split()]
    s = [list(stdin.readline().rstrip()) for _ in range(H)]
    for h in range(H):
        for w in range(W):
            if s[h][w] == '.':
                continue
            idxs = [(h - 1, w), (h, w - 1), (h, w + 1), (h + 1, w)]
            for i, j in idxs:
                if (0 <= i < H) and (0 <= j < W) and (s[i][j] == '
                    break
            else:
                print('No')
                return
    print('Yes')


if __name__ == '__main__':
    main()

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

cnt = 0

if H >= 2 and W >= 3:
	if s[0][0] == "
		cnt += 1

	for w in range(1, W - 1):
		if s[0][w] == "
			cnt += 1

	if s[0][W - 1] == "
		cnt += 1 

	if H >= 3:
		for h in range(1, H - 1):
			if s[h][0] == "
				cnt += 1

			for w in range(1, W - 1):
				if s[h][w] == "
					cnt += 1

			if s[h][W - 1] == "
				cnt += 1 

	if s[H - 1][0] == "
		cnt += 1

	for w in range(1, W - 1):
		if s[H - 1][w] == "
			cnt += 1

	if s[H - 1][W - 1] == "
		cnt += 1

elif H == 1:
	if s[0][0] == "
		cnt += 1

	for w in range(1, W - 1):
		if s[0][w] == "
			cnt += 1

	if s[0][W - 1] == "
		cnt += 1

elif W == 1:
	if s[0][0] == "
		cnt += 1

	for h in range(1, H - 1):
		if s[h][0] == "
			cnt += 1

	if s[H - 1][0] == "
		cnt += 1

else: 
	if s[0][0] == "
		cnt += 1

	if s[0][1] == "
		cnt += 1

	if H >= 3:
		for h in range(1, H - 1):
			if s[h][0] == "
				cnt += 1

			if s[h][1] == "
				cnt += 1 

	if s[1][0] == "
		cnt += 1

	if s[1][1] == "
		cnt += 1


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

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

h,w = map(int, input().split())
board = []
for _ in range(h):
    s = input()
    board.append(list(s))
ans = 'Yes'
for i in range(h):
    for j in range(w):
        if board[i][j] == '.': continue
        adj = 0
        for k in range(4):
            yy = i+dy[k]
            xx = j+dx[k]
            if yy < 0 or yy > h-1: continue
            if xx < 0 or xx > w-1: continue
            if board[yy][xx] == '
        if adj == 0: ans = 'No'
print(ans)

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

s = []
s.append(["."]*(W+2))

for _ in range(H):
    a = [i for i in input()]
    a.append(".")
    a.insert(0, ".")
    s.append(a)
s.append(["."]*(W+2))

flg = 0
for i in range(1, W):
    for j in range(1, H):
        if s[j][i] == "
            if s[j-1][i] == "." and s[j+1][i] == "." and s[j][i-1] == "." and s[j][i+1] == ".":
                flg = 1
                break
print("Yes" if flg == 0 else "No")

Solution (Python):
import sys
sys.setrecursionlimit(100000)
h,w = map(int,input().split())
lst = []
for i in range(h):
  lst.append([s for s in input()])
def dfs(x,y):
  if lst[x][y] == '
    lst[x][y] = '.'
    if x + 1 <= h - 1:
      dfs(x + 1,y)
    if x - 1 >= 0:
      dfs(x - 1,y)
    if y + 1 <= w - 1:
      dfs(x, y + 1)
    if y - 1 >= 0:
      dfs(x,y - 1)
flag = True
for i in range(h):
  for j in range(w):
    if lst[i][j] == '
      if (i - 1 >= 0 and lst[i - 1][j] == "
        dfs(i,j)
      else:
        flag = False
        break
if flag:
  print("Yes")
else:
  print("No")

Solution (Python):
Tmp = []
Tmp = input().rstrip().split(' ')

H = int(Tmp[0])
W = int(Tmp[1])
Data =  [[0 for i in range(W)]for j in range(H)]
N = []

for j in range(H):
    N = input()
    for i in range(W):
        if N[i]=='
            Data[j][i] = 1
        else:
            Data[j][i] = 0

Chk = 0
Flag = 0 
for j in range(H):
    for i in range(W):
        nTmp = Data[j][i]
        if nTmp == 1:
            Chk = 1
            if i > 0:
                if Data[j][i - 1]==1:
                    Chk = 0
            if j > 0:
                if Data[j - 1][i]==1:
                    Chk = 0
            if i < W - 1:
                if Data[j][i + 1]==1:
                    Chk = 0
            if j < H - 1:
                if Data[j + 1][i]==1:
                    Chk = 0
            
            if Chk == 1:
                Flag = 1
        
        if Flag ==1:
            break
    if Flag ==1:
        break

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

Solution (Python):
import sys,collections,math;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

H,W = Is()
mat = ["."*(W+2)]
for i in range(H):
    mat.append("." + S() + ".")
mat.append("."*(W+2))
for h in range(1,H+1):
    for w in range(1,W+1):
        t = mat[h][w]
        if t == "
            print("No")
            exit()
print("Yes")

Solution (Python):
H, W = (int(i) for i in input().split())

inp = [[_ for _ in input().strip()] for i in range(H)]

for i in inp:
    i.insert(0, ".")
    i.append(".")
a = ["." for _ in range(W+2)]
inp.append(a)
inp.insert(0, a)

for h in range(H):
    for w in range(W):
        if(inp[h][w] == "
            if inp[h+1][w] == "." and \
                    inp[h][w+1] == "." and \
                    inp[h-1][w] == "." and \
                    inp[h][w-1] == ".":
                print("No")
                exit(0)
print("Yes")

Solution (Python):
import re

inp = re.split(" ",input())
max_i = int(inp[0])
max_j = int(inp[1])

field = []
calcfield = []

for i in range(max_i):
    inp = input()
    field.append([])
    calcfield.append([])
    for j in range(max_j):
        field[i].append(inp[j])
        calcfield[i].append('.')


for i in range(max_i):
    for j in range(max_j):
        if field[i][j] == '
            if i > 0 and field[i-1][j] == '
                calcfield[i][j] = '
                calcfield[i-1][j] = '
            elif i+1 < max_i and field[i+1][j] == '
                calcfield[i][j] = '
                calcfield[i+1][j] = '
            elif j > 0 and field[i][j-1] == '
                calcfield[i][j] = '
                calcfield[i][j-1] = '
            elif j+1 < max_j and field[i][j+1] == '
                calcfield[i][j] = '
                calcfield[i][j+1] = '

if field==calcfield:
    print("Yes")
else:
    print("No")

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

def check(y, x):
    if s[y][x] == "
        for i, j in dir:
            try:
                if s[y+i][x+j] == "
                    return True
            except:
                pass
        else:
            return False
    return True
def solve():
    for y in range(H):
        for x in range(W):
            if not check(y, x):
                return False
    return True

def main():
    if solve():
        print("Yes")
    else:
        print("No")

main()

Solution (Python):
import math
import random
import heapq
from collections import Counter, defaultdict
from decimal import Decimal, ROUND_HALF_UP, ROUND_CEILING
from functools import lru_cache, reduce
from itertools import combinations_with_replacement, product, combinations


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def mt(f):
    import time
    import sys

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        print(e - s, 'sec', file=sys.stderr)
        return ret

    return wrap


@mt
def slv(H, W, M):
    def ok(i, j):
        f = False
        if i > 0 and M[i - 1][j] == '
            f = True
        if i < H - 1 and M[i + 1][j] == '
            f = True

        if j > 0 and M[i][j - 1] == '
            f = True

        if j < W - 1 and M[i][j + 1] == '
            f = True
        return f

    for i in range(H):
        for j in range(W):
            if M[i][j] == '
                return 'No'

    return 'Yes'


def main():
    H, W = read_int_n()
    M = [read_str() for _ in range(H)]
    print(slv(H, W, M))


if __name__ == '__main__':
    main()

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


def isValid(i,j):
  
  st=False
  if i>0:
    st|=s[i-1][j]=='
  if i+1<H:
    st|=s[i+1][j]=='
  if j>0:
    st|=s[i][j-1]=='
  if j+1<W:
    st|=s[i][j+1]=='
  return st

for i in range(H):
  for j in range(W):
    if s[i][j]=='.':
      continue
    elif not isValid(i,j):
      print("No")
      exit(0)
print("Yes")