Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
mat = [list(input()) for _ in range(H)]
ans = "Yes"

def judge(i, j):
    dx = [-1, 0, 1, 0]
    dy = [0, 1, 0, -1]
    for k in range(4):
        if 0 <= i+dy[k] <= (W-1) and 0 <= j+dx[k] <= (H-1):
            if mat[i+dy[k]][j+dx[k]] == "#":
                return True
    return False

for x in range(W):
    for y in range(H):
        if mat[x][y] == "#":
            if not judge(x,y):
                ans = "No"
                break
print(ans)

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

def check(h,w):
    dx = [0,0,-1,1]
    dy = [1,-1,0,0]
    for k in range(len(dx)):
        if 0 <= h+dy[k] <= (H-1) and 0 <= w+dx[k] <= (W-1):
            if s[h+dy[k]][w+dx[k]] == "#":
                break
            elif k == 3:
                return True
    return False

ans = "Yes"
for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            if check(i,j):
                ans = "No"
                break
print(ans)

Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
mat = [list(input()) for _ in range(H)]
ans = "Yes"

def judge(i, j):
    dx = [-1, 0, 1, 0]
    dy = [0, 1, 0, -1]
    for k in range(4):
        if 0 <= i+dy[k] <= (W-1) and 0 <= j+dx[k] <= (H-1):
            if mat[i+dy[k]][j+dx[k]] == "#":
                return True
    return False

for i in range(W):
    for j in range(H):
        if mat[i][j] == "#":
            if not judge(i,j):
                ans = "No"
                break
print(ans)

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

def check(h,w):
    dx = [0,0,-1,1]
    dy = [1,-1,0,0]
    for k in range(len(dx)):
        if 0 <= h+dy[k] <= (H-1) and 0 <= w+dx[k] <= (W-1):
            if s[h+dy[k]][w+dx[k]] == "#":
                break
            elif k == 3:
                return True
    return False

ans = "Yes"
for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            if check(i,j):
                ans = "No"
                break
print(ans)

Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
mat = [list(input()) for _ in range(H)]
ans = "Yes"

def judge(i, j):
    dx = [-1, 0, 1, 0]
    dy = [0, 1, 0, -1]
    for k in range(4):
        if 0 <= i+dx[k] <= (W-1) and 0 <= j+dy[k] <= (H-1):
            if mat[i+dx[k]][j+dy[k]] == "#":
                return True
    return False

for i in range(W):
    for j in range(H):
        if mat[i][j] == "#":
            if not judge(i,j):
                ans = "No"
                break
print(ans)

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

def check(h,w):
    dx = [0,0,-1,1]
    dy = [1,-1,0,0]
    for k in range(len(dx)):
        if 0 <= h+dy[k] <= (H-1) and 0 <= w+dx[k] <= (W-1):
            if s[h+dy[k]][w+dx[k]] == "#":
                break
            elif k == 3:
                return True
    return False

ans = "Yes"
for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            if check(i,j):
                ans = "No"
                break
print(ans)

Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
mat = [list(input()) for _ in range(H)]
ans = "Yes"
dx = [-1,0,1,0]
dy = [0,1,0,-1]
for i in range(W):
    for j in range(H):
        if mat[i][j] == "#":
            for k in range(4):
                if 0 <= i+dx[k] <= W-1 and 0 <= j+dy[k] <= H-1:
                    if mat[i+dx[k]][j+dy[k]] == "#":
                        break
                    elif k == 3:
                        ans = "No"
                        break
print(ans)

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

def check(h,w):
    dx = [0,0,-1,1]
    dy = [1,-1,0,0]
    for k in range(len(dx)):
        if 0 <= h+dy[k] <= (H-1) and 0 <= w+dx[k] <= (W-1):
            if s[h+dy[k]][w+dx[k]] == "#":
                break
            elif k == 3:
                return True
    return False

ans = "Yes"
for i in range(H):
    for j in range(W):
        if s[i][j] == "#":
            if check(i,j):
                ans = "No"
                break
print(ans)