Buggy python submission (verdict: Time Limit Exceeded):
import sys
H,W,K = map(int, sys.stdin.readline().split())
MAP = sys.stdin.readlines()
ans = [None] * H
for i in range(H):
	ans[i] = list(map(str,MAP[i].rstrip()))


#H,W,K = map(int, input().split())
#ans = [list(map(str,input())) for _ in range(H)]

cnt = 1
for i in range(H):
	ichigo = 0
	cond = 0
	for j in range(W):
		if j == W-1 and ans[i][j] == ".":
			ans[i][j] = cnt
			cond = 1
			break
		if ans[i][j] == ".":
			ans[i][j] = cnt
		else:
			ans[i][j] = cnt
			cnt += 1
			ichigo += 1

	if ichigo == 0:
		ans[i] = []
		continue

	if cond:
		for k in range(W):
			if ans[i][-(k+1)] == cnt:
				ans[i][-(k+1)] -= 1
			else:
				break


cond = 1
while cond:
	cond = 0
	for i in range(H):
		if ans[i] == []:
			cond = 1
			if i == H-1:
				ans[i] = ans[i-1]
			else:
				ans[i] = ans[i+1]

for i in range(H):
	for j in range(W):
		if j == W-1:
			print(ans[i][j])
		else:
			print(ans[i][j], end = " ")

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

H,W,K = map(int, readline().split())
grid = np.frombuffer(read(), 'S1').reshape(H,-1)[:,:W]

X,Y = np.where(grid == b'#')

A = np.zeros((H,W), np.int32)
A[X,Y] = np.arange(1,K+1)

np.maximum.accumulate(A, axis = 1, out = A)

for w in range(W-2, -1, -1):
	A[:,w] += A[:,w+1] * (A[:,w] == 0)

for h in range(1,H):
	if A[h,-1] == 0:
		A[h] += A[h-1]
for h in range(H-1,-1,-1):
	if A[h,-1] == 0:
		A[h] += A[h+1]

print('\n'.join(' '.join(row) for row in A.astype(str)))

Buggy python submission (verdict: Time Limit Exceeded):
H,W,K = map(int, input().split())
ans = [list(map(str,input())) for _ in range(H)]

cnt = 1
for i in range(H):
	ichigo = 0
	cond = 0
	for j in range(W):
		if j == W-1 and ans[i][j] == ".":
			ans[i][j] = cnt
			cond = 1
			break
		if ans[i][j] == ".":
			ans[i][j] = cnt
		else:
			ans[i][j] = cnt
			cnt += 1
			ichigo += 1

	if ichigo == 0:
		ans[i] = []
		continue

	if cond:
		for k in range(W):
			if ans[i][-(k+1)] == cnt:
				ans[i][-(k+1)] -= 1
			else:
				break


cond = 1
while cond:
	cond = 0
	for i in range(H):
		if ans[i] == []:
			cond = 1
			if i == H-1:
				ans[i] = ans[i-1]
			else:
				ans[i] = ans[i+1]

for i in range(H):
	for j in range(W):
		if j == W-1:
			print(ans[i][j])
		else:
			print(ans[i][j], end = " ")

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

H,W,K = map(int, readline().split())
grid = np.frombuffer(read(), 'S1').reshape(H,-1)[:,:W]

X,Y = np.where(grid == b'#')

A = np.zeros((H,W), np.int32)
A[X,Y] = np.arange(1,K+1)

np.maximum.accumulate(A, axis = 1, out = A)

for w in range(W-2, -1, -1):
	A[:,w] += A[:,w+1] * (A[:,w] == 0)

for h in range(1,H):
	if A[h,-1] == 0:
		A[h] += A[h-1]
for h in range(H-1,-1,-1):
	if A[h,-1] == 0:
		A[h] += A[h+1]

print('\n'.join(' '.join(row) for row in A.astype(str)))

Buggy python submission (verdict: Time Limit Exceeded):
H,W,K = map(int, input().split())
S = [list(map(str,input())) for _ in range(H)]

ans = [[-1]*W for _ in range(H)]

cnt = 1
cnt_max = 0
for i in range(H):
	ichigo = S[i].count("#")
	if ichigo == 0:
		ans[i] = []
		continue
	cnt_max = cnt + ichigo - 1
	for j in range(W):
		if S[i][j] == ".":
			ans[i][j] = min(cnt,cnt_max)
		else:
			ans[i][j] = min(cnt,cnt_max)
			cnt += 1
	cnt = cnt_max+1
