Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
s = [list(input()) for _ in range(W)]
dp = [[0] * W for _ in range(H)]

if s[0][0] == '.':
  dp[0][0] = 0
else:
  dp[0][0] = 1

for i in range(1,W):
  if s[0][i] == '.':
    dp[0][i] = dp[0][i-1]
  else:
    if s[0][i-1] == '.':
      dp[0][i] = dp[0][i-1]+1
    else:
      dp[0][i] = dp[0][i-1]

for i in range(1,H):
  for j in range(W):
    if j == 0:
      if s[i][j] == '.':
        dp[i][j] = dp[i-1][j]
      else:
        dp[i][j] = dp[i-1][j]+1
    else:
      if s[i][j] == '.':
        dp[i][j] = min(dp[i-1][j],dp[i][j-1])
      else:
        left = 0
        up = 0
        if s[i-1][j] == '.':
          left = 1
        if s[i][j-1] == '.':
          up = 1
        dp[i][j] = min(dp[i-1][j]+left,dp[i][j-1]+up)
print(dp[-1][-1])


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

for i in range(1, W):
    dp[0][i] = dp[0][i-1] + (int(s[0][i]=="#") if s[0][i-1]=="." else 0)
for h in range(1,H):
  dp[h][0] = dp[h-1][0] + (int(s[h][0]=="#") if s[h-1][0]=="." else 0)
  for w in range(1,W):
    dp[h][w] = min(dp[h-1][w]+(int(s[h][w]=="#") if s[h-1][w]=="." else 0), 
    dp[h][w-1]+(int(s[h][w]=="#") if s[h][w-1]=="." else 0))
print(dp[-1][-1])

Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
s = [list(input()) for _ in range(W)]
dp = [[0] * W for _ in range(H)]

if s[0][0] == '.':
  dp[0][0] = 0
else:
  dp[0][0] = 1

for i in range(1,W):
  if s[0][i] == '.':
    dp[0][i] = dp[0][i-1]
  else:
    dp[0][i] = dp[0][i-1]+1

for i in range(1,H):
  for j in range(W):
    if j == 0:
      if s[i][j] == '.':
        dp[i][j] = dp[i-1][j]
      else:
        dp[i][j] = dp[i-1][j]+1
    else:
      if s[i][j] == '.':
        dp[i][j] = min(dp[i-1][j],dp[i][j-1])
      else:
        left = 0
        up = 0
        if s[i-1][j] == '.':
          left = 1
        if s[i][j-1] == '.':
          up = 1
        dp[i][j] = min(dp[i-1][j]+left,dp[i][j-1]+up)
print(dp[-1][-1])


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

for i in range(1, W):
    dp[0][i] = dp[0][i-1] + (int(s[0][i]=="#") if s[0][i-1]=="." else 0)
for h in range(1,H):
  dp[h][0] = dp[h-1][0] + (int(s[h][0]=="#") if s[h-1][0]=="." else 0)
  for w in range(1,W):
    dp[h][w] = min(dp[h-1][w]+(int(s[h][w]=="#") if s[h-1][w]=="." else 0), 
    dp[h][w-1]+(int(s[h][w]=="#") if s[h][w-1]=="." else 0))
print(dp[-1][-1])

Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
s = [list(input()) for _ in range(W)]
dp = [[0] * W for _ in range(H)]

if s[0][0] == '#':
  dp[0][0] = 1
else:
  dp[0][0] = 0

for i in range(1,W):
  if s[0][i] == '.':
    dp[0][i] = dp[0][i-1]
  else:
    dp[0][i] = dp[0][i-1]+1
for i in range(1,H):
  for j in range(W):
    if j == 0:
      if s[i][j] == '.':
        dp[i][j] = dp[i-1][j]
      else:
        dp[i][j] = dp[i-1][j]+1
    else:
      if s[i][j] == '.':
        dp[i][j] = min(dp[i-1][j],dp[i][j-1])
      else:
        dp[i][j] = min(dp[i-1][j]+1,dp[i][j-1]+1)
print(dp[-1][-1])

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

for i in range(1, W):
    dp[0][i] = dp[0][i-1] + (int(s[0][i]=="#") if s[0][i-1]=="." else 0)
for h in range(1,H):
  dp[h][0] = dp[h-1][0] + (int(s[h][0]=="#") if s[h-1][0]=="." else 0)
  for w in range(1,W):
    dp[h][w] = min(dp[h-1][w]+(int(s[h][w]=="#") if s[h-1][w]=="." else 0), 
    dp[h][w-1]+(int(s[h][w]=="#") if s[h][w-1]=="." else 0))
print(dp[-1][-1])

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

print(ans)

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

for i in range(1, W):
    dp[0][i] = dp[0][i-1] + (int(s[0][i]=="#") if s[0][i-1]=="." else 0)
for h in range(1,H):
  dp[h][0] = dp[h-1][0] + (int(s[h][0]=="#") if s[h-1][0]=="." else 0)
  for w in range(1,W):
    dp[h][w] = min(dp[h-1][w]+(int(s[h][w]=="#") if s[h-1][w]=="." else 0), 
    dp[h][w-1]+(int(s[h][w]=="#") if s[h][w-1]=="." else 0))
print(dp[-1][-1])

Buggy python submission (verdict: Runtime Error):
ans = 0
H,W = map(int,input().split())
s = [list(input()) for _ in range(W)]
if s[H-1][W-1] == '#':
  ans += 1
if s[0][0] == '#':
  ans += 1
for i in range(H):
  for j in range(W):
    if s[i][j] == '.':
      s[i][j] = 0
    else:
      s[i][j] = 1
      

print(ans)

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

for i in range(1, W):
    dp[0][i] = dp[0][i-1] + (int(s[0][i]=="#") if s[0][i-1]=="." else 0)
for h in range(1,H):
  dp[h][0] = dp[h-1][0] + (int(s[h][0]=="#") if s[h-1][0]=="." else 0)
  for w in range(1,W):
    dp[h][w] = min(dp[h-1][w]+(int(s[h][w]=="#") if s[h-1][w]=="." else 0), 
    dp[h][w-1]+(int(s[h][w]=="#") if s[h][w-1]=="." else 0))
print(dp[-1][-1])

Buggy python submission (verdict: Runtime Error):
ans = 0
H,W = map(int,input().split())
s = [list(input()) for _ in range(W)]
if s[H-1][W-1] == '#':
  ans += 1
if s[0][0] == '#':
  ans += 1
for i in range(H):
  for j in range(W):
    if s[i][j] == '.':
      s[i][j] = 0
    else:
      s[i][j] = 1
      
i = 0
j = 0

while i < H-1 and j < W-1:
  if s[i+1][j] != 1:
    i += 1
  elif s[i][j+1] != 1:
    j += 1
  elif s[i+1][j] == 1 and s[i][j+1] == 1:
    if i < W-2:
      i += 1
    else:
      j += 1
    ans += 1
print(ans)

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

for i in range(1, W):
    dp[0][i] = dp[0][i-1] + (int(s[0][i]=="#") if s[0][i-1]=="." else 0)
for h in range(1,H):
  dp[h][0] = dp[h-1][0] + (int(s[h][0]=="#") if s[h-1][0]=="." else 0)
  for w in range(1,W):
    dp[h][w] = min(dp[h-1][w]+(int(s[h][w]=="#") if s[h-1][w]=="." else 0), 
    dp[h][w-1]+(int(s[h][w]=="#") if s[h][w-1]=="." else 0))
print(dp[-1][-1])