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())
S = []
for i in range(H):
    S.append(input())

c = [[-1]*W for i in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == '
            c[i][j] += 1
            if i != 0: c[i][j] += (S[i-1][j] == '
            if i != H-1: c[i][j] += (S[i+1][j] == '
            if j != 0: c[i][j] += (S[i][j-1] == '
            if j != W-1: c[i][j] += (S[i][j+1] == '

if any(list(map(lambda s: 0 in s, c))):
    print('No')
else:
    print('Yes')

Solution (Python):
import sys

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

array = ["".join(list(input())) for x in range(h)]

flag = True
for h_i in range(1, len(array)-2):
    for w_i in range(1, len(array[h_i]) - 2):
        if array[h_i][w_i] == "
                array[h_i - 1][w_i] == "." and "." == array[h_i][w_i - 1]:
            print("No")
            sys.exit()

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

Solution (Python):

"""
C - Grid Repainting 2
https://abc096.contest.atcoder.jp/tasks/abc096_c

"""
import sys
from sys import stdin
input = stdin.readline


def is_possible(h, w, pict):
    moves = [(0, -1), (0, 1), (-1, 0), (1, 0)]
    check = True

    ans = [['.'] * w for _ in range(h)]
    for cy in range(h):
        for cx in range(w):
            if ans[cy][cx] != pict[cy][cx]:
                check = False
                for dxy in moves:
                    nx = cx + dxy[0]
                    ny = cy + dxy[1]

                    if 0<= nx <= w-1 and 0 <= ny <= h-1:
                        if pict[ny][nx] == '
                            ans[ny][nx] = '
                            check = True
                            break
                if check != True:
                    return 'No'
    return 'Yes'


def main(args):
    h, w = map(int, input().split())
    pict = []
    for _ in range(h):
        pict.append(list(input().strip()))

    ans = is_possible(h, w, pict)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):


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

ans = 'Yes'
endFlg = False



for i in range(H):
    for j in range(W):
        if S[i][j] == '
            if i != 0 and S[i-1][j] == '
                continue
            elif i != H-1 and S[i+1][j] == '
                continue
            elif j != 0 and S[i][j-1] == '
                continue
            elif j != W-1 and S[i][j+1] == '
                continue
            else :
                ans = 'No'
                endFlg = True
                break
    if endFlg:
        break

print(ans)

Solution (Python):



x, y = map(int, input().split())


canvas = []
for i in range(x):
	canvas.append(list(input()))

for i in range(x):
	for j in range(y):
		
		if canvas[i][j] == "
			
			if i != 0:
				
				if canvas[i-1][j] == "
					continue
			
			if i != x-1:
				
				if canvas[i+1][j] == "
					continue
			
			if j != 0:
				
				if canvas[i][j-1] == "
					continue
			
			if j != y-1:
				
				if canvas[i][j+1] == "
					continue
			
			print("No")
			exit()

print("Yes")

Solution (Python):
l = input().split()
h,w = int(l[0]),int(l[1])
mapxy = []
for i in range(h):
    mapxy.append(list(input()))
dx = [1,0,-1,0]
dy = [0,1,0,-1]
flag1 = 0
flag2 = 0
for i in range(h):
    for j in range(w):
        if mapxy[i][j] == "
            for k in range(4):
                if 0<=i+dy[k]<h and 0<=j+dx[k]<w:
                    if mapxy[i+dy[k]][j+dx[k]] == "
                        flag1 = 1
            if flag1 == 0:
                flag2 = 1
                break
            flag1 = 0
    if flag2 == 1:
        print("No")
        break
if flag2 != 1:
    print("Yes")

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

field = []
for i in range(h):
    field.append(input())
flag = "Yes"

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

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

mx = [0, 1, 0, -1]
my = [1, 0, -1, 0]
for i in range(h):
  for  j in range(w):
    if table[i][j] == "
      for k in range(4):
        tx, ty = j + mx[k], i + my[k]
        if 0 <= tx < w and 0 <= ty < h and table[ty][tx] == "
          visited[i][j] = visited[ty][tx] = "

for i in range(h):
  for  j in range(w):
    if table[i][j] != visited[i][j]:
      print("No")
      exit(0)
print("Yes")

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

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

ans = True
for i in range(h):
    for j in range(w):
        if (s[i][j] == '
            found = False
            for k in range(4):
                i2 = i + dx[k]
                j2 = j + dy[k]
                if (0 <= i2 < h) and (0 <= j2 < w) and (s[i2][j2] == '
                    found = True
            if not(found):
                ans = False

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

Solution (Python):
def c_grid_repainting(H, W, Grid):
    delta = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    for h in range(H):
        for w in range(W):
            if Grid[h][w] == '.':  
                continue
            black = 0  
            for dh, dw in delta:
                is_internal = 0 <= h + dh < H and 0 <= w + dw < W
                if is_internal and Grid[h + dh][w + dw] == '
                    
                    black += 1
            if black == 0:
                
                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):
import numpy as np

h,w=list(map(int,input().split()))
s=np.zeros((h+2,w+2))

for i in range(1,h+1):
    input_=input()
    for j in range(1,w+1):
        if input_[j-1]=="
            s[i][j]=1
n=0
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j]==1:
            if (s[i-1][j]==0 and s[i+1][j]==0 and s[i][j+1]==0 and s[i][j-1]==0):
                n+=1
if n==0:
    print("Yes")
else:
    print("No")

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

s = [raw_input() for _ in range(H)]

ans = "Yes"

for y in range(H):
  for x in range(W):
    if s[y][x]=="
      ok = False
      for dx,dy in [(-1,0), (1,0), (0,-1), (0,1)]:
        if 0<=x+dx<W and 0<=y+dy<H and s[y+dy][x+dx]=="
          ok = True
      if not ok:
        ans = "No"

                
print ans

Solution (Python):
from itertools import repeat, product

def get_targets(a_grid):
    h = len(a_grid)
    w = len(a_grid[0])

    targets = [t for t in product(range(h), range(w)) if a_grid[t[0]][t[1]] == '

    return targets

def get_arounds(t, h, w):
    arounds = map(lambda a: (t[0] + a[0], t[1] + a[1]), ((0, 1), (1, 0), (0, -1), (-1, 0)))

    return list(filter(lambda x: -1 < x[0] < h and -1 < x[1] < w, arounds))

def main():
    h, w = tuple(map(int, input().split()))
    a_grid = [list(input()) for _ in range(h)]

    black_sq = get_targets(a_grid)

    if all([any([(sq in black_sq) for sq in get_arounds(bsq, h, w)]) for bsq in black_sq]):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

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

paintable = True

for i in range(H):
    for j in range(W):
        if grid[i][j] == '
            if i != 0:
                if grid[i-1][j] == '
                    continue
            if i != H - 1:
                if grid[i+1][j] == '
                    continue
            if j != 0:
                if grid[i][j-1] == '
                    continue
            if j != W - 1:
                if grid[i][j+1] == '
                    continue
            paintable = False
    if not paintable:
        break
        
print("Yes" if paintable else "No")

Solution (Python):
h,w = (int(i) for i in input().split())
s = ["."+input()+"." for i in range(h)]
s,flag = ["."*(w+2)]+s+["."*(w+2)],True
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]==".":
				flag = False
if flag: print("Yes")
else: print("No")

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

def check():
    for i in range(1,h+1):
        for j in range(1,w+1):
            if s[i][j] == '.':
                continue
            if all([s[x][y]=='.' for x,y in [(i-1,j), (i+1,j), (i,j+1), (i,j-1)]]) :
                return False
    return True

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

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

T=0
if H==1 & W==1:
	print("No")
	T=1


D=0
Numlist = []
for i in range(H):
	D+=100
	I=0
	RawList = []
	RawList = list(input())

	for j in range(W):
		CheckNum = RawList[j]
		I+=1

		if CheckNum == "
			Numlist.append(D+I)

N=0
for k in range(len(Numlist)):
	A = Numlist[k]


	OK=0

	if (A+1) in Numlist:
		OK+=1
	if (A-1) in Numlist:
		OK+=1
	if (A+100) in Numlist:
		OK+=1
	if (A-100) in Numlist:
		OK+=1

	if OK == 0 and T==0:
		print("No")
		N=1
		break


if N==0 and T==0:
	print("Yes")

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

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

            def ok(x,y):
                return x>=0 and x<h and y>=0 and y<w and s[x][y]=='

            if all([not ok(x,y) for x,y in [(i-1,j), (i+1,j), (i,j+1), (i,j-1)]]) :
                return False
    return True


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

Solution (Python):
d = list(map(int,input().split()))
at = []
at.append(["."]*(d[1]+2))
for i in range(d[0]):
  at.append(list(input()))
  at[i+1].insert(0,".")
  at[i+1].insert(d[1]+1,".")
at.append(["."]*(d[1]+2))
l = [[1,0],[0,1],[-1,0],[0,-1]]
re = True
op = False
ppp = True
def ao(k, re,op,l,ppp,d):
  for a in range(1,d[0]):
    for b in range(1,d[1]+1):
      for dx,dy in l:
        if k[a][b] =="
          re = False
        if k[a][b] =="
          op = True
      if op == True:
        re = True
      if re == False:
        ppp = False
      op = False
      re = True
  if ppp == False:
    return False
  else:
    return True
 
if ao(at,re,op,l,ppp,d) == True:
  print("Yes")
else:
  print("No")

Solution (Python):
d = list(map(int,input().split()))
at = []
at.append(["."]*(d[1]+2))
for i in range(d[0]):
  at.append(list(input()))
  at[i+1].insert(0,".")
  at[i+1].insert(d[1]+1,".")
at.append(["."]*(d[1]+2))
l = [[1,0],[0,1],[-1,0],[0,-1]]
re = True
op = False
ppp = True
def ao(k, re,op,l,ppp,d):
  for a in range(1,d[0]):
    for b in range(1,d[1]+1):
      for dx,dy in l:
        if k[a][b] =="
          re = False
        if k[a][b] =="
          op = True
      if op == True:
        re = True
      if re == False:
        ppp = False
      op = False
      re = True
  if ppp == False:
    return False
  else:
    return True
 
if ao(at,re,op,l,ppp,d) == True:
  print("Yes")
else:
  print("No")

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

def check():
    for i in range(h):
        for j in range(w):
            if s[i][j] == '.':
                continue
            ok = False
            for x,y in [(i-1,j), (i+1,j), (i,j+1), (i,j-1)]:
                if x<0 or x>=h or y<0 or y>=w :
                    continue
                if s[x][y] == '
                    ok = True
            if not ok:
                return False
    return True


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

Solution (Python):
H,W = map(int, input().split())
lis = [input() for i in range(H)]
flag = False
for i in range(H):
    for j in range(W):
        if lis[i][j] == "
            if i != 0:
                if lis[i-1][j] == "
                    continue
            if i != H-1:
                if lis[i+1][j] == "
                    continue
            if j != 0:
                if lis[i][j-1] == "
                    continue
            if j != W-1:
                if lis[i][j+1] == "
                    continue
            flag = True
    if flag:
        break
print("No" if flag else "Yes")

Solution (Python):
import sys

H,W = map(int,input().split())
s = []
for i in range(H):
        s.append(input())
for i in range(H):
        for j in range(W):
                if s[i][j]=="
                        if i==0:
                                if j==0:
                                        if s[i+1][j]=="." and s[i][j+1]==".":
                                                print("No")
                                                sys.exit(0)
                                elif j==W-1:
                                        if s[i+1][j]=="." and s[i][j-1]==".":
                                                print("No")
                                                sys.exit(0)
                                else:
                                        if s[i+1][j]=="." and s[i][j-1]=="." and s[i][j+1]==".":
                                                print("No")
                                                sys.exit(0)
                        elif i==H-1:
                                if j==0:
                                        if s[i-1][j]=="." and s[i][j+1]==".":
                                                print("No")
                                                sys.exit(0)
                                elif j==W-1:
                                        if s[i-1][j]=="." and s[i][j-1]==".":
                                                print("No")
                                                sys.exit(0)
                                else:
                                        if s[i-1][j]=="." and s[i][j-1]=="." and s[i][j+1]==".":
                                                print("No")
                                                sys.exit(0)
                        else:
                                if j==0:
                                        if s[i+1][j]=="." and s[i-1][j]=="." and s[i][j+1]==".":
                                                print("No")
                                                sys.exit(0)
                                elif j==W-1:
                                        if s[i+1][j]=="." and s[i-1][j]=="." and s[i][j-1]==".":
                                                print("No")
                                                sys.exit(0)
                                else:
                                        if s[i+1][j]=="." and s[i-1][j]=="." and s[i][j-1]=="." and s[i][j+1]==".":
                                                print("No")
                                                sys.exit(0)
print("Yes")

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

def check(x, y):
	global flag
	global c
	c += 1
	if flag:
		return
	if (x < 0 or x > W-1):
		return
	if (y < 0 or y > H-1):
		return
	if c != 1:
		if s_lines[y][x] == '
			flag = True
			return
		elif s_lines[y][x] == '.':
			return
	check(x+1, y)
	check(x-1, y)
	check(x, y+1)
	check(x, y-1)


for y, line in enumerate(s_lines):	
	for x, l in enumerate(line):
		if l == '
			flag = False
			c = 0
			check(x, y)
			if flag is False:
				print('No')
				exit()
print('Yes')

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

def check(x, y):
	global flag
	global c
	c += 1
	if flag:
		return
	if (x < 0 or x > W-1):
		return
	if (y < 0 or y > H-1):
		return
	if c != 1:
		if s_lines[y][x] == '
			flag = True
			return
		elif s_lines[y][x] == '.':
			return
	check(x+1, y)
	check(x-1, y)
	check(x, y+1)
	check(x, y-1)


for y, line in enumerate(s_lines):	
	for x, l in enumerate(line):
		if l == '
			flag = False
			c = 0
			check(x, y)
			if flag is False:
				print('No')
				exit()
print('Yes')

Solution (Python):
import sys
H,W = input().split()
H = int(H)
W = int(W)
s = []

s.append("."*(W+2))
for i in range(H):
    s.append("."+input()+".")

s.append("."*(W+2))


for i in range(1,1+H):
    for j in range(1,1+W):

        if s[i][j] == "
            if s[i][j-1] != "
                print("No")

                sys.exit()

print("Yes")

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

for i in range(h):
	list.append([])
	row = input()
	for j in range(w):
		element = row[j]
		list[i].append(element == '

def all_check(h, w, list):
	for i in range(h):
		for j in range(w):
			if not check(i, j, h, w, list):
				return False

	return True

def check(i, j, h, w,list):
	if list[i][j]:
		return subcheck(i, j, h, w, list)
	else:
		return True

def subcheck(i, j, h, w, list):
	if i > 0 and list[i-1][j]:
		return True
	if i < h-1 and list[i+1][j]:
		return True
	if j > 0 and list[i][j-1]:
		return True
	if j < w-1 and list[i][j+1]:
		return True

if all_check(h, w, list):
	print("Yes")
else:
	print("No")

Solution (Python):
s = input().rstrip().split()
h = int(s[0])
w = int(s[1])

table = []

for i in range(h):
  t = input()
  line = list(t)
  table.append(line)

flg = 0

h_edge = h-1
w_edge = w-1

for i in range(h):
  for j in range(w):
    if(table[i][j] == "
      table[i][j] == "/"
      if(i == 0 and j == 0):
        if(table[i][j+1] == "." and table[i+1][j] == "."):
          flg = 1
      elif(i == 0 and j != w_edge):
        if(table[i][j+1] == "." and table[i+1][j] == "." and table[i][j-1] == "."):
          flg = 1
      elif(j == 0 and i != h_edge):
        if(table[i][j+1] == "." and table[i+1][j] == "." and table[i-1][j] == "."):
          flg = 1
      elif(i == h_edge and j == w_edge):
        if(table[i-1][j] == "." and table[i][j-1] == "."):
          flg = 1
      elif(i == h_edge):
        if(table[i][j+1] == "." and table[i][j-1] == "." and table[i-1][j] == "."):
          flg = 1
      elif(j == w_edge):
        if(table[i+1][j] == "." and table[i][j-1] == "." and table[i-1][j] == "."):
          flg = 1
      else:
        if(table[i][j+1] == "." and table[i+1][j] == "." and table[i][j-1] == "." and table[i-1][j] == "."):
          flg = 1
      if(flg == 1):
        break
  else:
    continue
  break

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

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

s=[]

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


def check(i, j):
    if i != 0 and s[i-1][j] == '
        return True
    if j != 0 and s[i][j -1] == '
        return True
    if i != h - 1 and s[i+1][j] == '
        return True
    if j != w -1 and s[i][j+1] == '
        return True
    return False

ret = True
for i in range(h):
    for j in range(w):
        if s[i][j] == '
            ret = False
print('Yes' if ret else 'No')

Solution (Python):
H,W = map(int,input().split())
lists = [input() for i in range(H)]
x = 1
y = 1
check = True
for x in range(1,H-1):
    for y in range(1,W-1):
        if(lists[x][y] == "
            if(x!=0 or y!=0 or x==W-1or y==H-1):
                if((lists[x+1][y] == ".") and (lists[x-1][y] == ".") and (lists[x][y-1] == ".") and (lists[x][y+1] == ".")):
                    check = False
if(lists[0][0] == "
     if(lists[0][1] == "." and lists[1][0] == "."):
        check = False
if(lists[H-1][0] == "
     if(lists[H-2][0] == "." and lists[H-1][1] == "."):
            check = False
if(lists[0][W-1] == "
    if(lists[0][W-2] == "." and lists[1][W-1] == "."):
        check = False
if(lists[H-1][W-1] == "
    if(lists[H-2][W-1] == "." and lists[H-1][W-2] == "."):
        check = False
if(check):
    print("Yes")
else :
    print("No")

Solution (Python):
h,w=map(int,input().split())
a=[]
for i in range(h):
    a.append(list(input()))
judge = True
for i in range(h):
    for j in range(w):
        if a[i][j]==".":
            continue
        if i>0 and a[i-1][j]=="
            continue
        if j>0 and a[i][j-1]=="
            continue
        if j<w-1 and a[i][j+1]=="
            continue
        if i<h-1 and a[i+1][j]=="
            continue
        judge =False
    if not judge :
        break
print("Yes" if judge else "No")

Solution (Python):
H, W = map(int, input().split())
grid = []
soloList = []
soloGrid = ""
for _ in range(H):
    row = list(input())
    grid.append(row)

if H == 1 and W == 1:
    if grid[0][0] == ".":
        print("Yes")
    else:
        print("No")

elif H == 1:
    for i in range(H): 
        for j in range(W): 
            if j == 0:
                if grid[i][j] == "
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
                
            elif j == W-1:
                if grid[i][j] == "
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass

            else:
                if grid[i][j] == "
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
    if soloList == []:
        print("Yes")
    else:
        print("No")

elif W == 1:
    for j in range(W):  
        for i in range(H): 
            if i == 0:
                if grid[i][j] == "
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
                
            elif i == H-1:
                if grid[i][j] == "
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
            else:
                if grid[i][j] == "
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
    print(soloGrid)
    if soloList == []:
        print("Yes")
    else:
        print("No")
                
else:
    for i in range(H): 
        for j in range(W): 
            if j == 0:
                if grid[i][j] == "
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
                
            elif j == W-1:
                if grid[i][j] == "
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass

            else:
                if grid[i][j] == "
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass


    for j in range(W):  
        for i in range(H): 
            if i == 0:
                if grid[i][j] == "
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
                
            elif i == H-1:
                if grid[i][j] == "
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
            else:
                if grid[i][j] == "
                    soloGrid = str(i) + ", " + str(j)
                    soloList.append(soloGrid)
                else:
                    pass
            
    if len(soloList) == len(set(soloList)):
        print("Yes")
    else:
        print("No")

Solution (Python):
h,w = map(int,input().split())
c = [[] for i in range(0,h+2)]
ans = "Yes"
c[0] = ["."for i in range(0,w+2)]
c[h+1] = ["."for i in range(0,w+2)]
for i in range(1,h+1):
    d = []
    d = list(input())
    d.append(".")
    d.insert(0,".")
    c[i] = d
for j in range(1,h+1):
    for i in range(1,w+1):
        if c[j][i] == "
            flag = "No"
            if(c[j][i-1] == "
                flag = "Yes"
            if(c[j][i+1] == "
                flag = "Yes"
            if(c[j-1][i] == "
                flag = "Yes"
            if(c[j+1][i] == "
                flag = "Yes"
            if(flag == "No"):
                ans = "No"
print(ans)

Solution (Python):

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

As_is_campus=[[False for w in range(W)] for h in range(H)]

To_be_campus=[[False for w in range(W+2)] for h in range(H+2)]

for h in range(H):
    for i,w in enumerate(input()):
        if w=="
            To_be_campus[h+1][i+1]=True
            



flag = True
for i in range(1,H+2):
    if not flag :
        break
    for j in range(1,W+2):
        if To_be_campus[i][j]:
            if not (To_be_campus[i-1][j] or To_be_campus[i][j-1] or To_be_campus[i][j+1]  or To_be_campus[i+1][j] ):
                flag = False
                break

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

Solution (Python):




R, C = list(map(int, input().split(" ")))



want_map = []
can_map = []

for r in range(R):
    
    want_map.append(list(input()))
    can_map.append(["?"] * C)


    for c in range(C):
        if can_map[r][c] != "feasible":
            if want_map[r][c] == ".":
                can_map[r][c] = "feasible"

            else:
                if c + 1 < C:
                    if want_map[r][c+1] == "
                        can_map[r][c] = "feasible"
                        can_map[r][c+1] = "feasible"
        else:
            if c + 1 < C:
                if want_map[r][c + 1] == "
                    can_map[r][c + 1] = "feasible"

        if r != 0:
            if (want_map[r][c] == "
                can_map[r][c] = "feasible"
                can_map[r-1][c] = "feasible"





can_elements = []

for can_map_row in can_map:
    can_elements.extend(can_map_row)

if "?" in can_elements:
    print("No")
else:
    print("Yes")

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

for i in range(H):
  x = input().split()
  x = list(x[0])
  for j,l in enumerate(x):
    lst[i][j] = l

for i in range(H):
  for j in range(W):
    checker = []
    if lst[i][j] == '
      if i != 0:
        num = 1 if lst[i - 1][j] == '.' else 0
        checker.append(num)
      if i != H - 1:
        num = 1 if lst[i + 1][j] == '.' else 0
        checker.append(num)
      if j != 0:
        num = 1 if lst[i][j - 1] == '.' else 0
        checker.append(num)
      if j != W - 1:
        num = 1 if lst[i][j + 1] == '.' else 0
        checker.append(num)
    
    if len(checker) == sum(checker) and len(checker) != 0:
      print('No')
      exit()

print('Yes')

Solution (Python):
import itertools
H, W = list(map(int,input().strip().split(' ')))
pict = [[0]*W]*H
for i in range(H):
    pict[i] = list(map(str,input().strip().split(' ')))
now = [['.' for i in range(W)] for j in range(H)]
for i,j in itertools.product(range(H),range(W)):
    if pict[i][0][j] == '
        if j < W-1:
            if pict[i][0][j+1]== '
                now[i][j],now[i][j+1] = '
        if i < H-1:
            if pict[i+1][0][j] == '
                now[i][j],now[i+1][j] = '
flg = 'Yes'

for i,j in itertools.product(range(H),range(W)):
    if pict[i][0][j] != now[i][j]:
        flg = 'No'
print(flg)

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

array = ["".join(list(input())) for x in range(h)]

array2 = list(map(list, zip(*array)))
array3 = []
for i in array2:
    array3.append("".join(i))

flag = True
for h_i in range(len(array)):
    for w_i in range(len(array[h_i]) - 2):
        if array[h_i][w_i:w_i + 3] == ".
            if array3[w_i + 1][h_i:h_i + 3] == ".
                flag = False
                break
    if not flag:
        break

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

Solution (Python):
H,W = map(int,input().split())
a = [["."]*(W+2)]*(H+1)
f = True
for i in range(H):
    a[i+1] = ["."]
    a[i+1].extend([x for x in input()])
    a[i+1].append(".")
a.append(["."]*(W+2))
for i in range(1,H+1):
    for j in range(1,W+1):
        if a[i][j] == "
            if a[i][j+1] == "." and a[i][j-1] == "." and a[i+1][j] == "." and a[i-1][j] == ".":
                f = False
                break
                break
if f:
    print("Yes")
else:
    print("No")

Solution (Python):
H, W = (int(i) for i in input().split())
t = []
t.append(['.']*(H+2))

for j in range(H):
	tmp = input()
	tmp = '.' + tmp + '.'
	t.append(list(tmp))

t.append(['.']*(H+2))

def CheckBlock(i,k):
	if t[i][k-1] == '
		return 0
	elif t[i-1][k] == '
		return 1
	elif t[i+1][k] == '
		return 2
	elif t[i][k+1] == '
		return 3
	else:
		return 4

for k in range(1,W+1):
	for i in range(1,H+1):
		if t[i][k] == '
			marker = CheckBlock(i,k)
			if marker == 4:
				print('No')
				quit()
print('Yes')

Solution (Python):


H,W = list(map(int,raw_input().split()))
field = []
answer = "Yes"
for i in range (H):
    li = list(raw_input().strip())
    field.append(li[:])
def check(a,b):
    if field[a][b] ==".":
        return True
    check_li = [[a-1,b],[a+1,b],[a,b+1],[a,b-1]]
    check_li = filter(lambda x: 0 <= x[0] <= H-1 and 0<= x[1] <=W-1,check_li )
    for i in check_li:
        if field[i[0]][i[1]] == "
            return True
            break
    else:
        return False

for i in range (H):
    for j in range (W):
        if check(i,j) == False:
            answer = "No"
            break
print answer

Solution (Python):
H, W = [int(a) for a in input().split()]
cambus = []
cambus.append(list("."*(W+2)))
for i in range(H):
     cambus.append(["."] + list(input()) + ["."])
cambus.append(list("."*(W+2)))
stop_num = 0


for i in range(H):
    for j in range(W):
        if cambus[i+1][j:j + 3] == [".", "
            if cambus[i][j+1] == "." and cambus[i+2][j+1] == ".":
                stop_num = 1
                break
if stop_num == 1:
    print("No")
else:
    print("Yes")