Buggy python submission (verdict: Runtime Error):
from collections import deque

H, W, K=map(int, input().split())
cake=[input() for _ in range(H)]
rows_list=[]
upper=0
for i in range(H):
  for j in range(W):
    if cake[i][j]=="#":
      rows_list.append([upper, i])
      upper=i+1
      break
rows_list[-1][-1]=H-1
ans_list=[]
for rows in rows_list:
  for i in range(rows[0], rows[1]+1):
    left=0
    for j in range(W):
      if cake[i][j]=="#":
        ans_list.append([rows[0], rows[1], left, j])
        left=j+1
    ans_list[-1][-1]=W-1
ans=[[0 for _ in range(W)] for _ in range(H)]
key=1
for l in ans_list:
  for i in range(l[0], l[1]+1):
    for j in range(l[2], l[3]+1):
      ans[i][j]=key
  key+=1
for a in ans:
  print(*a)

Fixed submission:
from collections import deque

H, W, K=map(int, input().split())
cake=[input() for _ in range(H)]
rows_list=[]
upper=0
for i in range(H):
  for j in range(W):
    if cake[i][j]=="#":
      rows_list.append([upper, i])
      upper=i+1
      break
rows_list[-1][-1]=H-1
ans_list=[]
for rows in rows_list:
  for i in range(rows[0], rows[1]+1):
    left=0
    for j in range(W):
      if cake[i][j]=="#":
        ans_list.append([rows[0], rows[1], left, j])
        left=j+1
    if ans_list:
      ans_list[-1][-1]=W-1
ans=[[0 for _ in range(W)] for _ in range(H)]
key=1
for l in ans_list:
  for i in range(l[0], l[1]+1):
    for j in range(l[2], l[3]+1):
      ans[i][j]=key
  key+=1
for a in ans:
  print(*a)

Buggy python submission (verdict: Runtime Error):
def cut(i, j, num):
  marked[i][j]=num
  if i>0 and cake[i-1][j]=="." and marked[i-1][j]==0:
    cut(i-1, j, num)
  if j>0 and cake[i][j-1]=="." and marked[i][j-1]==0:
    cut(i, j-1, num)
  if i<H-1 and cake[i+1][j]=="." and marked[i+1][j]==0:
    cut(i+1, j, num)
  if j<W-1 and cake[i][j+1]=="." and marked[i][j+1]==0:
    cut(i, j+1, num)

H, W, K=map(int, input().split())
cake=[input() for _ in range(H)]
marked=[[0 for _ in range(W)] for _ in range(H)]
mark=0
for i in range(H):
  for j in range(W):
    if cake[i][j]=="#":
      mark+=1
      cut(i, j, mark)
for i in range(H):
  print(*marked[i])

Fixed submission:
from collections import deque

H, W, K=map(int, input().split())
cake=[input() for _ in range(H)]
rows_list=[]
upper=0
for i in range(H):
  for j in range(W):
    if cake[i][j]=="#":
      rows_list.append([upper, i])
      upper=i+1
      break
rows_list[-1][-1]=H-1
ans_list=[]
for rows in rows_list:
  for i in range(rows[0], rows[1]+1):
    left=0
    for j in range(W):
      if cake[i][j]=="#":
        ans_list.append([rows[0], rows[1], left, j])
        left=j+1
    if ans_list:
      ans_list[-1][-1]=W-1
ans=[[0 for _ in range(W)] for _ in range(H)]
key=1
for l in ans_list:
  for i in range(l[0], l[1]+1):
    for j in range(l[2], l[3]+1):
      ans[i][j]=key
  key+=1
for a in ans:
  print(*a)

Buggy python submission (verdict: Runtime Error):
def cut(i, j, num):
  marked[i][j]=num
  if i>0 and cake[i-1][j]=="." and marked[i-1][j]==0:
    cut(i-1, j, num)
  if j>0 and cake[i][j-1]=="." and marked[i][j-1]==0:
    cut(i, j-1, num)
  if i<H-1 and cake[i+1][j]=="." and marked[i+1][j]==0:
    cut(i+1, j, num)
  if j<W-1 and cake[i][j+1]=="." and marked[i][j+1]==0:
    cut(i, j+1, num)

H, W, K=map(int, input().split())
cake=[input() for _ in range(H)]
marked=[[0 for _ in range(W)] for _ in range(H)]
mark=0
for i in range(H):
  for j in range(W):
    if cake[i][j]=="#":
      mark+=1
      cut(i, j, mark)
print(marked)

Fixed submission:
from collections import deque

H, W, K=map(int, input().split())
cake=[input() for _ in range(H)]
rows_list=[]
upper=0
for i in range(H):
  for j in range(W):
    if cake[i][j]=="#":
      rows_list.append([upper, i])
      upper=i+1
      break
rows_list[-1][-1]=H-1
ans_list=[]
for rows in rows_list:
  for i in range(rows[0], rows[1]+1):
    left=0
    for j in range(W):
      if cake[i][j]=="#":
        ans_list.append([rows[0], rows[1], left, j])
        left=j+1
    if ans_list:
      ans_list[-1][-1]=W-1
ans=[[0 for _ in range(W)] for _ in range(H)]
key=1
for l in ans_list:
  for i in range(l[0], l[1]+1):
    for j in range(l[2], l[3]+1):
      ans[i][j]=key
  key+=1
for a in ans:
  print(*a)