Buggy python submission (verdict: Time Limit Exceeded):
import sys

H, W = map(int, sys.stdin.readline().split())
s = [list(sys.stdin.readline().rstrip()) for _ in range(H)]

ans = float("inf")


def dfs(x, y, tmp=0):
    if s[x][y] == "#":
        tmp = tmp + 1
    global ans
    if tmp > ans:
        return
    if x == H - 1 and y == W - 1:
        if tmp == 0:
            print(0)
            exit()
        ans = tmp
        return ans
    else:
        if x == H - 1:
            dfs(x, y + 1, tmp)
        elif y == W - 1:
            dfs(x + 1, y, tmp)
        else:
            dfs(x, y + 1, tmp)
            dfs(x + 1, y, tmp)


def main():
    dfs(0, 0)
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
import sys


def main():
    dp = [[0] * W for _ in range(H)]

    for y in range(H):
        for x in range(W):
            if x == 0 and y == 0:
                if s[0][0] == "#":
                    dp[0][0] = 1
            elif x == 0:
                if s[y][x] == "#" and s[y - 1][x] == ".":
                    dp[y][x] = dp[y - 1][x] + 1
                else:
                    dp[y][x] = dp[y - 1][x]
            elif y == 0:
                if s[y][x] == "#" and s[y][x - 1] == ".":
                    dp[y][x] = dp[y][x - 1] + 1
                else:
                    dp[y][x] = dp[y][x - 1]
            else:
                if s[y][x] == "#" and s[y][x - 1] == "." and s[y - 1][x] == ".":
                    dp[y][x] = min(dp[y][x - 1], dp[y - 1][x]) + 1
                elif s[y][x] == "#" and s[y][x - 1] == ".":
                    dp[y][x] = min(dp[y][x - 1] + 1, dp[y - 1][x])
                elif s[y][x] == "#" and s[y - 1][x] == ".":
                    dp[y][x] = min(dp[y][x - 1], dp[y - 1][x] + 1)
                else:
                    dp[y][x] = min(dp[y][x - 1], dp[y - 1][x])

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


if __name__ == "__main__":
    H, W = map(int, sys.stdin.readline().split())
    s = [list(sys.stdin.readline().rstrip()) for _ in range(H)]
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

H, W = map(int, sys.stdin.readline().split())
s = [list(sys.stdin.readline().rstrip()) for _ in range(H)]

ans = float("inf")


def dfs(x, y, tmp=0):
    if s[x][y] == "#":
        tmp = tmp + 1
    global ans
    if tmp > ans:
        return
    if x == H - 1 and y == W - 1:
        ans = tmp
        return ans
    else:
        if x == H - 1:
            dfs(x, y + 1, tmp)
        elif y == W - 1:
            dfs(x + 1, y, tmp)
        else:
            dfs(x, y + 1, tmp)
            dfs(x + 1, y, tmp)


def main():
    dfs(0, 0)
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
import sys


def main():
    dp = [[0] * W for _ in range(H)]

    for y in range(H):
        for x in range(W):
            if x == 0 and y == 0:
                if s[0][0] == "#":
                    dp[0][0] = 1
            elif x == 0:
                if s[y][x] == "#" and s[y - 1][x] == ".":
                    dp[y][x] = dp[y - 1][x] + 1
                else:
                    dp[y][x] = dp[y - 1][x]
            elif y == 0:
                if s[y][x] == "#" and s[y][x - 1] == ".":
                    dp[y][x] = dp[y][x - 1] + 1
                else:
                    dp[y][x] = dp[y][x - 1]
            else:
                if s[y][x] == "#" and s[y][x - 1] == "." and s[y - 1][x] == ".":
                    dp[y][x] = min(dp[y][x - 1], dp[y - 1][x]) + 1
                elif s[y][x] == "#" and s[y][x - 1] == ".":
                    dp[y][x] = min(dp[y][x - 1] + 1, dp[y - 1][x])
                elif s[y][x] == "#" and s[y - 1][x] == ".":
                    dp[y][x] = min(dp[y][x - 1], dp[y - 1][x] + 1)
                else:
                    dp[y][x] = min(dp[y][x - 1], dp[y - 1][x])

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


if __name__ == "__main__":
    H, W = map(int, sys.stdin.readline().split())
    s = [list(sys.stdin.readline().rstrip()) for _ in range(H)]
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

