Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
hw = [input() for _ in range(h)]
dp = [[1000]*w for _ in range(h)]
if hw[0][0] == "#":
    dp[0][0] = 1
else:
    dp[0][0] = 0

for i in range(w):
    for j in range(h):
        if i > 0:
            if hw[i][j] == "#" and hw[i-1][j] == ".":
                dp[i][j] = min(dp[i][j], dp[i-1][j] + 1)
            else:
                dp[i][j] = min(dp[i][j], dp[i-1][j])
        if j > 0:
            if hw[i][j] == "#" and hw[i][j-1] == ".":
                dp[i][j] = min(dp[i][j], dp[i][j-1] + 1)
            else:
                dp[i][j] = min(dp[i][j], dp[i][j-1])

print(dp[h-1][w-1])

Fixed submission:
h, w = map(int, input().split())
hw = [input() for _ in range(h)]
dp = [[1000]*w for _ in range(h)]
if hw[0][0] == "#":
    dp[0][0] = 1
else:
    dp[0][0] = 0

for i in range(h):
    for j in range(w):
        if i > 0:
            if hw[i][j] == "#" and hw[i-1][j] == ".":
                dp[i][j] = min(dp[i][j], dp[i-1][j] + 1)
            else:
                dp[i][j] = min(dp[i][j], dp[i-1][j])
        if j > 0:
            if hw[i][j] == "#" and hw[i][j-1] == ".":
                dp[i][j] = min(dp[i][j], dp[i][j-1] + 1)
            else:
                dp[i][j] = min(dp[i][j], dp[i][j-1])

print(dp[h-1][w-1])

Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
hw = [input() for _ in range(h)]
dp = [[1000]*w for _ in range(h)]
if hw[0][0] == "#":
    dp[0][0] = 1
else:
    dp[0][0] = 0

for i in range(w):
    for j in range(h):
        if i > 0:
            if hw[i][j] == "#" and hw[i-1][j] == ".":
                dp[i][j] = min(dp[i][j], dp[i-1][j] + 1)
            else:
                dp[i][j] = min(dp[i][j], dp[i-1][j])
        if j > 0:
            if hw[i][j] == "#" and hw[i][j-1] == ".":
                dp[i][j] = min(dp[i][j], dp[i][j-1] + 1)
            else:
                dp[i][j] = min(dp[i][j], dp[i][j-1])

print(dp[h-1][w-1])

Fixed submission:
h, w = map(int, input().split())
hw = [input() for _ in range(h)]
dp = [[1000]*w for _ in range(h)]
if hw[0][0] == "#":
    dp[0][0] = 1
else:
    dp[0][0] = 0

for i in range(h):
    for j in range(w):
        if i > 0:
            if hw[i][j] == "#" and hw[i-1][j] == ".":
                dp[i][j] = min(dp[i][j], dp[i-1][j] + 1)
            else:
                dp[i][j] = min(dp[i][j], dp[i-1][j])
        if j > 0:
            if hw[i][j] == "#" and hw[i][j-1] == ".":
                dp[i][j] = min(dp[i][j], dp[i][j-1] + 1)
            else:
                dp[i][j] = min(dp[i][j], dp[i][j-1])

print(dp[h-1][w-1])

Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
hw = [input() for _ in range(h)]
ans = h+w
pvs = None

def dfs(x, y, cnt, pvs):
    global ans
    if hw[x][y] == "#" and pvs != "#":
        cnt += 1
        pvs = "#"
    elif hw[x][y] == "#" and pvs == "#":
        pass
    elif hw[x][y] == ".":
        pvs = "."
    if x == h-1 and y == w-1:
        ans = min(ans, cnt)
        return ans
    if x < h-1 and y == w-1:
        dfs(x+1, y, cnt, pvs)
    if x == h-1 and y < w-1:
        dfs(x, y+1, cnt, pvs)
    if x < h-1 and y < w-1:
        dfs(x+1, y, cnt, pvs)
        dfs(x, y+1, cnt, pvs)

dfs(0, 0, 0, pvs)
print(ans)

Fixed submission:
h, w = map(int, input().split())
hw = [input() for _ in range(h)]
dp = [[1000]*w for _ in range(h)]
if hw[0][0] == "#":
    dp[0][0] = 1
else:
    dp[0][0] = 0

for i in range(h):
    for j in range(w):
        if i > 0:
            if hw[i][j] == "#" and hw[i-1][j] == ".":
                dp[i][j] = min(dp[i][j], dp[i-1][j] + 1)
            else:
                dp[i][j] = min(dp[i][j], dp[i-1][j])
        if j > 0:
            if hw[i][j] == "#" and hw[i][j-1] == ".":
                dp[i][j] = min(dp[i][j], dp[i][j-1] + 1)
            else:
                dp[i][j] = min(dp[i][j], dp[i][j-1])

print(dp[h-1][w-1])