Buggy python submission (verdict: Time Limit Exceeded):
n, m, k = [int(i) for i in input().split()]

subsets = []
splits = [i for i in range(1, n)]
n -= 1
for i in range(2**n):
    x = []
    for j in range(n):
        if i&(1<<j):
            x.append(j)
    subsets.append(x)
n+=1
A = []
for i in range(n):
    A.append([int(j) for j in input()])
ans = n*m
for subset in subsets:
    cur_ans = len(subset)
    #print(subset)
    tmp = []
    col = 0
    subset.append(100000)
    running_sum = [0 for i in range(len(subset)+10)]    
    while col<m:
        row_ptr = 0    
        for row in range(n):
            if row > subset[row_ptr]:
                row_ptr += 1
            running_sum[row_ptr] += A[row][col]
            if running_sum[row_ptr] > k:
                col -= 1
                running_sum = [0 for i in range(len(subset)+10)]
                cur_ans += 1
                break
        col += 1                
    ans = min(ans, cur_ans)
print(ans)


Fixed submission:
n, m, k = [int(i) for i in input().split()]

subsets = []
splits = [i for i in range(1, n)]
n -= 1
for i in range(2**n):
    x = []
    for j in range(n):
        if i&(1<<j):
            x.append(j)
    subsets.append(x)
n+=1
A = []
for i in range(n):
    A.append([int(j) for j in input()])
ans = n*m
for subset in subsets:
    cur_ans = len(subset)
    tmp = []
    col = 0
    subset.append(100000)
    running_sum = [0 for i in range(len(subset))]    
    while col<m:
        row_ptr = 0    
        for row in range(n):
            if row > subset[row_ptr]:
                row_ptr += 1
            running_sum[row_ptr] += A[row][col]
            if running_sum[row_ptr] > k:
                col -= 1
                running_sum = [0 for i in range(len(subset))]
                cur_ans += 1
                break
                
        col += 1                
        if cur_ans >= ans:
          break
    ans = min(ans, cur_ans)
print(ans)

Buggy python submission (verdict: Runtime Error):
n, m, k = [int(i) for i in input().split()]

subsets = []
splits = [i for i in range(1, n)]
n -= 1
for i in range(2**n):
    x = []
    for j in range(n):
        if i&(1<<j):
            x.append(j)
    subsets.append(x)

n+=1

A = []
for i in range(n):
    A.append([int(j) for j in input()])
#print(A)

ans = n*m


for subset in subsets:
    cur_ans = len(subset)
    #print(subset)
    tmp = []
    col = 0
    subset.append(1000000000)
    running_sum = [0 for i in range(len(subset)+10)]    
    while col<m:
        row_ptr = 0    
        for row in range(n):
            if row > subset[row_ptr]:
                row_ptr += 1

            running_sum[row_ptr] += A[row][col]
            if running_sum[row_ptr] > k:
                #print(dict(update_at = (row,col)), running_sum)
                col -= 1
                
                running_sum = [0 for i in range(len(subset)+10)]
                cur_ans += 1
                
        col += 1                
    #print(subset, cur_ans)
    ans = min(ans, cur_ans)
print(ans)


Fixed submission:
n, m, k = [int(i) for i in input().split()]

subsets = []
splits = [i for i in range(1, n)]
n -= 1
for i in range(2**n):
    x = []
    for j in range(n):
        if i&(1<<j):
            x.append(j)
    subsets.append(x)
n+=1
A = []
for i in range(n):
    A.append([int(j) for j in input()])
ans = n*m
for subset in subsets:
    cur_ans = len(subset)
    tmp = []
    col = 0
    subset.append(100000)
    running_sum = [0 for i in range(len(subset))]    
    while col<m:
        row_ptr = 0    
        for row in range(n):
            if row > subset[row_ptr]:
                row_ptr += 1
            running_sum[row_ptr] += A[row][col]
            if running_sum[row_ptr] > k:
                col -= 1
                running_sum = [0 for i in range(len(subset))]
                cur_ans += 1
                break
                
        col += 1                
        if cur_ans >= ans:
          break
    ans = min(ans, cur_ans)
print(ans)

Buggy python submission (verdict: Runtime Error):
n, m, k = [int(i) for i in input().split()]

subsets = []
splits = [i for i in range(1, n)]
n -= 1
for i in range(2**n):
    x = []
    for j in range(n):
        if i&(1<<j):
            x.append(j)
    subsets.append(x)

n+=1

A = []
for i in range(n):
    A.append([int(j) for j in input()])