H, W = map(int, sys.stdin.readline().split())
s = [list(sys.stdin.readline().rstrip()) for _ in range(H)]

ans = []


def dfs(x, y, tmp=0):
    if s[x][y] == "#":
        tmp = tmp + 1
    if x == H - 1 and y == W - 1:
        return ans.append(tmp)
    else:
        if x == H - 1:
            dfs(x, y + 1, tmp)
        elif y == W - 1:
            dfs(x + 1, y, tmp)
        else:
            dfs(x, y + 1, tmp)
            dfs(x + 1, y, tmp)


def main():
    dfs(0, 0)
    print(min(ans))


if __name__ == "__main__":
    main()

Fixed submission:
import sys


def main():
    dp = [[0] * W for _ in range(H)]

    for y in range(H):
        for x in range(W):
            if x == 0 and y == 0:
                if s[0][0] == "#":
                    dp[0][0] = 1
            elif x == 0:
                if s[y][x] == "#" and s[y - 1][x] == ".":
                    dp[y][x] = dp[y - 1][x] + 1
                else:
                    dp[y][x] = dp[y - 1][x]
            elif y == 0:
                if s[y][x] == "#" and s[y][x - 1] == ".":
                    dp[y][x] = dp[y][x - 1] + 1
                else:
                    dp[y][x] = dp[y][x - 1]
            else:
                if s[y][x] == "#" and s[y][x - 1] == "." and s[y - 1][x] == ".":
                    dp[y][x] = min(dp[y][x - 1], dp[y - 1][x]) + 1
                elif s[y][x] == "#" and s[y][x - 1] == ".":
                    dp[y][x] = min(dp[y][x - 1] + 1, dp[y - 1][x])
                elif s[y][x] == "#" and s[y - 1][x] == ".":
                    dp[y][x] = min(dp[y][x - 1], dp[y - 1][x] + 1)
                else:
                    dp[y][x] = min(dp[y][x - 1], dp[y - 1][x])

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


if __name__ == "__main__":
    H, W = map(int, sys.stdin.readline().split())
    s = [list(sys.stdin.readline().rstrip()) for _ in range(H)]
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

H, W = map(int, sys.stdin.readline().split())
s = [list(sys.stdin.readline().rstrip()) for _ in range(H)]

ans = []


def dfs(x, y, tmp=0):
    if s[x][y] == "#":
        tmp = tmp + 1
    if x == H - 1 and y == W - 1:
        return ans.append(tmp)
    else:
        if x == H - 1:
            dfs(x, y + 1, tmp)
        elif y == W - 1:
            dfs(x + 1, y, tmp)
        else:
            dfs(x, y + 1, tmp)
            dfs(x + 1, y, tmp)


def main():
    dfs(0, 0)
    print(min(ans))


if __name__ == "__main__":
    main()

Fixed submission:
import sys


def main():
    dp = [[0] * W for _ in range(H)]

    for y in range(H):
        for x in range(W):
            if x == 0 and y == 0:
                if s[0][0] == "#":
                    dp[0][0] = 1
            elif x == 0:
                if s[y][x] == "#" and s[y - 1][x] == ".":
                    dp[y][x] = dp[y - 1][x] + 1
                else:
                    dp[y][x] = dp[y - 1][x]
            elif y == 0:
                if s[y][x] == "#" and s[y][x - 1] == ".":
                    dp[y][x] = dp[y][x - 1] + 1
                else:
                    dp[y][x] = dp[y][x - 1]
            else:
                if s[y][x] == "#" and s[y][x - 1] == "." and s[y - 1][x] == ".":
                    dp[y][x] = min(dp[y][x - 1], dp[y - 1][x]) + 1
                elif s[y][x] == "#" and s[y][x - 1] == ".":
                    dp[y][x] = min(dp[y][x - 1] + 1, dp[y - 1][x])
                elif s[y][x] == "#" and s[y - 1][x] == ".":
                    dp[y][x] = min(dp[y][x - 1], dp[y - 1][x] + 1)
                else:
                    dp[y][x] = min(dp[y][x - 1], dp[y - 1][x])

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


if __name__ == "__main__":
    H, W = map(int, sys.stdin.readline().split())
    s = [list(sys.stdin.readline().rstrip()) for _ in range(H)]
    main()