Buggy python submission (verdict: Runtime Error):
def dfs(f, stack, cnt):
    while stack:
        y, x = stack.pop()
        f[y][x] = '.'
        cnt += 1

        dxy = [(0,1), (0,-1), (1,0), (-1,0)]
        for dx, dy in dxy:
            nx, ny = x + dx, y + dy
            if 0 <= nx < w and 0 <= ny < h and f[ny][nx] == '#':
                stack.append([ny, nx])
                cnt, f = dfs(f, stack, cnt)
    return cnt, f

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

flg = False
dxy = [(0,1), (0,-1), (1,0), (-1,0)]
stack = []
for y in range(h):
    for x in range(w):
        if f[y][x] == '#':
            stack.append([y, x])
            cnt = 0
            cnt, f = dfs(f, stack, cnt)
            if cnt < 2:
                flg = True

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

Fixed submission:
h, w = map(int, input().split())
f = [["."] * (w + 2)] + \
    [list("." + input() + ".") for i in range(h)] + \
    [["."] * (w + 2)]

flg = False
for y in range(h):
    for x in range(w):
        if f[y][x] == '#':
            cnt = 0
            if f[y+1][x] == f[y-1][x] == f[y][x+1] == f[y][x-1] == '.':
                flg = True

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

Buggy python submission (verdict: Runtime Error):
def dfs(f, stack, cnt):
    while stack:
        y, x = stack.pop()
        f[y][x] = '.'
        cnt += 1

        dxy = [(0,1), (0,-1), (1,0), (-1,0)]
        for dx, dy in dxy:
            nx, ny = x + dx, y + dy
            if 0 <= nx < w and 0 <= ny < h and f[ny][nx] == '#':
                stack.append([ny, nx])
                cnt, f = dfs(f, stack, cnt)
    return cnt, f

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

flg = False
dxy = [(0,1), (0,-1), (1,0), (-1,0)]
stack = []
for y in range(h):
    for x in range(w):
        if f[y][x] == '#':
            stack.append([y, x])
            cnt = 0
            cnt, f = dfs(f, stack, cnt)
            if cnt < 2:
                flg = True
                break
    if flg:
        break

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

Fixed submission:
h, w = map(int, input().split())
f = [["."] * (w + 2)] + \
    [list("." + input() + ".") for i in range(h)] + \
    [["."] * (w + 2)]

flg = False
for y in range(h):
    for x in range(w):
        if f[y][x] == '#':
            cnt = 0
            if f[y+1][x] == f[y-1][x] == f[y][x+1] == f[y][x-1] == '.':
                flg = True

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

Buggy python submission (verdict: Runtime Error):
def dfs(f, stack, cnt):
    while stack:
        x, y = stack.pop()
        f[y][x] = '.'
        cnt += 1

        dxy = [(0,1), (0,-1), (1,0), (-1,0)]
        for dx, dy in dxy:
            nx, ny = x + dx, y + dy
            if 0 <= nx < w and 0 <= ny < h:
                if f[ny][nx] == '#':
                    stack.append([nx, ny])
                    cnt = dfs(f, stack, cnt)
    return cnt


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

flg = False
dxy = [(0,1), (0,-1), (1,0), (-1,0)]
stack = []
for y in range(h):
    for x in range(w):
        if f[y][x] == '#':
            stack.append([x, y])
            cnt = 0
            cnt = dfs(f, stack, cnt)
            if cnt < 2:
                flg = True
                break
    if flg:
        break

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

Fixed submission:
h, w = map(int, input().split())
f = [["."] * (w + 2)] + \
    [list("." + input() + ".") for i in range(h)] + \
    [["."] * (w + 2)]

flg = False
for y in range(h):
    for x in range(w):
        if f[y][x] == '#':
            cnt = 0
            if f[y+1][x] == f[y-1][x] == f[y][x+1] == f[y][x-1] == '.':
                flg = True

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