cond = 1
while cond:
	cond = 0
	for i in range(H):
		if ans[i] == []:
			cond = 1
			if i == H-1:
				ans[i] = ans[i-1]
			else:
				ans[i] = ans[i+1]

for i in range(H):
	for j in range(W):
		if j == W-1:
			print(ans[i][j])
		else:
			print(ans[i][j], end = " ")

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

H,W,K = map(int, readline().split())
grid = np.frombuffer(read(), 'S1').reshape(H,-1)[:,:W]

X,Y = np.where(grid == b'#')

A = np.zeros((H,W), np.int32)
A[X,Y] = np.arange(1,K+1)

np.maximum.accumulate(A, axis = 1, out = A)

for w in range(W-2, -1, -1):
	A[:,w] += A[:,w+1] * (A[:,w] == 0)

for h in range(1,H):
	if A[h,-1] == 0:
		A[h] += A[h-1]
for h in range(H-1,-1,-1):
	if A[h,-1] == 0:
		A[h] += A[h+1]

print('\n'.join(' '.join(row) for row in A.astype(str)))

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

ans = [[-1]*W for _ in range(H)]

cnt = 1
cnt_max = 0
for i in range(H):
	ichigo = S[i].count("#")
	if ichigo == 0:
		ans[i].clear()
		continue
	cnt_max = cnt + ichigo - 1
	for j in range(W):
		if S[i][j] == ".":
			ans[i][j] = min(cnt,cnt_max)
		else:
			ans[i][j] = min(cnt,cnt_max)
			cnt += 1
	cnt = cnt_max+1
cond = 1
while cond:
	cond = 0
	for i in range(H):
		if ans[i] == []:
			cond = 1
			if i == H-1:
				ans[i] = ans[i-1]
			else:
				ans[i] = ans[i+1]

for i in range(H):
	for j in range(W):
		if j == W-1:
			print(ans[i][j])
		else:
			print(ans[i][j], end = " ")

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

H,W,K = map(int, readline().split())
grid = np.frombuffer(read(), 'S1').reshape(H,-1)[:,:W]

X,Y = np.where(grid == b'#')

A = np.zeros((H,W), np.int32)
A[X,Y] = np.arange(1,K+1)

np.maximum.accumulate(A, axis = 1, out = A)

for w in range(W-2, -1, -1):
	A[:,w] += A[:,w+1] * (A[:,w] == 0)

for h in range(1,H):
	if A[h,-1] == 0:
		A[h] += A[h-1]
for h in range(H-1,-1,-1):
	if A[h,-1] == 0:
		A[h] += A[h+1]

print('\n'.join(' '.join(row) for row in A.astype(str)))

Buggy python submission (verdict: Time Limit Exceeded):
H,W,K = map(int, input().split())
S = [list(map(str,input())) for _ in range(H)]

ans = [[-1]*W for _ in range(H)]

cnt = 1
cnt_max = 0
for i in range(H):
	ichigo = S[i].count("#")
	if ichigo == 0:
		ans[i].clear()
		continue
	cnt_max = cnt + ichigo - 1
	for j in range(W):
		if S[i][j] == ".":
			ans[i][j] = min(cnt,cnt_max)
		else:
			ans[i][j] = min(cnt,cnt_max)
			cnt += 1
	cnt = cnt_max+1
cond = 1
while cond:
	cond = 0
	for i in range(H):
		if ans[i] == []:
			cond = 1
			if i == H-1:
				ans[i] = ans[i-1]
			else:
				ans[i] = ans[i+1]

for i in range(H):
	for j in range(W):
		if j == W-1:
			print(ans[i][j])
		else:
			print(ans[i][j], end = " ")

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

H,W,K = map(int, readline().split())
grid = np.frombuffer(read(), 'S1').reshape(H,-1)[:,:W]

X,Y = np.where(grid == b'#')

A = np.zeros((H,W), np.int32)
A[X,Y] = np.arange(1,K+1)

np.maximum.accumulate(A, axis = 1, out = A)

for w in range(W-2, -1, -1):
	A[:,w] += A[:,w+1] * (A[:,w] == 0)

for h in range(1,H):
	if A[h,-1] == 0:
		A[h] += A[h-1]
for h in range(H-1,-1,-1):
	if A[h,-1] == 0:
		A[h] += A[h+1]

print('\n'.join(' '.join(row) for row in A.astype(str)))