Ivan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classes at the university.

There are m working hours during each Berland day, and each lesson at the university lasts exactly one hour. If at some day Ivan's first lesson is during i-th hour, and last lesson is during j-th hour, then he spends j - i + 1 hours in the university during this day. If there are no lessons during some day, then Ivan stays at home and therefore spends 0 hours in the university.

Ivan doesn't like to spend a lot of time in the university, so he has decided to skip some lessons. He cannot skip more than k lessons during the week. After deciding which lessons he should skip and which he should attend, every day Ivan will enter the university right before the start of the first lesson he does not skip, and leave it after the end of the last lesson he decides to attend. If Ivan skips all lessons during some day, he doesn't go to the university that day at all.

Given n, m, k and Ivan's timetable, can you determine the minimum number of hours he has to spend in the university during one week, if he cannot skip more than k lessons?


-----Input-----

The first line contains three integers n, m and k (1 ≤ n, m ≤ 500, 0 ≤ k ≤ 500) — the number of days in the Berland week, the number of working hours during each day, and the number of lessons Ivan can skip, respectively.

Then n lines follow, i-th line containing a binary string of m characters. If j-th character in i-th line is 1, then Ivan has a lesson on i-th day during j-th hour (if it is 0, there is no such lesson).


-----Output-----

Print the minimum number of hours Ivan has to spend in the university during the week if he skips not more than k lessons.


-----Examples-----
Input
2 5 1
01001
10110

Output
5

Input
2 5 0
01001
10110

Output
8



-----Note-----

In the first example Ivan can skip any of two lessons during the first day, so he spends 1 hour during the first day and 4 hours during the second day.

In the second example Ivan can't skip any lessons, so he spends 4 hours every day.

Difficulty: interview

Starter code:

Solutions:
n, m, k = input().split(' ')
n = int(n)
m = int(m)
k = int(k)
ind = []
pre = []

for _ in range(n):
    s = input()
    ind.append([])
    for i, c in enumerate(s):
        if c == '1':
            ind[-1].append(i)

for i in range(n):
    pre.append([])
    for j in range(k + 1):
        pre[i].append([])
        if len(ind[i]) > j:
            pre[i][j] = ind[i][-1] - ind[i][0] + 1
        else:
            pre[i][j] = 0
            continue
        for x in range(j + 1):
            y = len(ind[i]) - 1 - j + x

            if y >= x and ind[i][y] - ind[i][x] + 1 < pre[i][j]:
                pre[i][j] = ind[i][y] - ind[i][x] + 1
dp = [[]]

for i in range(k + 1):
    dp[0].append(pre[0][i])


for i in range(1, n):
    dp.append([])
    for j in range(0, k + 1):
        dp[i].append(pre[i][j] + dp[i - 1][0])
        for z in range(j + 1):
            dp[i][j] = min(dp[i][j], dp[i - 1][z] + pre[i][j - z])

print(dp[n - 1][k])


import queue
intput = lambda:list(map(int, input().split()))

N, M, K = intput()
ht = [[] for _ in range(N)]
for _ in range(N):
    day = input()
    ht[_] = [i for i in range(M) if day[i] == '1']

# req[i][j] -- required hours for day i if j lessons skipped
# dp[i][j] -- required hours up to day i if j lesson skipped
# dp[i+1][j+z] = dp[i][j] + req[i][z]

tc = [1,2,3,8,9]
# just return dp[-1][-1]
req = [[0 for _ in range(M+1)] for __ in range(N)]
dp = [[0 for _ in range(K+1)] for __ in range(N)]
for i in range(N):
    # cost to skip j lessons today
    for j in range(len(ht[i])):
        req[i][j] = ht[i][-1] - ht[i][0] + 1  # default large num
        # if start at the first-th lesson
        for first in range(j+1):
            last = first + len(ht[i])-j-1
            cost = ht[i][last]-ht[i][first]+1
            if last >= first:
                req[i][j] = min(req[i][j], cost)

for i in range(min(len(req[0]), len(dp[0]))):
    dp[0][i] = req[0][i]
