Buggy python submission (verdict: Time Limit Exceeded):
#! /usr/bin/env python3

def dropcell():
    for y in range(H):
        for i in range(H):
            for j in range(W):
                if gm[H-i][j] == 0:
                    gm[H-i-1][j], gm[H-i][j] = gm[H-i][j], gm[H-i-1][j]
def removecell():
    global gp, gf
    gf = False
    p = 0
    for y in range(H):
        c = 1
        t = 0
        for i in range(W+1):
            x = gm[y+1][i]
            if x > 0 and x == t:
                c += 1
            else:
                if c >= K:
                    for j in range(c):
                        gm[y+1][i-1-j] = 0
                    p += (t * c)
                    gf = True
                t = x
                c = 1
    gp += p * (2**gi)


H, W, K = map(int, input().split())
M = [[0]*(W+1)]+[list(map(int, list(input())))+[0] for i in range(H)]
points = {}
for i in range(H)[::-1]:
    for j in range(W):
        gp = 0
        gf = True
        gi = 0
        gm = [[j for j in i]for i in M]
        gm[i+1][j] = 0
        while gf:
            dropcell()
            removecell()
            gi += 1
        points[gp] = 1
print(max(points))

Fixed submission:
#! /usr/bin/env python3

def dropcell(h, w, rm):
    for i in range(w):
        y = 0
        for j in range(h):
            if rm[h-j-1][i] != 0:
                rm[h-y-1][i] = rm[h-j-1][i]
                y += 1
        for j in range(h-y):
            rm[h-y-j-1][i] = 0

def removecell(h, w, k, rm, a):
    p = 0
    for y in range(h):
        c, t = 1, 0
        for i in range(w+1):
            x = rm[y][i]
            if x > 0 and x == t:
                c += 1
            else:
                if c >= k:
                    for j in range(c):
                        rm[y][i-1-j] = 0
                    p += (t * c)
                t = x
                c = 1
    return p * (2**a)

def game(h, w, k, M, y, x):
    f, score, a = 1, 0, 0
    rm = [[j for j in i]for i in M[:y+1]]
    rm[y][x] = 0
    while f:
        dropcell(len(rm), w, rm)
        f = removecell(len(rm), w, k, rm, a)
        score += f
        a += 1
    return score

def main():
    H, W, K = map(int, input().split())
    M = [list(map(int, list(input())))+[0] for i in range(H)]
    ans = 0
    for j in range(W):
        t = 0
        for i in range(1, H):
            if M[i][j] != t:
                ans = max(ans, game(H, W, K, M, i, j))
                t = M[i][j]
    print(ans)
    
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
#! /usr/bin/env python3

def dropcell():
    for y in range(H):
        for i in range(H):
            for j in range(W):
                if gm[H-i][j] == 0:
                    gm[H-i-1][j], gm[H-i][j] = gm[H-i][j], gm[H-i-1][j]
def removecell():
    global gp, gf
    gf = False
    p = 0
    for y in range(H):
        c = 1
        t = 0
        for i in range(W+1):
            x = gm[y+1][i]
            if x > 0 and x == t:
                c += 1
            else:
                if c >= K:
                    for j in range(c):
                        gm[y+1][i-1-j] = 0
                    p += (t * c)
                    gf = True
                t = x
                c = 1
    gp += p * (2**gi)


H, W, K = map(int, input().split())
M = [[0]*(W+1)]+[list(map(int, [*input()]))+[0] for i in range(H)]
points = {}
for i in range(H)[::-1]:
    for j in range(W):
        gp = 0
        gf = True
        gi = 0
        gm = [[j for j in i]for i in M]
        gm[i+1][j] = 0
        while gf:
            dropcell()
            removecell()
            gi += 1
        points[gp] = 1
print(max(points))

Fixed submission:
#! /usr/bin/env python3

def dropcell(h, w, rm):
    for i in range(w):
        y = 0
        for j in range(h):
            if rm[h-j-1][i] != 0:
                rm[h-y-1][i] = rm[h-j-1][i]
                y += 1
        for j in range(h-y):
            rm[h-y-j-1][i] = 0

def removecell(h, w, k, rm, a):
    p = 0
    for y in range(h):
        c, t = 1, 0
        for i in range(w+1):
            x = rm[y][i]
            if x > 0 and x == t:
                c += 1
            else:
                if c >= k:
                    for j in range(c):
                        rm[y][i-1-j] = 0
                    p += (t * c)
                t = x
                c = 1
    return p * (2**a)

def game(h, w, k, M, y, x):
    f, score, a = 1, 0, 0
    rm = [[j for j in i]for i in M[:y+1]]
    rm[y][x] = 0
    while f:
        dropcell(len(rm), w, rm)
        f = removecell(len(rm), w, k, rm, a)
        score += f
        a += 1
    return score

def main():
    H, W, K = map(int, input().split())
    M = [list(map(int, list(input())))+[0] for i in range(H)]
    ans = 0
    for j in range(W):
        t = 0
        for i in range(1, H):
            if M[i][j] != t:
                ans = max(ans, game(H, W, K, M, i, j))
                t = M[i][j]
    print(ans)
    
if __name__ == '__main__':
    main()