Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
S = [list(input()) for __ in range(H)]

dl = [(-1, 0), (0, 1), (1, 0), (0, -1)]
for i, row in enumerate(S):
    for j, val in enumerate(row):
        if val == '.':
            continue

        can_paint = False
        for dx, dy in dl:
            di, dj = i + dx, j + dy
            if di < 0 or H <= di or dj < 0 or W <= dj:
                continue
            if S[di][dj] == '#':
                can_paint = True
                break
        if not can_paint:
            print('No')
            return
print('Yes')

Fixed submission:
def resolve():
    H, W = map(int, input().split())
    S = [list(input()) for __ in range(H)]

    dl = [(-1, 0), (0, 1), (1, 0), (0, -1)]
    for i, row in enumerate(S):
        for j, val in enumerate(row):
            if val == '.':
                continue

            can_paint = False
            for dx, dy in dl:
                di, dj = i + dx, j + dy
                if di < 0 or H <= di or dj < 0 or W <= dj:
                    continue
                if S[di][dj] == '#':
                    can_paint = True
                    break
            if not can_paint:
                return 'No'
    return 'Yes'

print(resolve())

Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
S = [list(input()) for __ in range(H)]

dl = [(-1, 0), (0, 1), (1, 0), (-1, -1)]
for i, row in enumerate(S):
    for j, val in enumerate(row):
        if val == '.':
            continue

        can_paint = False
        for dx, dy in dl:
            di, dj = i + dx, j + dy
            if di < 0 or H <= di or dj < 0 or W <= dj:
                continue
            if S[di][dj] == '#':
                can_paint = True
                break
        if not can_paint:
            print('No')
            sys.exit(0)
print('Yes')

Fixed submission:
def resolve():
    H, W = map(int, input().split())
    S = [list(input()) for __ in range(H)]

    dl = [(-1, 0), (0, 1), (1, 0), (0, -1)]
    for i, row in enumerate(S):
        for j, val in enumerate(row):
            if val == '.':
                continue

            can_paint = False
            for dx, dy in dl:
                di, dj = i + dx, j + dy
                if di < 0 or H <= di or dj < 0 or W <= dj:
                    continue
                if S[di][dj] == '#':
                    can_paint = True
                    break
            if not can_paint:
                return 'No'
    return 'Yes'

print(resolve())

Buggy python submission (verdict: Runtime Error):
H, W = map(int, input())
S = [list(input()) for __ in range(H)]

dl = [(-1, 0), (0, 1), (1, 0), (-1, -1)]
for i, row in enumerate(S):
    for j, val in enumerate(row):
        if val == '.':
            continue

        res = False
        for dx, dy in dl:
            di, dj = i + dx, j + dy
            if di < 0 or W < di or dj < 0 or H < dj:
                continue
            if S[di][dj] == '#':
                res = True
                break
        if res:
            print('No')
print('Yes')

Fixed submission:
def resolve():
    H, W = map(int, input().split())
    S = [list(input()) for __ in range(H)]

    dl = [(-1, 0), (0, 1), (1, 0), (0, -1)]
    for i, row in enumerate(S):
        for j, val in enumerate(row):
            if val == '.':
                continue

            can_paint = False
            for dx, dy in dl:
                di, dj = i + dx, j + dy
                if di < 0 or H <= di or dj < 0 or W <= dj:
                    continue
                if S[di][dj] == '#':
                    can_paint = True
                    break
            if not can_paint:
                return 'No'
    return 'Yes'

print(resolve())