for i in range(1, N):
    # total skipped up to this point
    for j in range(K+1):
        dp[i][j] = dp[i-1][j] + req[i][0]
        # additional skipped for this day -- min of (skips left, curr skips, num lessons)
        for z in range(1+min(j, len(ht[i]))):
            dp[i][j] = min(dp[i][j], dp[i-1][j-z] + req[i][z])

# print('{}\n{}'.format(req,dp))
print(dp[-1][-1])


R = lambda: map(int, input().split())
n, m, k = R()
cls = [list(i for i, x in enumerate(map(int, input())) if x) for _ in range(n)]
dp = [[n * m] * (k + 1) for i in range(n + 1)]
dp.append([0] * (k + 1))
for i in range(n):
    row = cls[i]
    c2l = [m + 1] * (m + 1)
    c2l[0] = row[-1] - row[0] + 1 if row else 0
    c2l[len(row)] = 0
    for r in range(len(row)):
        for l in range(r + 1):
            c2l[len(row) - (r - l + 1)] = min(c2l[len(row) - (r - l + 1)], row[r] - row[l] + 1)
    for j in range(k + 1):
        for c, l in enumerate(c2l):
            if j + c <= k and l < m + 1:
                dp[i][j] = min(dp[i][j], dp[i - 1][j + c] + l)
print(min(dp[n - 1]))

def min_sub_array(day, k):
    if not day:
        return [0] * (k + 1)
    n = len(day)
    best = [float('inf')] * (n + 1)
    best[0] = 0
    best[1] = 1
    for size in range(2, n + 1):
        for i in range(n + 1 - size):
            best[size] = min(best[size], day[i + size - 1] - day[i] + 1)
    output = [0] * (k + 1)
    for i in range(k + 1):
        if n - i > 0:
            output[i] = best[n - i]
    return output


N, M, K = list(map(int, input().split()))

day = [i for i, val in enumerate(input()) if val == '1']
best = min_sub_array(day, K)

for _ in range(N - 1):
    day = [i for i, val in enumerate(input()) if val == '1']
    new_day_best = min_sub_array(day, K)

    new_best = [float('inf')] * (K + 1)
    for i in range(K + 1):
        for j in range(i + 1):
            new_best[i] = min(new_best[i], new_day_best[j] + best[i - j])
    best = new_best
print(best[K])


import sys
input = sys.stdin.readline

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()
from collections import Counter
import math
import bisect
from collections import deque
n,m,lesson=int_array()
dp=[[250005 for i in range(lesson+2)]for j in range(n+1)]
days=[[] for i in range(n)]
for i in range(n):
	s=input()
	for  j in range(m):
		if s[j]=="1":
			days[i].append(j+1)

m=[[250005 for i in range(lesson+2)]for j in range(n+1)]
for i in range(n):
	for j in range(lesson+1):
		if j<=len(days[i]):
			if j==len(days[i]):
				m[i][j]=0
				continue
			else:
				for k  in range(0,j+1):
					var=days[i][0+k]
					var1=days[i][-1*max(1,1+(j-k))]
					m[i][j]=min(m[i][j],var1-var+1)



for i in range(lesson+1):
	dp[0][i]=m[0][i]
for i in range(1,n):
	for j in range(lesson+1):
		for k in range(j+1):

			dp[i][j]=min(dp[i][j],dp[i-1][j-k]+m[i][k])
			#dp[i][j] = min(dp[i][j], dp[i - 1][k]+m[i][j-k])

print(min(dp[n-1]))



import sys

n, m, k = list(map(int, input().split()))
table = [input() for _ in range(n)]

dp = [0]*(k+1)

for a in table:
    one = []
    for i in range(m):
        if a[i] == '1':
            one.append(i)

    if not one:
        continue

    ni = len(one)
    subdp = [10**9] * (ni+1)
    subdp[-1] = 0

    for i in range(ni):
        for j in range(i, ni):
            subdp[ni-(j-i+1)] = min(subdp[ni-(j-i+1)], one[j]-one[i]+1)

    next_dp = [10**9]*(k+1)
    for i in range(k, -1, -1):
        for j in range(ni+1):
            if i+j > k:
                break
            next_dp[i+j] = min(next_dp[i+j], dp[i] + subdp[j])
    dp = next_dp

print(min(dp))