#print(A)

ans = n*m


for subset in subsets:
    cur_ans = len(subset)
    #print(subset)
    tmp = []
    col = 0
    subset.append(1000000000)
    running_sum = [0 for i in range(len(subset)+10)]    
    while col<m:
        row_ptr = 0    
        for row in range(n):
            if row > subset[row_ptr] and row_ptr+1 < len(subset):
                row_ptr += 1
            #print(subset, row, row_ptr, running_sum)    
            running_sum[row_ptr] += A[row][col]
            if running_sum[row_ptr] > k:
                #print(dict(update_at = (row,col)), running_sum)
                col -= 1
                
                running_sum = [0 for i in range(len(subset)+10)]
                cur_ans += 1
                
            
            
        col += 1                
    #print(subset, cur_ans)
    ans = min(ans, cur_ans)
print(ans)


Fixed submission:
n, m, k = [int(i) for i in input().split()]

subsets = []
splits = [i for i in range(1, n)]
n -= 1
for i in range(2**n):
    x = []
    for j in range(n):
        if i&(1<<j):
            x.append(j)
    subsets.append(x)
n+=1
A = []
for i in range(n):
    A.append([int(j) for j in input()])
ans = n*m
for subset in subsets:
    cur_ans = len(subset)
    tmp = []
    col = 0
    subset.append(100000)
    running_sum = [0 for i in range(len(subset))]    
    while col<m:
        row_ptr = 0    
        for row in range(n):
            if row > subset[row_ptr]:
                row_ptr += 1
            running_sum[row_ptr] += A[row][col]
            if running_sum[row_ptr] > k:
                col -= 1
                running_sum = [0 for i in range(len(subset))]
                cur_ans += 1
                break
                
        col += 1                
        if cur_ans >= ans:
          break
    ans = min(ans, cur_ans)
print(ans)

Buggy python submission (verdict: Runtime Error):
n, m, k = [int(i) for i in input().split()]

subsets = []
splits = [i for i in range(1, n)]
n -= 1
for i in range(2**n):
    x = []
    for j in range(n):
        if i&(1<<j):
            x.append(j)
    subsets.append(x)

n+=1

A = []
for i in range(n):
    A.append([int(j) for j in input()])
#print(A)

ans = n*m

def solve(mat, k):
    ret_val = 0
    running_sum = 0
    i = 0
    #print(mat)
    while i<len(mat[0]): # col
        
        for j in range(len(mat)): # row
            running_sum += mat[j][i]
        if running_sum > k:
            ret_val += 1
            #print(dict(adding_at=(j,i)))
            i -= 1
            running_sum = 0
        i += 1
    #print(mat, ret_val)    
    return ret_val                    
    

for subset in subsets:
    cur_ans = len(subset)
    #print(subset)
    tmp = []
    col = 0
    subset.append(1000000000)
    running_sum = [0 for i in range(len(subset)+1)]    
    while col<m:
        row_ptr = 0    
        for row in range(n):
            if row > subset[row_ptr] and row_ptr+1 < len(subset):
                row_ptr += 1
            #print(subset, row, row_ptr, running_sum)    
            running_sum[row_ptr] += A[row][col]
            if running_sum[row_ptr] > k:
                #print(dict(update_at = (row,col)), running_sum)
                col -= 1
                
                running_sum = [0 for i in range(len(subset))]
                cur_ans += 1
                
            
            
        col += 1                
    #print(subset, cur_ans)
    ans = min(ans, cur_ans)
print(ans)


Fixed submission:
n, m, k = [int(i) for i in input().split()]

subsets = []
splits = [i for i in range(1, n)]
n -= 1
for i in range(2**n):
    x = []
    for j in range(n):
        if i&(1<<j):
            x.append(j)
    subsets.append(x)
n+=1
A = []
for i in range(n):
    A.append([int(j) for j in input()])
ans = n*m
for subset in subsets:
    cur_ans = len(subset)
    tmp = []
    col = 0
    subset.append(100000)
    running_sum = [0 for i in range(len(subset))]    
    while col<m:
        row_ptr = 0    
        for row in range(n):
            if row > subset[row_ptr]:
                row_ptr += 1
            running_sum[row_ptr] += A[row][col]
            if running_sum[row_ptr] > k:
                col -= 1
                running_sum = [0 for i in range(len(subset))]
                cur_ans += 1
                break
                
        col += 1                
        if cur_ans >= ans:
          break
    ans = min(ans, cur_ans)
print(ans)