r=range

h,*s=open(0)

h,w,k,*m=list(map(int,h.split()))

for i in r(512):

 t=[j+1for j in r(h)if i>>j&1]+[h];l=len(t);v=1;c=[0]*l

 for i in r(w):

  b=f=g=0;u=[]

  for j in r(l):d,b=sum(s[j][i]>"0"for j in r(b,t[j])),t[j];u+=d,;g|=d>k;c[j]+=d;f|=c[j]>k

  v-=f

  if f:c=u

 if g<1:m+=l-v,

print((min(m)))
x,*s=open(0)

h,w,k,*m=list(map(int,x.split()))

for b in range(512):

 r=t=j=0;d=[0]*h

 while w-j:

  i=c=0

  while h-i:

   d[c]+=s[i][j]>'0';x=d[c]>k

   if(t<j)&x:r+=1;t=j;d=[0]*h;break

   r+=h*w*x;c+=b>>i&1;i+=1

  else:j+=1

 m+=r+bin(b).count('1'),

print((min(m)))
r = range
h, *s = open(0)
h, w, k, *m = list(map(int, h.split()))
for i in r(512):
    t = [j + 1 for j in r(h) if i >> j & 1] + [h]
    l = len(t)
    v = 1
    c = [0] * l
    for i in r(w):
        b = f = g = 0
        u = []
        for j in r(l):
            d, b = sum(s[j][i] > "0" for j in r(b, t[j])), t[j]
            u += (d,)
            g |= d > k
            c[j] += d
            f |= c[j] > k
        v -= f
        if f:
            c = u
    if g < 1:
        m += (l - v,)
print((min(m)))

x, *s = open(0)
h, w, k, *m = list(map(int, x.split()))
for b in range(512):
    r = t = j = 0
    d = [0] * h
    while w - j:
        i = c = 0
        while h - i:
            d[c] += s[i][j] > "0"
            x = d[c] > k
            if (t < j) & x:
                r += 1
                t = j
                d = [0] * h
                break
            r += h * w * x
            c += b >> i & 1
            i += 1
        else:
            j += 1
    m += (r + bin(b).count("1"),)
print((min(m)))

-r = range -h, *s = open(0) -h, w, k, *m = list(map(int, h.split())) -for i in r(512): -    t = [j + 1 for j in r(h) if i >> j & 1] + [h] -    l = len(t) -    v = 1 -    c = [0] * l -    for i in r(w): -        b = f = g = 0 -        u = [] -        for j in r(l): -            d, b = sum(s[j][i] > "0" for j in r(b, t[j])), t[j] -            u += (d,) -            g |= d > k -            c[j] += d -            f |= c[j] > k -        v -= f -        if f: -            c = u -    if g < 1: -        m += (l - v,) +x, *s = open(0) +h, w, k, *m = list(map(int, x.split())) +for b in range(512): +    r = t = j = 0 +    d = [0] * h +    while w - j: +        i = c = 0 +        while h - i: +            d[c] += s[i][j] > "0" +            x = d[c] > k +            if (t < j) & x: +                r += 1 +                t = j +                d = [0] * h +                break +            r += h * w * x +            c += b >> i & 1 +            i += 1 +        else: +            j += 1 +    m += (r + bin(b).count("1"),)