Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy
from typing import List
import sys
input = sys.stdin.readline


def delete_cell_line(line: List[int], k: int) -> int:
    prev = -1
    block = 1
    point = 0
    for idx, num in enumerate(line+[0]):
        if num == prev:
            block += 1

        else:
            if block >= k:
                point += prev * block
                for i in range(idx-block, idx):
                    line[i] = 0
            block = 1
            prev = num
    return point


def drop_down(board: List[List[int]]):
    w = len(board[0])
    h = len(board)

    for x in range(w):
        vertical_line = []
        for y in range(h):
            cell = board[y][x]
            if cell:
                vertical_line.append(cell)

        vertical_line = [0]*(h-len(vertical_line)) + vertical_line
        for y, new_cell in enumerate(vertical_line):
            board[y][x] = new_cell


def calc_score(y: int, x: int, k: int, board: List[List[int]]) -> int:
    board[y][x] = 0
    drop_down(board)
    chain = 0
    score = 0
    while True:
        point = 0
        for line in board:
            point += delete_cell_line(line, k)
        if not point:
            break

        score += point * 2**chain
        chain += 1
        drop_down(board)
    return score


def main():
    h, w, k = map(int, input().split())
    board = []
    for _ in range(h):
        pre_line = input().rstrip("\n")
        line = list(map(int, list(pre_line)))
        board.append(line)

    ans = 0
    for y in range(h):
        for x in range(w):
            new_board = deepcopy(board)
            score = calc_score(y, x, k, new_board)
            if ans < score:
                ans = score

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from copy import deepcopy
from typing import List
import sys
input = sys.stdin.readline


def delete_cell_line(line: List[int], k: int) -> int:
    prev = -1
    block = 1
    point = 0
    for idx, num in enumerate(line+[0]):
        if num == prev:
            block += 1

        else:
            if block >= k:
                point += prev * block
                for i in range(idx-block, idx):
                    line[i] = 0
            block = 1
            prev = num
    return point


def drop_down(board: List[List[int]]):
    w = len(board[0])
    h = len(board)

    for x in range(w):
        vertical_line = []
        for y in range(h):
            cell = board[y][x]
            if cell:
                vertical_line.append(cell)

        vertical_line = [0]*(h-len(vertical_line)) + vertical_line
        for y, new_cell in enumerate(vertical_line):
            board[y][x] = new_cell


def calc_score(y: int, x: int, k: int, board: List[List[int]]) -> int:
    board[y][x] = 0
    drop_down(board)
    chain = 0
    score = 0
    while True:
        point = 0
        for line in board:
            point += delete_cell_line(line, k)
        if not point:
            break

        score += point * 2**chain
        chain += 1
        drop_down(board)
    return score


def main():
    h, w, k = map(int, input().split())
    board = []
    for _ in range(h):
        pre_line = input().rstrip("\n")
        line = list(map(int, list(pre_line)))
        board.append(line)

    ans = 0
    for y in range(h):
        for x in range(w):
            new_board = deepcopy(board)
            score = calc_score(y, x, k, new_board)
            if ans < score:
                ans = score

    print(ans)


if __name__ == "__main__":
    main()