use std::cmp::min;
use std::io;
use std::io::Stdin;
use std::str::FromStr;

fn read_line(stdin : &Stdin, line : &mut String) {
    match stdin.read_line(line) {
        Ok(_) => return,
        Err(msg) => panic!("Could not read line! Message: {}.", msg),
    }
}

fn parse_t<T : FromStr>(s : &str) -> T {
    match s.trim().parse() {
        Ok(y) => y,
        Err(_) => panic!("Could not read from string!"),
    }
}

fn read_ts<T : FromStr>(stdin : &Stdin, ts : &mut Vec<T>) {
    let mut line = String::new();
    read_line(stdin, &mut line);
    let word_iter = line.split_whitespace();
    for word in word_iter {
        let x = parse_t(word);
        ts.push(x);
    }
}

fn read_day_schedule(stdin : &Stdin, day_schedule : &mut Vec<usize>) {
    let zero_one = "01".as_bytes();
    let zero = zero_one[0];
    let one = zero_one[1];
    let mut str_schedule = String::new();
    read_line(&stdin, &mut str_schedule);
    let mut hour = 1;
    for &b in str_schedule.trim().as_bytes().iter() {
        if b == zero {
            // Do nothing ...
        } else if b == one {
            day_schedule.push(hour);
        } else {
            panic!("Unknown character in day schedule.");
        }
        hour = hour + 1;
    }
}

fn read_week_schedule(n : usize,
                      stdin : &Stdin,
                      week_schedule : &mut Vec<Vec<usize>>) {
    for _ in 0 .. n {
        let mut day_schedule = vec![];
        read_day_schedule(&stdin, &mut day_schedule);
        week_schedule.push(day_schedule);
    }
}

// Computes the optimal hours at school for a skip with
// given start and end hour.
fn optimal_skip_for_start_end(day_schedule : &Vec<usize>,
                              start_idx : usize,
                              end_idx : usize,
                              interval_set : &mut Vec<Vec<bool>>,
                              current_min : usize,
                              optimal_intervals : &mut Vec<(usize, usize)>) -> usize {
    // If you are attending a single class, then skipping it
    // means, you don't have to go to school.
    if start_idx == end_idx {
        optimal_intervals.clear();
        0
    } else {
        // Note that we reduce time spent at school, by only
        // skipping the first/last class.
        let skip_start_idx = start_idx + 1;
        let skip_end_idx = end_idx - 1;
        let start = day_schedule[start_idx];
        let start_after_skip = day_schedule[skip_start_idx];
        let end = day_schedule[end_idx];
        let end_after_skip = day_schedule[skip_end_idx];
        let skip_start_hours = end - start_after_skip + 1;
        let skip_end_hours = end_after_skip - start + 1;
        if skip_start_hours < skip_end_hours {
            if skip_start_hours < current_min {
                // optimal_intervals.clear();
                optimal_intervals.push((skip_start_idx, end_idx));
                interval_set[skip_start_idx][end_idx] = true;
            } else if skip_start_hours == current_min {
                if interval_set[skip_start_idx][end_idx] {
                    // Do nothing ...
                } else {
                    optimal_intervals.push((skip_start_idx, end_idx));
                    interval_set[skip_start_idx][end_idx] = true;
                }
            } else {
                // Do nothing ...
            }
            skip_start_hours
        } else if skip_start_hours > skip_end_hours {
            if skip_end_hours < current_min {
                // optimal_intervals.clear();
                optimal_intervals.push((start_idx, skip_end_idx));
                interval_set[start_idx][skip_end_idx] = true;
            } else if skip_end_hours == current_min {
                if interval_set[start_idx][skip_end_idx] {
                    // Do nothing ...
                } else {
                    optimal_intervals.push((start_idx, skip_end_idx));
                    interval_set[start_idx][skip_end_idx] = true;
                }
            } else {
                // Do nothing ...
            }
            skip_end_hours
        } else {
            if skip_start_hours < current_min {
                // optimal_intervals.clear();
                optimal_intervals.push((skip_start_idx, end_idx));
                interval_set[skip_start_idx][end_idx] = true;
                optimal_intervals.push((start_idx, skip_end_idx));
                interval_set[start_idx][skip_end_idx] = true;
            } else if skip_start_hours == current_min {
                if interval_set[skip_start_idx][end_idx] {
                    // Do nothing ...
                } else {
                    optimal_intervals.push((skip_start_idx, end_idx));
                    interval_set[skip_start_idx][end_idx] = true;
                }
                if interval_set[start_idx][skip_end_idx] {
                    // Do nothing ...
                } else {
                    optimal_intervals.push((start_idx, skip_end_idx));
                    interval_set[start_idx][skip_end_idx] = true;
                }
            } else {
                // Do nothing ...
            }
            skip_start_hours
        }
    }
}

const INFINITY : usize = usize::max_value();

fn optimal_skips_for_day(k : usize,
                         m : usize,
                         day_schedule : &Vec<usize>,
                         hours_at_school : &mut Vec<usize>) {
    // If there are no classes on a day, then hours at school
    // is 0 for all skips.
    if day_schedule.is_empty() {
        let k_plus_1 = k + 1;
        for _ in 0 .. k_plus_1 {
            hours_at_school.push(0);
        }
    } else {
        let start_idx = 0;
        let end_idx = day_schedule.len() - 1;
        let hours_no_skip = day_schedule[end_idx] - day_schedule[start_idx] + 1;
        hours_at_school.push(hours_no_skip);
        let mut num_skips = 1;
        let mut interval_set = vec![];
        let m_plus_1 = m + 1;
        for _ in 0 .. m_plus_1 {
            let bit_vector = vec![false; m_plus_1];
            interval_set.push(bit_vector);
        }
        let mut optimal_intervals_for_k = vec![];
        optimal_intervals_for_k.push((start_idx, end_idx));
        loop {
            if num_skips > k {
                break;
            } else {
                if optimal_intervals_for_k.is_empty() {
                    hours_at_school.push(0);
                } else {
                    let mut optimal_intervals_for_k_plus_1 = vec![];
                    let mut current_min = INFINITY;
                    for &(s, e) in optimal_intervals_for_k.iter() {
                        current_min = optimal_skip_for_start_end(day_schedule,
                                                                 s,
                                                                 e,
                                                                 &mut interval_set,
                                                                 current_min,
                                                                 &mut optimal_intervals_for_k_plus_1);
                    }
                    if current_min == INFINITY {
                        hours_at_school.push(0);
                    } else {
                        hours_at_school.push(current_min);
                    }
                    optimal_intervals_for_k = optimal_intervals_for_k_plus_1;
                }
            }
            num_skips = num_skips + 1;
        }
    }
}

fn update_min_hours_so_far(k : usize,
                           hours_at_school : &Vec<usize>,
                           min_hours_so_far : &Vec<usize>,
                           new_min_hours_so_far : &mut Vec<usize>) {
    let k_plus_1 = k + 1;
    for i in 0 .. k_plus_1 {
        let i_plus_1 = i + 1;
        for j in 0 .. i_plus_1 {
            let i_minus_j = i - j;
            let x = hours_at_school[j] + min_hours_so_far[i_minus_j];
            new_min_hours_so_far[i] = min(x, new_min_hours_so_far[i]);
        }
    }
}

fn min_hours_at_school(n : usize,
                       m : usize,
                       k : usize,
                       week_schedule : &Vec<Vec<usize>>) -> usize {
    let mut min_hours_so_far = vec![];
    optimal_skips_for_day(k, m, &(week_schedule[0]), &mut min_hours_so_far);
    for i in 1 .. n {
        let mut hours_at_school = vec![];
        optimal_skips_for_day(k, m, &(week_schedule[i]), &mut hours_at_school);
        // println!("{} -> {:?}", i, hours_at_school);
        let mut new_min_hours_so_far = vec![INFINITY; k + 1];
        update_min_hours_so_far(k,
                                &hours_at_school,
                                &min_hours_so_far,
                                &mut new_min_hours_so_far);
        min_hours_so_far = new_min_hours_so_far;
    }
    min_hours_so_far[k]
}

fn main() {
    let stdin = io::stdin();
    let mut n_m_k : Vec<usize> = vec![];
    read_ts(&stdin, &mut n_m_k);
    // println!("n_m_k = {:?}", n_m_k);
    let n = n_m_k[0];
    let m = n_m_k[1];
    let k = n_m_k[2];
    let mut week_schedule = vec![];
    read_week_schedule(n, &stdin, &mut week_schedule);
    // println!("{:?}", week_schedule);
    let min_hours = min_hours_at_school(n, m, k, &week_schedule);
    println!("{}", min_hours);
}


use std::cmp::min;
use std::io;
use std::io::Stdin;
use std::str::FromStr;

fn read_line(stdin : &Stdin, line : &mut String) {
    match stdin.read_line(line) {
        Ok(_) => return,
        Err(msg) => panic!("Could not read line! Message: {}.", msg),
    }
}

fn parse_t<T : FromStr>(s : &str) -> T {
    match s.trim().parse() {
        Ok(y) => y,
        Err(_) => panic!("Could not read from string!"),
    }
}

fn read_ts<T : FromStr>(stdin : &Stdin, ts : &mut Vec<T>) {
    let mut line = String::new();
    read_line(stdin, &mut line);
    let word_iter = line.split_whitespace();
    for word in word_iter {
        let x = parse_t(word);
        ts.push(x);
    }
}

fn read_day_schedule(stdin : &Stdin, day_schedule : &mut Vec<usize>) {
    let zero_one = "01".as_bytes();
    let zero = zero_one[0];
    let one = zero_one[1];
    let mut str_schedule = String::new();
    read_line(&stdin, &mut str_schedule);
    let mut hour = 1;
    for &b in str_schedule.trim().as_bytes().iter() {
        if b == zero {
            // Do nothing ...
        } else if b == one {
            day_schedule.push(hour);
        } else {
            panic!("Unknown character in day schedule.");
        }
        hour = hour + 1;
    }
}

fn read_week_schedule(n : usize,
                      stdin : &Stdin,
                      week_schedule : &mut Vec<Vec<usize>>) {
    for _ in 0 .. n {
        let mut day_schedule = vec![];
        read_day_schedule(&stdin, &mut day_schedule);
        week_schedule.push(day_schedule);
    }
}

/*
fn is_palindrome(day_schedule : &Vec<usize>) -> bool {
    if day_schedule.is_empty() {
        return true;
    }
    let mut s = 0;
    let mut e = day_schedule.len() - 1;
    let mut done = false;
    loop {
        if done {
            break;
        } else {
            if s >= e {
                done = true;
            } else {
                if day_schedule[s] == day_schedule[e] {
                    s = s + 1;
                    e = e - 1;
                } else {
                    return false;
                }
            }
        }

    }
    true
}
*/

fn is_palindrome(day_schedule : &Vec<usize>) -> bool {
    let mut day_schedule_copy = day_schedule.clone();
    day_schedule_copy.reverse();
    (*day_schedule) == day_schedule_copy
}

// Computes the optimal hours at school for a skip with
// given start and end hour.
fn optimal_skip_for_start_end(day_schedule : &Vec<usize>,
                              start_idx : usize,
                              end_idx : usize) -> (usize, usize, usize) {
    // If you are attending a single class, then skipping it
    // means, you don't have to go to school.
    if start_idx == end_idx {
        (0, start_idx, end_idx)
    } else {
        // Note that we reduce time spent at school, by only
        // skipping the first/last class.
        // Try skipping the first class.
        let skip_start_idx = start_idx + 1;
        let skip_end_idx = end_idx - 1;
        let start = day_schedule[start_idx];
        let start_after_skip = day_schedule[skip_start_idx];
        let end = day_schedule[end_idx];
        let end_after_skip = day_schedule[skip_end_idx];
        let skip_start_hours = end - start_after_skip + 1;
        let skip_end_hours = end_after_skip - start + 1;
        if skip_start_hours < skip_end_hours {
            (skip_start_hours, skip_start_idx, end_idx)
        } else if skip_start_hours > skip_end_hours {
            (skip_end_hours, start_idx, skip_end_idx)
        } else {
            let mut zero_one_day_schedule = vec![0; end - start + 1];
            for i in start_idx .. (end_idx + 1) {
                zero_one_day_schedule[day_schedule[i] - start] = 1;
            }
            if (day_schedule.len() < 500) || is_palindrome(&zero_one_day_schedule) {
                (skip_start_hours, skip_start_idx, end_idx)
            } else {
                println!("(not palindrome) && (skip_start_hours == skip_end_hours).");
                panic!("(not palindrome) && (skip_start_hours == skip_end_hours).");
            }
        }
    }
}

fn optimal_skips_for_day(k : usize,
                         day_schedule : &Vec<usize>,
                         hours_at_school : &mut Vec<usize>) {
    // If there are no classes on a day, then hours at school
    // is 0 for all skips.
    if day_schedule.is_empty() {
        let k_plus_1 = k + 1;
        for _ in 0 .. k_plus_1 {
            hours_at_school.push(0);
        }
    } else {
        let mut done = false;
        let mut start_idx = 0;
        let mut end_idx = day_schedule.len() - 1;
        let hours_no_skip = day_schedule[end_idx] - day_schedule[start_idx] + 1;
        hours_at_school.push(hours_no_skip);
        let mut num_skips = 1;
        loop {
            if num_skips > k {
                break;
            } else {
                if start_idx == end_idx {
                    if done {
                        hours_at_school.push(0);
                    } else {
                        let (optimal_hours, new_start_idx, new_end_idx) =
                            optimal_skip_for_start_end(day_schedule,
                                                       start_idx,
                                                       end_idx);
                        hours_at_school.push(optimal_hours);
                        start_idx = new_start_idx;
                        end_idx = new_end_idx;
                        done = true;
                    }
                } else {
                    let (optimal_hours, new_start_idx, new_end_idx) =
                        optimal_skip_for_start_end(day_schedule,
                                                   start_idx,
                                                   end_idx);
                    hours_at_school.push(optimal_hours);
                    start_idx = new_start_idx;
                    end_idx = new_end_idx;
                }
            }
            num_skips = num_skips + 1;
        }
    }
}

fn update_min_hours_so_far(k : usize,
                           hours_at_school : &Vec<usize>,
                           min_hours_so_far : &Vec<usize>,
                           new_min_hours_so_far : &mut Vec<usize>) {
    let k_plus_1 = k + 1;
    for i in 0 .. k_plus_1 {
        let i_plus_1 = i + 1;
        for j in 0 .. i_plus_1 {
            let i_minus_j = i - j;
            let x = hours_at_school[j] + min_hours_so_far[i_minus_j];
            new_min_hours_so_far[i] = min(x, new_min_hours_so_far[i]);
        }
    }
}

const INFINITY : usize = usize::max_value();

fn min_hours_at_school(n : usize,
                       k : usize,
                       week_schedule : &Vec<Vec<usize>>) -> usize {
    let mut min_hours_so_far = vec![];
    optimal_skips_for_day(k, &(week_schedule[0]), &mut min_hours_so_far);
    for i in 1 .. n {
        let mut hours_at_school = vec![];
        optimal_skips_for_day(k, &(week_schedule[i]), &mut hours_at_school);
        // println!("{} -> {:?}", i, hours_at_school);
        let mut new_min_hours_so_far = vec![INFINITY; k + 1];
        update_min_hours_so_far(k,
                                &hours_at_school,
                                &min_hours_so_far,
                                &mut new_min_hours_so_far);
        min_hours_so_far = new_min_hours_so_far;
    }
    min_hours_so_far[k]
}

fn main() {
    let stdin = io::stdin();
    let mut n_m_k : Vec<usize> = vec![];
    read_ts(&stdin, &mut n_m_k);
    // println!("n_m_k = {:?}", n_m_k);
    let n = n_m_k[0];
    let k = n_m_k[2];
    let mut week_schedule = vec![];
    read_week_schedule(n, &stdin, &mut week_schedule);
    // println!("{:?}", week_schedule);
    let min_hours = min_hours_at_school(n, k, &week_schedule);
    println!("{}", min_hours);
}


use std::cmp::min;
use std::io;
use std::io::Stdin;
use std::str::FromStr;

fn read_line(stdin : &Stdin, line : &mut String) {
    match stdin.read_line(line) {
        Ok(_) => return,
        Err(msg) => panic!("Could not read line! Message: {}.", msg),
    }
}

fn parse_t<T : FromStr>(s : &str) -> T {
    match s.trim().parse() {
        Ok(y) => y,
        Err(_) => panic!("Could not read from string!"),
    }
}

fn read_ts<T : FromStr>(stdin : &Stdin, ts : &mut Vec<T>) {
    let mut line = String::new();
    read_line(stdin, &mut line);
    let word_iter = line.split_whitespace();
    for word in word_iter {
        let x = parse_t(word);
        ts.push(x);
    }
}

fn read_day_schedule(stdin : &Stdin, day_schedule : &mut Vec<usize>) {
    let zero_one = "01".as_bytes();
    let zero = zero_one[0];
    let one = zero_one[1];
    let mut str_schedule = String::new();
    read_line(&stdin, &mut str_schedule);
    let mut hour = 1;
    for &b in str_schedule.trim().as_bytes().iter() {
        if b == zero {
            // Do nothing ...
        } else if b == one {
            day_schedule.push(hour);
        } else {
            panic!("Unknown character in day schedule.");
        }
        hour = hour + 1;
    }
}

fn read_week_schedule(n : usize,
                      stdin : &Stdin,
                      week_schedule : &mut Vec<Vec<usize>>) {
    for _ in 0 .. n {
        let mut day_schedule = vec![];
        read_day_schedule(&stdin, &mut day_schedule);
        week_schedule.push(day_schedule);
    }
}

fn is_palindrome(day_schedule : &Vec<usize>,
                 start_idx : usize,
                 end_idx : usize) -> bool {
    let mut s = start_idx;
    let mut e = end_idx;
    let mut done = false;
    loop {
        if done {
            break;
        } else {
            if s >= e {
                done = true;
            } else {
                if day_schedule[s] == day_schedule[e] {
                    s = s + 1;
                    e = e - 1;
                } else {
                    return false;
                }
            }
        }

    }
    true
}

// Computes the optimal hours at school for a skip with
// given start and end hour.
fn optimal_skip_for_start_end(day_schedule : &Vec<usize>,
                              start_idx : usize,
                              end_idx : usize) -> (usize, usize, usize) {
    // If you are attending a single class, then skipping it
    // means, you don't have to go to school.
    if start_idx == end_idx {
        (0, start_idx, end_idx)
    } else {
        // Note that we reduce time spent at school, by only
        // skipping the first/last class.
        // Try skipping the first class.
        let skip_start_idx = start_idx + 1;
        let skip_end_idx = end_idx - 1;
        let start = day_schedule[start_idx];
        let start_after_skip = day_schedule[skip_start_idx];
        let end = day_schedule[end_idx];
        let end_after_skip = day_schedule[skip_end_idx];
        let skip_start_hours = end - start_after_skip + 1;
        let skip_end_hours = end_after_skip - start + 1;
        if skip_start_hours < skip_end_hours {
            (skip_start_hours, skip_start_idx, end_idx)
        } else if skip_start_hours > skip_end_hours {
            (skip_end_hours, start_idx, skip_end_idx)
        } else {
            let mut zero_one_day_schedule = vec![0; end_idx - start_idx + 1];
            for i in start_idx .. (end_idx + 1) {
                zero_one_day_schedule[i] = 1;
            }
            if is_palindrome(&zero_one_day_schedule, start_idx, end_idx) {
                (skip_start_hours, skip_start_idx, end_idx)
            } else {
                println!("(not palindrome) && (skip_start_hours == skip_end_hours).");
                panic!("(not palindrome) && (skip_start_hours == skip_end_hours).");
            }
        }
    }
}

fn optimal_skips_for_day(k : usize,
                         day_schedule : &Vec<usize>,
                         hours_at_school : &mut Vec<usize>) {
    // If there are no classes on a day, then hours at school
    // is 0 for all skips.
    if day_schedule.is_empty() {
        let k_plus_1 = k + 1;
        for _ in 0 .. k_plus_1 {
            hours_at_school.push(0);
        }
    } else {
        let mut done = false;
        let mut start_idx = 0;
        let mut end_idx = day_schedule.len() - 1;
        let hours_no_skip = day_schedule[end_idx] - day_schedule[start_idx] + 1;
        hours_at_school.push(hours_no_skip);
        let mut num_skips = 1;
        loop {
            if num_skips > k {
                break;
            } else {
                if start_idx == end_idx {
                    if done {
                        hours_at_school.push(0);
                    } else {
                        let (optimal_hours, new_start_idx, new_end_idx) =
                            optimal_skip_for_start_end(day_schedule,
                                                       start_idx,
                                                       end_idx);
                        hours_at_school.push(optimal_hours);
                        start_idx = new_start_idx;
                        end_idx = new_end_idx;
                        done = true;
                    }
                } else {
                    let (optimal_hours, new_start_idx, new_end_idx) =
                        optimal_skip_for_start_end(day_schedule,
                                                   start_idx,
                                                   end_idx);
                    hours_at_school.push(optimal_hours);
                    start_idx = new_start_idx;
                    end_idx = new_end_idx;
                }
            }
            num_skips = num_skips + 1;
        }
    }
}

fn update_min_hours_so_far(k : usize,
                           hours_at_school : &Vec<usize>,
                           min_hours_so_far : &Vec<usize>,
                           new_min_hours_so_far : &mut Vec<usize>) {
    let k_plus_1 = k + 1;
    for i in 0 .. k_plus_1 {
        let i_plus_1 = i + 1;
        for j in 0 .. i_plus_1 {
            let i_minus_j = i - j;
            let x = hours_at_school[j] + min_hours_so_far[i_minus_j];
            new_min_hours_so_far[i] = min(x, new_min_hours_so_far[i]);
        }
    }
}

const INFINITY : usize = usize::max_value();

fn min_hours_at_school(n : usize,
                       k : usize,
                       week_schedule : &Vec<Vec<usize>>) -> usize {
    let mut min_hours_so_far = vec![];
    optimal_skips_for_day(k, &(week_schedule[0]), &mut min_hours_so_far);
    for i in 1 .. n {
        let mut hours_at_school = vec![];
        optimal_skips_for_day(k, &(week_schedule[i]), &mut hours_at_school);
        // println!("{} -> {:?}", i, hours_at_school);
        let mut new_min_hours_so_far = vec![INFINITY; k + 1];
        update_min_hours_so_far(k,
                                &hours_at_school,
                                &min_hours_so_far,
                                &mut new_min_hours_so_far);
        min_hours_so_far = new_min_hours_so_far;
    }
    min_hours_so_far[k]
}

fn main() {
    let stdin = io::stdin();
    let mut n_m_k : Vec<usize> = vec![];
    read_ts(&stdin, &mut n_m_k);
    // println!("n_m_k = {:?}", n_m_k);
    let n = n_m_k[0];
    let k = n_m_k[2];
    let mut week_schedule = vec![];
    read_week_schedule(n, &stdin, &mut week_schedule);
    // println!("{:?}", week_schedule);
    let min_hours = min_hours_at_school(n, k, &week_schedule);
    println!("{}", min_hours);
}


package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
)

const (
  INF = 1234567890
)

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	M := io.NextInt()
	K := io.NextInt()

	S := make([]string, N)
	for i := range S {
	  S[i] = io.NextLine()
	}

	skips := MakeIntMatrix(N, M + 1)
	for ln, line := range S {
	  total := 0
	  for _, c := range line {
	    if c == '1' {
	      total++
	    }
	  }
	 // fmt.Printf("ln = %d, line = %s, total = %d\n", ln, line, total)
	  FillIntArray(skips[ln], INF)
	  for i := 0; i < M; i++ {
	    classes := 0
	    for j := i; j < M; j++ {
	      if line[j] == '1' {
	        classes++
	        skipped := total - classes
	       // fmt.Println(i, j, total, classes, skipped)
	        skips[ln][skipped] = Min(skips[ln][skipped], j - i + 1)
	      }
	    }
	  }
	  for i := 0; i <= M; i++ {
	    if skips[ln][i] == INF {
	      skips[ln][i] = 0
	    }
	  }
    // fmt.Println(ln, skips[ln])
	}

	dp := make([]int, K + 1)
	FillIntArray(dp, INF)
	dp[0] = 0
	for i := 0; i < N; i++ {
	  next := make([]int, K + 1)
	  FillIntArray(next, INF)
	  for j := 0; j <= K; j++ {
	    for k := 0; j + k <= K && k <= M; k++ {
	     // fmt.Println(i, j, k, len(skips), len(dp), len(next))
	      next[j + k] = Min(next[j + k], dp[j] + skips[i][k])
	     // fmt.Printf("i = %d, j = %d, k = %d, next = %d\n", i, j, k, next[j + k])
	    }
	  }
	  dp = next
	 // fmt.Println(i, dp)
	}

	best := INF
	for i := 0; i <= K; i++ {
	  best = Min(best, dp[i])
	}
	io.Println(best)
}

func MakeIntMatrix(rows, cols int) [][]int {
	mat := make([][]int, rows)
	for i := range mat {
		mat[i] = make([]int, cols)
	}
	return mat
}

func Min(args ...int) int {
	min := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] < min {
			min = args[i]
		}
	}
	return min
}

func FillIntArray(arr []int, val int) {
	for i := range arr {
		arr[i] = val
	}
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}


package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
)

const (
  INF = 1234567890
)

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	M := io.NextInt()
	K := io.NextInt()

	S := make([]string, N)
	for i := range S {
	  S[i] = io.NextLine()
	}

	skips := MakeIntMatrix(N, M + 1)
	for ln, line := range S {
	  total := 0
	  for _, c := range line {
	    if c == '1' {
	      total++
	    }
	  }
	 // fmt.Printf("ln = %d, line = %s, total = %d\n", ln, line, total)
	  FillIntArray(skips[ln], INF)
	  for i := 0; i < M; i++ {
	    classes := 0
	    for j := i; j < M; j++ {
	      if line[j] == '1' {
	        classes++
	        skipped := total - classes
	       // fmt.Println(i, j, total, classes, skipped)
	        skips[ln][skipped] = Min(skips[ln][skipped], j - i + 1)
	      }
	    }
	  }
	  for i := 0; i <= M; i++ {
	    if skips[ln][i] == INF {
	      skips[ln][i] = 0
	    }
	  }
    // fmt.Println(ln, skips[ln])
	}

	dp := make([]int, K + 1)
	FillIntArray(dp, INF)
	dp[0] = 0
	for i := 0; i < N; i++ {
	  next := make([]int, K + 1)
	  FillIntArray(next, INF)
	  for j := 0; j <= M && j <= K; j++ {
	    for k := 0; j + k <= K; k++ {
	      next[j + k] = Min(next[j + k], dp[j] + skips[i][k])
	     // fmt.Printf("i = %d, j = %d, k = %d, next = %d\n", i, j, k, next[j + k])
	    }
	  }
	  dp = next
	 // fmt.Println(i, dp)
	}

	best := INF
	for i := 0; i <= K; i++ {
	  best = Min(best, dp[i])
	}
	io.Println(best)
}

func MakeIntMatrix(rows, cols int) [][]int {
	mat := make([][]int, rows)
	for i := range mat {
		mat[i] = make([]int, cols)
	}
	return mat
}

func Min(args ...int) int {
	min := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] < min {
			min = args[i]
		}
	}
	return min
}

func FillIntArray(arr []int, val int) {
	for i := range arr {
		arr[i] = val
	}
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}


package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
)

const (
  INF = 1234567890
)

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	M := io.NextInt()
	K := io.NextInt()

	S := make([]string, N)
	for i := range S {
	  S[i] = io.NextLine()
	}

	skips := MakeIntMatrix(N, M + 1)
	for ln, line := range S {
	  total := 0
	  for _, c := range line {
	    if c == '1' {
	      total++
	    }
	  }
	  FillIntArray(skips[ln], INF)
	  for i := 0; i < M; i++ {
	    classes := 0
	    for j := i; j < M; j++ {
	      if line[j] == '1' {
	        classes++
	        skipped := total - classes
	        skips[ln][skipped] = Min(skips[ln][skipped], j - i + 1)
	      }
	    }
	  }
	  for i := 0; i <= M; i++ {
	    if skips[ln][i] == INF {
	      skips[ln][i] = 0
	    }
	  }
	}

	dp := make([]int, K + 1)
	FillIntArray(dp, INF)
	dp[0] = 0
	for i := 0; i < N; i++ {
	  next := make([]int, K + 1)
	  FillIntArray(next, INF)
	  for j := 0; j <= K; j++ {
	    for k := 0; j + k <= K && k <= M; k++ {
	      next[j + k] = Min(next[j + k], dp[j] + skips[i][k])
	    }
	  }
	  dp = next
	}

	best := INF
	for i := 0; i <= K; i++ {
	  best = Min(best, dp[i])
	}
	io.Println(best)
}

func MakeIntMatrix(rows, cols int) [][]int {
	mat := make([][]int, rows)
	for i := range mat {
		mat[i] = make([]int, cols)
	}
	return mat
}

func Min(args ...int) int {
	min := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] < min {
			min = args[i]
		}
	}
	return min
}

func FillIntArray(arr []int, val int) {
	for i := range arr {
		arr[i] = val
	}
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}


package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
)

const (
  INF = 1234567890
)

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	M := io.NextInt()
	K := io.NextInt()

	S := make([]string, N)
	for i := range S {
	  S[i] = io.NextLine()
	}

	skips := MakeIntMatrix(N, M + 1)
	for ln, line := range S {
	  total := 0
	  for _, c := range line {
	    if c == '1' {
	      total++
	    }
	  }
	 // fmt.Printf("ln = %d, line = %s, total = %d\n", ln, line, total)
	  FillIntArray(skips[ln], INF)
	  for i := 0; i < M; i++ {
	    classes := 0
	    for j := i; j < M; j++ {
	      if line[j] == '1' {
	        classes++
	        skipped := total - classes
	       // fmt.Println(i, j, total, classes, skipped)
	        skips[ln][skipped] = Min(skips[ln][skipped], j - i + 1)
	      }
	    }
	  }
	  for i := 0; i <= M; i++ {
	    if skips[ln][i] == INF {
	      skips[ln][i] = 0
	    }
	  }
    // fmt.Println(ln, skips[ln])
	}

	dp := make([]int, K + 1)
	FillIntArray(dp, INF)
	dp[0] = 0
	for i := 0; i < N; i++ {
	  next := make([]int, K + 1)
	  FillIntArray(next, INF)
	  for j := 0; j <= M && j <= K; j++ {
	    for k := 0; j + k <= K && k <= M; k++ {
	     // fmt.Println(i, j, k, len(skips), len(dp), len(next))
	      next[j + k] = Min(next[j + k], dp[j] + skips[i][k])
	     // fmt.Printf("i = %d, j = %d, k = %d, next = %d\n", i, j, k, next[j + k])
	    }
	  }
	  dp = next
	 // fmt.Println(i, dp)
	}

	best := INF
	for i := 0; i <= K; i++ {
	  best = Min(best, dp[i])
	}
	io.Println(best)
}

func MakeIntMatrix(rows, cols int) [][]int {
	mat := make([][]int, rows)
	for i := range mat {
		mat[i] = make([]int, cols)
	}
	return mat
}

func Min(args ...int) int {
	min := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] < min {
			min = args[i]
		}
	}
	return min
}

func FillIntArray(arr []int, val int) {
	for i := range arr {
		arr[i] = val
	}
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}


package main

import (
	"bufio"
	"fmt"
	"os"
)

const (
	MaxN = 512
	MaxK = 512
	Inf  = MaxN * MaxK
)

var n, m, k int
var f, dp [MaxN][MaxK]int

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d %d %d\n", &n, &m, &k)
	for i := 0; i < n; i++ {
		var tmp string
		fmt.Fscanf(buf, "%s\n", &tmp)
		t := make([]int, 0)
		for j := 0; j < m; j++ {
			if tmp[j] == '1' {
				t = append(t, j)
			}
		}
		tlen := len(t)
		if tlen > 0 {
			for k1 := 0; k1 < tlen; k1++ {
				f[i][k1] = Inf
			}
			for k1 := 0; k1 < tlen; k1++ {
				for x := 0; x <= k1; x++ {
					y := tlen - (k1 - x) - 1
					m := t[y] - t[x] + 1
					if f[i][k1] > m {
						f[i][k1] = m
					}
				}
			}
		}
	}

	for i := 0; i <= n; i++ {
		for j := 0; j <= k; j++ {
			dp[i][j] = Inf
		}
	}

	dp[0][0] = 0
	for i := 1; i <= n; i++ {
		for j := 0; j <= k; j++ {
			for l := 0; l <= j; l++ {
				t := dp[i-1][j-l] + f[i-1][l]
				if dp[i][j] > t {
					dp[i][j] = t
				}
			}
		}
	}

	fmt.Println(dp[n][k])
}


package main

import (
	"bufio"
	"fmt"
	"os"
)

const (
	MaxN = 512
	MaxK = 512
	Inf  = MaxN * MaxK
)

var n, m, k int
var f, dp [MaxN][MaxK]int
var dpf [MaxN][MaxN][MaxK]int

func init() {
	for i := 0; i < MaxN; i++ {
		for j := 0; j < MaxN; j++ {
			for k := 0; k < MaxK; k++ {
				dpf[i][j][k] = -1
			}
		}
	}
}

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d %d %d\n", &n, &m, &k)
	for i := 0; i < n; i++ {
		var tmp string
		fmt.Fscanf(buf, "%s\n", &tmp)
		t := make([]int, 0)
		for j := 0; j < m; j++ {
			if tmp[j] == '1' {
				t = append(t, j)
			}
		}
		tlen := len(t)
		if tlen > 0 {
			var memo func(int, int, int) int
			memo = func(ind1, ind2, ones int) int {
				if ones == 0 {
					if ind2 < ind1 {
						return 0
					}
					return t[ind2] - t[ind1] + 1
				}
				if dpf[ind1][ind2][ones] != -1 {
					return dpf[ind1][ind2][ones]
				}
				m1 := memo(ind1+1, ind2, ones-1)
				m2 := memo(ind1, ind2-1, ones-1)
				if m1 < m2 {
					dpf[ind1][ind2][ones] = m1
				} else {
					dpf[ind1][ind2][ones] = m2
				}
				return dpf[ind1][ind2][ones]
			}
			for j := 0; j <= tlen; j++ {
				f[i][j] = memo(0, tlen-1, j)
			}
		}
	}

	for i := 0; i <= n; i++ {
		for j := 0; j <= k; j++ {
			dp[i][j] = Inf
		}
	}

	dp[0][0] = 0
	for i := 1; i <= n; i++ {
		for j := 0; j <= k; j++ {
			for l := 0; l <= j; l++ {
				t := dp[i-1][j-l] + f[i-1][l]
				if dp[i][j] > t {
					dp[i][j] = t
				}
			}
		}
	}

	fmt.Println(dp[n][k])
}


package main

import (
	"bufio"
	"fmt"
	"os"
)

const (
	MaxN = 512
	MaxK = 512
	Inf  = MaxN * MaxK
)

var n, m, k int
var f, dp [MaxN][MaxK]int
var dpf [MaxN][MaxN][MaxK]int16

func init() {
	for i := 0; i < MaxN; i++ {
		for j := 0; j < MaxN; j++ {
			for k := 0; k < MaxK; k++ {
				dpf[i][j][k] = -1
			}
		}
	}
}

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d %d %d\n", &n, &m, &k)
	for i := 0; i < n; i++ {
		var tmp string
		fmt.Fscanf(buf, "%s\n", &tmp)
		t := make([]int, 0)
		for j := 0; j < m; j++ {
			if tmp[j] == '1' {
				t = append(t, j)
			}
		}
		tlen := len(t)
		if tlen > 0 {
			var memo func(int, int, int) int
			memo = func(ind1, ind2, ones int) int {
				if ones == 0 {
					if ind2 < ind1 {
						return 0
					}
					return t[ind2] - t[ind1] + 1
				}
				if dpf[ind1][ind2][ones] != -1 {
					return int(dpf[ind1][ind2][ones])
				}
				m1 := memo(ind1+1, ind2, ones-1)
				m2 := memo(ind1, ind2-1, ones-1)
				if m1 < m2 {
					dpf[ind1][ind2][ones] = int16(m1)
				} else {
					dpf[ind1][ind2][ones] = int16(m2)
				}
				return int(dpf[ind1][ind2][ones])
			}
			for j := 0; j <= tlen; j++ {
				f[i][j] = memo(0, tlen-1, j)
			}
		}
	}

	for i := 0; i <= n; i++ {
		for j := 0; j <= k; j++ {
			dp[i][j] = Inf
		}
	}

	dp[0][0] = 0
	for i := 1; i <= n; i++ {
		for j := 0; j <= k; j++ {
			for l := 0; l <= j; l++ {
				t := dp[i-1][j-l] + f[i-1][l]
				if dp[i][j] > t {
					dp[i][j] = t
				}
			}
		}
	}

	fmt.Println(dp[n][k])
}


n, m, k = map(int, raw_input().split())

s = [''] * n
for i in xrange(n): s[i] = raw_input()

def calc1(i, k):
    a = []
    for j in xrange(m):
        if s[i][j] == '1': a.append(j)

    if (len(a) == 0): return [0] * (k + 1)

    w = [m] * (k + 1)
    for x in xrange(k + 1):
        for y in xrange(k + 1):
            if x + y > k: continue
            l = min(x, len(a) - 1)
            r = max(len(a) - 1 - y, 0)
            t = max(a[r] - a[l] + 1, 0)
            w[x + y] = min(w[x + y], t)

    return w

b = calc1(0, k)
for i in xrange(1, n):
    d = [0] * (k + 1)
    w = calc1(i, k)
    for f in xrange(k + 1):
        t = n * m
        for g in xrange(f + 1):
            t = min(t, w[g] + b[f - g])
        d[f] = t
    b = d

print b[-1]


n, m, k = map(int, raw_input().split())

s = [''] * n
for i in xrange(n): s[i] = raw_input()

def calc1(i, k):
    a = []
    for j in xrange(m):
        if s[i][j] == '1': a.append(j)

    w = [m] * (k + 1)
    for x in xrange(k + 1):
        for y in xrange(k + 1):
            if x + y > k: continue
            l = min(x, len(a) - 1)
            r = max(len(a) - 1 - y, 0)
            t = max(a[r] - a[l] + 1, 0)
            w[x + y] = min(w[x + y], t)

    return w

b = calc1(0, k)
for i in xrange(1, n):
    d = [0] * (k + 1)
    w = calc1(i, k)
    for f in xrange(k + 1):
        t = n * m
        for g in xrange(f + 1):
            t = min(t, w[g] + b[f - g])
        d[f] = t
    b = d

print b[-1]


n, m, k = map(int, raw_input().split())

a = [[] for i in xrange(n)]
for i in xrange(n):
    s = raw_input()
    for j in xrange(m):
        if s[j] == '1': a[i].append(j)

w = [([0] * (k + 1)) for i in xrange(n)]
for i in xrange(n):
    if len(a[i]) == 0: continue
    for j in xrange(k + 1):
        if len(a[i]) > j:
            w[i][j] = a[i][-1] - a[i][0] + 1
        else:
            w[i][j] = 0
            continue
        for x in xrange(j + 1):
            y = len(a[i]) - 1 - (j - x)
            if y >= x:
                t = a[i][y] - a[i][x] + 1
                w[i][j] = min(w[i][j], t)

dp = [[n * m for j in xrange(k + 1)] for i in xrange(n)]
for j in xrange(k + 1):
    dp[0][j] = w[0][j]

for i in xrange(1, n):
    for j in xrange(k + 1):
        for l in xrange(j + 1):
            dp[i][j] = min(dp[i][j], w[i][l] + dp[i - 1][j - l])

print dp[-1][-1]


n, m, k = map(int, raw_input().split())

s = [''] * n
a = [[] for i in xrange(n)]

for i in xrange(n):
    s[i] = raw_input()
    for j in xrange(m):
        if s[i][j] == '1': a[i].append(j)

def calc(i, k):
    if (len(a[i]) == 0): return [0] * (k + 1)

    w = [m] * (k + 1)
    for x in xrange(k + 1):
        for y in xrange(k + 1 - x):
            l = min(x, len(a[i]) - 1)
            r = max(len(a[i]) - 1 - y, 0)
            t = max(a[i][r] - a[i][l] + 1, 0)
            w[x + y] = min(w[x + y], t)

    return w

b = [[0 for j in xrange(k + 1)] for i in xrange(n)]
w = calc(0, k)
for i in xrange(k + 1):
    b[0][i] = w[i]

for i in xrange(1, n):
    w = calc(i, k)
    for f in xrange(k + 1):
        t = n * m
        for g in xrange(f + 1):
            t = min(t, w[g] + b[i - 1][f - g])
        b[i][f] = t

print b[-1][-1]


n, m, k = map(int, raw_input().split())

s = [''] * n
for i in xrange(n): s[i] = raw_input()

def calc(i, k):
    a = []
    for j in xrange(m):
        if s[i][j] == '1': a.append(j)

    if (len(a) == 0): return [0] * (k + 1)

    w = [m] * (k + 1)
    for x in xrange(k + 1):
        for y in xrange(k + 1 - i):
            if x + y > k: continue
            l = min(x, len(a) - 1)
            r = max(len(a) - 1 - y, 0)
            t = max(a[r] - a[l] + 1, 0)
            w[x + y] = min(w[x + y], t)

    return w

b = [[0 for j in xrange(k + 1)] for i in xrange(n)]
w = calc(0, k)
for i in xrange(k + 1):
    b[0][i] = w[i]

for i in xrange(1, n):
    w = calc(i, k)
    for f in xrange(k + 1):
        t = n * m
        for g in xrange(f + 1):
            t = min(t, w[g] + b[i - 1][f - g])
        b[i][f] = t

print b[-1][-1]


n, m, k = map(int, raw_input().split())

s = [''] * n
for i in xrange(n): s[i] = raw_input()

def calc(i, k):
    a = []
    for j in xrange(m):
        if s[i][j] == '1': a.append(j)

    if (len(a) == 0): return [0] * (k + 1)

    w = [m] * (k + 1)
    for x in xrange(k + 1):
        for y in xrange(k + 1):
            if x + y > k: continue
            l = min(x, len(a) - 1)
            r = max(len(a) - 1 - y, 0)
            t = max(a[r] - a[l] + 1, 0)
            w[x + y] = min(w[x + y], t)

    return w

b = [[0 for j in xrange(k + 1)] for i in xrange(n)]
w = calc(0, k)
for i in xrange(k + 1):
    b[0][i] = w[i]

for i in xrange(1, n):
    w = calc(i, k)
    for f in xrange(k + 1):
        t = n * m
        for g in xrange(f + 1):
            t = min(t, w[g] + b[i - 1][f - g])
        b[i][f] = t

print b[-1][-1]


n, m, k = map(int, raw_input().split())

s = [''] * n
for i in range(n): s[i] = raw_input()

def calc2(a, k):
    if k == 0:
        return a[-1] - a[0] + 1
    else:
        c = m
        for i in range(k + 1):
            l = min(i, len(a) - 1)
            r = max(len(a) - 1 - (k - i), 0)
            t = max(a[r] - a[l] + 1, 0)
            c = min(t, c)
        return c

def calc1(i, k):
    a = []
    for j in range(m):
        if s[i][j] == '1': a.append(j)

    w = [0] * (k + 1)
    for f in range(k + 1):
        w[f] = calc2(a, f)

    return w

b = calc1(0, k)
for i in range(1, n):
    d = b[:]
    w = calc1(i, k)
    for f in range(k + 1):
        t = n * m
        for g in range(f + 1):
            t = min(t, w[g] + b[f - g])
        d[f] = t
    b = d

print b[-1]


n, m, k = map(int, raw_input().split())

s = [''] * n
for i in range(n): s[i] = raw_input()

def calc2(a, k):
    if len(a) == 0:
        return 0
    if k == 0:
        return a[-1] - a[0] + 1
    else:
        c = m
        for i in range(k + 1):
            l = min(i, len(a) - 1)
            r = max(len(a) - 1 - (k - i), 0)
            t = max(a[r] - a[l] + 1, 0)
            c = min(t, c)
        return c

def calc1(i, k):
    a = []
    for j in range(m):
        if s[i][j] == '1': a.append(j)

    w = [0] * (k + 1)
    for f in range(k + 1):
        w[f] = calc2(a, f)

    return w

b = calc1(0, k)
for i in range(1, n):
    d = b[:]
    w = calc1(i, k)
    for f in range(k + 1):
        t = n * m
        for g in range(f + 1):
            t = min(t, w[g] + b[f - g])
        d[f] = t
    b = d

print b[-1]


n, m, k = map(int, raw_input().split())

a = [[] for i in xrange(n)]
for i in xrange(n):
    s = raw_input()
    for j in xrange(m):
        if s[j] == '1': a[i].append(j)

w = [([0] * (k + 1)) for i in xrange(n)]
for i in xrange(n):
    if len(a[i]) == 0: continue
    for j in xrange(k + 1):
        w[i][j] = a[i][-1] - a[i][0] + 1
        for x in xrange(j + 1):
            y = len(a[i]) - 1 - (j - x)
            if y >= x:
                t = a[i][y] - a[i][x] + 1
                w[i][j] = min(w[i][j], t)

dp = [[n * m for j in xrange(k + 1)] for i in xrange(n)]
for j in xrange(k + 1):
    dp[0][j] = w[0][j]

for i in xrange(1, n):
    for j in xrange(k + 1):
        for l in xrange(j + 1):
            dp[i][j] = min(dp[i][j], w[i][l] + dp[i - 1][j - l])

print dp[-1][-1]


n, m, k = map(int, raw_input().split())

s = [''] * n
for i in xrange(n): s[i] = raw_input()

def calc(i, k):
    a = []
    for j in xrange(m):
        if s[i][j] == '1': a.append(j)

    if (len(a) == 0): return [0] * (k + 1)

    w = [m] * (k + 1)
    for x in xrange(k + 1):
        for y in xrange(k + 1 - x):
            if x + y > k: continue
            l = min(x, len(a) - 1)
            r = max(len(a) - 1 - y, 0)
            t = max(a[r] - a[l] + 1, 0)
            w[x + y] = min(w[x + y], t)

    return w

b = [[0 for j in xrange(k + 1)] for i in xrange(n)]
w = calc(0, k)
for i in xrange(k + 1):
    b[0][i] = w[i]

for i in xrange(1, n):
    w = calc(i, k)
    for f in xrange(k + 1):
        t = n * m
        for g in xrange(f + 1):
            t = min(t, w[g] + b[i - 1][f - g])
        b[i][f] = t

print b[-1][-1]


n, m, k = map(int, raw_input().split())

s = [''] * n
a = [[] for i in xrange(n)]
for i in xrange(n):
    s[i] = raw_input()
    for j in xrange(m):
        if s[i][j] == '1': a[i].append(j)

w = [([m] * (k + 1)) for i in xrange(n)]
for i in xrange(n):
    if (len(a[i]) == 0):
        for x in xrange(k + 1): w[i][x] = 0
        continue
    for x in xrange(k + 1):
        for y in xrange(k + 1 - x):
            l = min(x, len(a[i]) - 1)
            r = max(len(a[i]) - 1 - y, 0)
            t = max(a[i][r] - a[i][l] + 1, 0)
            w[i][x + y] = min(w[i][x + y], t)

b = [[0 for j in xrange(k + 1)] for i in xrange(n)]
for i in xrange(k + 1):
    b[0][i] = w[0][i]

for i in xrange(1, n):
    for f in xrange(k + 1):
        t = n * m
        for g in xrange(f + 1):
            t = min(t, w[i][g] + b[i - 1][f - g])
        b[i][f] = t

print b[-1][-1]


n, m, k = map(int, raw_input().split())

s = [''] * n
for i in range(n): s[i] = raw_input()

def calc2(a, k):
    if len(a) == 0: return 0

    if k == 0:
        return a[-1] - a[0] + 1
    else:
        c = m
        for i in xrange(k + 1):
            l = min(i, len(a) - 1)
            r = max(len(a) - 1 - (k - i), 0)
            t = max(a[r] - a[l] + 1, 0)
            c = min(t, c)
        return c

def calc1(i, k):
    a = []
    for j in xrange(m):
        if s[i][j] == '1': a.append(j)

    w = [0] * (k + 1)
    for f in xrange(k + 1):
        w[f] = calc2(a, f)

    return w

b = calc1(0, k)
for i in xrange(1, n):
    d = [0] * (k + 1)
    w = calc1(i, k)
    for f in xrange(k + 1):
        t = n * m
        for g in xrange(f + 1):
            t = min(t, w[g] + b[f - g])
        d[f] = t
    b = d

print b[-1]


n, m, k = map(int, raw_input().split())

a = [[] for i in xrange(n)]
for i in xrange(n):
    s = raw_input()
    for j in xrange(m):
        if s[j] == '1': a[i].append(j)

w = [([0] * (k + 1)) for i in xrange(n)]
for i in xrange(n):
    if len(a[i]) == 0: continue
    for j in xrange(k + 1):
        if len(a[i]) > j:
            w[i][j] = a[i][-1] - a[i][0] + 1
        else:
            w[i][j] = 0
            continue
        for x in xrange(j + 1):
            y = len(a[i]) - 1 - (j - x)
            if y >= x:
                t = a[i][y] - a[i][x] + 1
                w[i][j] = min(w[i][j], t)
            else:
            	break

dp = [[n * m for j in xrange(k + 1)] for i in xrange(n)]
for j in xrange(k + 1):
    dp[0][j] = w[0][j]

for i in xrange(1, n):
    for j in xrange(k + 1):
        for l in xrange(j + 1):
            dp[i][j] = min(dp[i][j], w[i][l] + dp[i - 1][j - l])

print dp[-1][-1]


n, m, k = map(int, raw_input().split())

classes = [[] for i in xrange(n)]

#For adding the hour when classes are there
for i in xrange(n):
	s = raw_input()
	for j in xrange(m):
		if s[j] == 1:
			classes[i].append(j)

# For w[i][j] = minimum number of hours to be attended where i corresponds to which day, and
# j is number of classes that can be skipped in that day

w = [([0]*(k+1)) for _ in xrange(n)]

# i is for the day which we are talking about
for i in xrange(n):
	if len(classes) == 0:
		continue

	#j is number of classes that can be skipped
	for j in xrange(k+1):
		if len(classes[i]) > j:
			#Just setting a value
			w[i][j] = a[i][-1] - a[i][0] + 1
		else:
			w[i][j] = 0
			continue

		for x in xrange(j+1):
			y = len(a[i]) - 1 - (j - x)
            if y >= x:
                t = a[i][y] - a[i][x] + 1
                w[i][j] = min(w[i][j], t)

dp = [[n * m for j in xrange(k + 1)] for i in xrange(n)]

for j in xrange(k + 1):
    dp[0][j] = w[0][j]

for i in xrange(1, n):
    for j in xrange(k + 1):
        for l in xrange(j + 1):
            dp[i][j] = min(dp[i][j], w[i][l] + dp[i - 1][j - l])

print dp[-1][-1]


n, m, k = map(int, raw_input().split())

a = [[] for i in xrange(n)]

#For adding the hour when classes are there
for i in xrange(n):
	s = raw_input()
	for j in xrange(m):
		if s[j] == 1:
			a[i].append(j)

# For w[i][j] = minimum number of hours to be attended where i corresponds to which day, and
# j is number of classes that can be skipped in that day

w = [([0]*(k+1)) for _ in xrange(n)]

# i is for the day which we are talking about
for i in xrange(n):
	if len(a) == 0:
		continue

	#j is number of classes that can be skipped
	for j in xrange(k+1):
		if len(a[i]) > j:
			#Just setting a value
			w[i][j] = a[i][-1] - a[i][0] + 1
		else:
			w[i][j] = 0
			continue

		for x in xrange(j+1):
			y = len(a[i]) - 1 - (j - x)
        	if y >= x:
				t = a[i][y] - a[i][x] + 1
				w[i][j] = min(w[i][j], t)

dp = [[n * m for j in xrange(k + 1)] for i in xrange(n)]

for j in xrange(k + 1):
    dp[0][j] = w[0][j]

for i in xrange(1, n):
    for j in xrange(k + 1):
        for l in xrange(j + 1):
            dp[i][j] = min(dp[i][j], w[i][l] + dp[i - 1][j - l])

print dp[-1][-1]


from sys import stdin

rstr = lambda: stdin.readline().strip()
rints = lambda: [int(x) for x in stdin.readline().split()]

n, m, k = rints()
a = [rstr() for _ in range(n)]
mem = [[float('inf') if i else 0 for _ in range(k + 1)] for i in range(n + 1)]

for i in range(n):
    ixs = []
    for j in range(m):
        if a[i][j] == '1':
            ixs.append(j)

    for j in range(k + 1):
        tem = 0
        if j < len(ixs):
            tem, c = float('inf'), 0
            for j1 in range(len(ixs) - j - 1, len(ixs)):
                tem = min(tem, ixs[j1] - ixs[c] + 1)
                c += 1

        for j1 in range(k + 1 - j):
            mem[i + 1][j1 + j] = min(mem[i + 1][j1 + j], mem[i][j1] + tem)

print(mem[n][k])
# print(mem)


from sys import stdin

def fast2():
    import os, sys, atexit
    from cStringIO import StringIO as BytesIO
    # range = xrange
    sys.stdout = BytesIO()
    atexit.register(lambda: os.write(1, sys.stdout.getvalue()))
    return BytesIO(os.read(0, os.fstat(0).st_size)).readline

stdin = fast2()
rstr = lambda: stdin.readline().strip()
rints = lambda: [int(x) for x in stdin.readline().split()]

n, m, k = rints()
a = [rstr() for _ in range(n)]
mem = [[float('inf') if i else 0 for _ in range(k + 1)] for i in range(n + 1)]

for i in range(n):
    ixs = []
    for j in range(m):
        if a[i][j] == '1':
            ixs.append(j)

    for j in range(k + 1):
        tem = 0
        if j < len(ixs):
            tem, c = float('inf'), 0
            for j1 in range(len(ixs) - j - 1, len(ixs)):
                tem = min(tem, ixs[j1] - ixs[c] + 1)
                c += 1

        for j1 in range(k + 1 - j):
            mem[i + 1][j1 + j] = min(mem[i + 1][j1 + j], mem[i][j1] + tem)

print(mem[n][k])
# print(mem)


from sys import stdin

def fast2():
    import os, sys, atexit
    from cStringIO import StringIO as BytesIO
    # range = xrange
    sys.stdout = BytesIO()
    atexit.register(lambda: os.write(1, sys.stdout.getvalue()))
    return BytesIO(os.read(0, os.fstat(0).st_size)).readline

input = fast2()
rstr = lambda: input().strip()
rints = lambda: [int(x) for x in input().split()]

n, m, k = rints()
a = [rstr() for _ in range(n)]
mem = [[float('inf') if i else 0 for _ in range(k + 1)] for i in range(n + 1)]

for i in range(n):
    ixs = []
    for j in range(m):
        if a[i][j] == '1':
            ixs.append(j)

    for j in range(k + 1):
        tem = 0
        if j < len(ixs):
            tem, c = float('inf'), 0
            for j1 in range(len(ixs) - j - 1, len(ixs)):
                tem = min(tem, ixs[j1] - ixs[c] + 1)
                c += 1

        for j1 in range(k + 1 - j):
            mem[i + 1][j1 + j] = min(mem[i + 1][j1 + j], mem[i][j1] + tem)

print(mem[n][k])
# print(mem)


n, m, k = map(int,raw_input().split())
a = [[] for i in xrange(n)]
for i in xrange(n):
    s = raw_input()
    for j in xrange(m):
        if s[j] == '1': a[i].append(j)
w = [([0] * (k + 1)) for i in xrange(n)]
for i in xrange(n):
    if len(a[i]) == 0: continue
    for j in xrange(k + 1):
        if len(a[i]) > j:
            w[i][j] = a[i][-1] - a[i][0] + 1
        else:
            w[i][j] = 0
            continue
        for x in xrange(j + 1):
            y = len(a[i]) - 1 - (j - x)
            if y >= x:
                t = a[i][y] - a[i][x] + 1
                w[i][j] = min(w[i][j], t)
dp = [[n * m for j in xrange(k + 1)] for i in xrange(n)]
for j in xrange(k + 1):
    dp[0][j] = w[0][j]
for i in xrange(1, n):
    for j in xrange(k + 1):
        for l in xrange(j + 1):
            dp[i][j] = min(dp[i][j], w[i][l] + dp[i - 1][j - l])

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


def min_sub_array(day, k):
    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][1] - day[i][0])
    output = [0] * (k + 1)
    for i in range(k + 1):
        if n - i > 0:
            output[i] = best[n - i]
    return output

n, m, k = map(int, input().split())

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

for _ in range(n - 1):
    day = [(i, i + 1) 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[k - j])
    best = new_best
print(best[k])


def min_sub_array(day, k):
    if not day:
        return [0]
    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][1] - day[i][0])
    output = [0] * (k + 1)
    for i in range(k + 1):
        if n - i > 0:
            output[i] = best[n - i]
    return output

n, m, k = map(int, input().split())

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

for _ in range(n - 1):
    day = [(i, i + 1) 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])


def min_sub_array(day, k):
    if not day:
        return [0]
    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][1] - day[i][0])
    output = [0] * (k + 1)
    for i in range(k + 1):
        if n - i > 0:
            output[i] = best[n - i]
    return output

n, m, k = map(int, input().split())

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

for _ in range(n - 1):
    day = [(i, i + 1) 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[k - j])
    best = new_best
print(best[k])


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 = 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

n, m, k = 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)

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

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

    for i in range(k, -1, -1):
        for j in range(1, min(len(one), k-i+1)):
            dp[i+j] = min(dp[i+j], dp[i] + subdp[j])
        dp[i] = dp[i] + subdp[0]

print(min(dp))


import sys

n, m, k = 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))


import sys

n, m, k = 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)

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

    for i in range(len(one)):
        for j in range(i, len(one)):
            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(len(one)):
            if i+j > k:
                break
            next_dp[i+j] = min(next_dp[i+j], dp[i] + subdp[j])
    dp = next_dp

print(min(dp))


import queue
intput = lambda: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)

dp[0][0:len(req[0])] = req[0]
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(dp[-1][-1])


import queue
intput = lambda: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)

dp[0] = req[0]
for i in range(1, N):
    for j in range(K+1):
        dp[i][j] = dp[i-1][j] + req[i][0]
        for z in range(min(j+1, 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])


import queue
intput = lambda: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])


intput = lambda: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']

cost = 0
marginal_good = []
for day in ht:
    if len(day) != 0:
        marginal_good.append(1)
        cost += day[-1] - day[0] + 1
        for i in range(len(day)-1):
            marginal_good.append(day[i+1]-day[i])

# print('cost', cost, 'good', marginal_good)

marginal_good.sort(key=lambda x:-x)
savings = sum(marginal_good[:K])
print(cost - savings)


intput = lambda: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']

cost = 0
marginal_good = []
for day in ht:
    cost += day[-1] - day[0] + 1
    for i in range(len(day)-1):
        marginal_good.append(day[i+1]-day[i])
    marginal_good.append(1)

# print('cost', cost, 'good', marginal_good)

marginal_good.sort(key=lambda x:-x)
savings = sum(marginal_good[:K])
print(cost - savings)


import queue
intput = lambda: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)

dp[0][0:len(req[0])] = req[0]
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[i][j])


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=[[1000 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=[[1000 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
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=[[1000 for i in range(n+5)]for j in range(lesson+5)]
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=[[1000 for i in range(n+4)]for j in range(lesson+10)]
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
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
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=[[2501 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=[[2501 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 math
#import math
#------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

#-------------------game starts now----------------------------------------------------import math
def calc(st,j):
    ans=9999999999999999999999
    #print(st)
    if j>=len(st):
        return 0
    j=len(st)-j
    for i in range(j-1,len(st)):
        ans=min(ans,st[i]-st[i-j+1]+1)
    return ans
n,m,k=map(int,input().split())
s=[]
for i in range(n):
    s.append(input())
inf=99999999999999999999
dp=[[inf for i in range(k+1)]for j in range(n+1)]
for i in range(k+1):
    dp[0][i]=0
for i in range(1,n+1):
    st=[]
    for ik in range(len(s[i-1])):
        if s[i-1][ik]=='1':
            st.append(ik)
    for j in range(k+1):
        no=calc(st,j)
        #print(no,j)
        for t in range(k+1-j):
            dp[i][t+j]=min(dp[i][t+j],no+dp[i-1][t])
#print(dp)
print(dp[n][k])


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]))


R = lambda: map(int, input().split())
n, m, k = R()
cls = [list(map(int, input())) for i in range(n)]
dp = [[n * m] * (k + 1) for i in range(n + 1)]
dp.append([0] * (k + 1))
for i in range(n):
    for j in range(k + 1):
        cnt = 0
        for ii in range(m):
            cnt += cls[i][ii]
            if j + cnt <= k:
                dp[i][j] = min(dp[i][j], dp[i - 1][j + cnt] + m - ii - 1)
        cnt = 0
        for ii in range(m - 1, -1, -1):
            cnt += cls[i][ii]
            if j + cnt <= k:
                dp[i][j] = min(dp[i][j], dp[i - 1][j + cnt] + ii)
print(min(dp[n - 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
    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]))


R = lambda: map(int, input().split())
n, m, k = R()
cls = [list(map(int, input())) for i in range(n)]
dp = [[n * m] * (k + 1) for i in range(n + 1)]
dp.append([0] * (k + 1))
for i in range(n):
    for j in range(k + 1):
        dp[i][j] = dp[i - 1][j] + m
        cnt = 0
        for ii in range(m):
            cnt += cls[i][ii]
            if j + cnt <= k:
                dp[i][j] = min(dp[i][j], dp[i - 1][j + cnt] + m - ii - 1)
        cnt = 0
        for ii in range(m - 1, -1, -1):
            cnt += cls[i][ii]
            if j + cnt <= k:
                dp[i][j] = min(dp[i][j], dp[i - 1][j + cnt] + ii)
print(min(dp[n - 1]))


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])


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

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

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])


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

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

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:
                pre[i][j] = 0
            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])


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 ind, c in enumerate(s):
        if c == '1':
            ind[-1].append(ind)

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])


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Olimp7
{
    class Program
    {
        static void Main(string[] param)
        {
            int[] input = Console.ReadLine().Split(' ').Select(_ => int.Parse(_)).ToArray();
            int n = input[0];//дней
            int m = input[1];//часов
            int k = input[2];
            int[,] boosts = new int[n,k];
            int sum = 0;
            for (int i = 0;i < n; i++)
            {
                string s = Console.ReadLine();
                int[] prices = new int[k + 1];
                List<int> indexes = new List<int>();
                for (int j = 0;j < m; j++)
                {
                    if(s[j] == '1')
                    {
                        indexes.Add(j);
                    }
                }
                for (int j = 0;j <= k; j++)
                {
                    int ll = indexes.Count - 1 - j;
                    if (ll < 0)
                    {
                        prices[j] = 0;
                    }
                    else if (ll == 0)
                    {
                        prices[j] = 1;
                    }
                    else
                    {
                        int min = int.MaxValue;
                        for (int l = 0; l + ll < indexes.Count; l++)
                        {
                            if (indexes[l + ll] - indexes[l] + 1 < min)
                            {
                                min = indexes[l + ll] - indexes[l] + 1;
                            }
                        }
                        prices[j] = min;
                    }
                }
                for (int l = 0;l < k; l++)
                {
                    boosts[i, l] = prices[0] - prices[l + 1];
                }
                sum += prices[0];
            }
            int[] dp = new int[k + 1];
            dp[0] = 0;
            for (int i = 0;i < n; i++)
            {
                for (int l = k; l > 0; l--)
                {
                    for (int j = 0; j < k; j++)
                    {
                        if (l - j > 0)
                        {
                            dp[l] = Math.Max(dp[l],dp[l - j - 1] + boosts[i,j]);
                        }
                    }
                }
            }
            Console.WriteLine(sum - dp.Last());
        }
    }
}


//set many funcs template
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int strsortfncsj(const void *a,const void *b){return strcmp((char *)a,(char *)b);}
int strsortfnckj(const void *a,const void *b){return strcmp((char *)b,(char *)a);}

int main(void){
    int jud,tl,i,j,n,m,k,a[512]={0},pa[512],b,c,w,r=inf,l,t,x;
    int dp[512][512];
    double d;
    char s[262144];
    scanf("%d%d%d",&n,&m,&k);
    //l=strlen(s);
    for(i=0;i<512;i++){
        for(j=0;j<512;j++){
            dp[i][j]=inf;
            if(i==0){dp[0][j]=0;}
        }
    }
    for(i=1;i<=n;i++){scanf("%s",s);
        a[0]=0;pa[0]=inf;tl=0;
        for(j=0;j<m;j++){
            tl+=(s[j]-'0');a[j+1]=a[j]+(s[j]-'0');pa[j+1]=inf;
        }
        pa[tl]=0;
        for(j=0;j<m;j++){
            for(x=j+1;x<=m;x++){
                jud=tl-(a[x]-a[j]);
                pa[jud]=min(pa[jud],x-j);
            }
        }
        for(j=k;j>=0;j--){
            for(x=tl;x>=0;x--){
                if(j+x>k){continue;}
                dp[i][j+x]=min(dp[i][j+x],dp[i-1][j]+pa[x]);
            }
        }
    }
    for(i=0;i<=k;i++){r=min(r,dp[n][i]);}
    //qsort(a,n,sizeof(int),sortfncsj);
    printf("%d\n",r);
    return 0;
}


#include "stdio.h"
const int inf=0x3f3f3f3f;
char clas[505];
int sum[505];
int skip[505][505];
int cost[505][505];
int dp[505];
int MIN(int x,int y)
{
    if(x<y)
        return x;
    else return y;
}
int main()
{
    int n,m,k,j,i,p,r,l,mi;
    scanf("%d%d%d",&n,&m,&k);
    for(i=1;i<=n;i++)
    {
        scanf("%s",clas+1);
        for(j=1;j<=m;j++)
        {
            if(clas[j]=='1')
                {
                    sum[i]++;
                    skip[i][sum[i]]=j;
                }
        }

        for(p=1;p<=sum[i]-1;p++)
        {
            mi=inf;
            for(r=0;r<=p-1;r++)
            {
                l=p-r;
                if(skip[i][sum[i]-r]-skip[i][l+1]+1<mi)
                {
                    mi=skip[i][sum[i]-r]-skip[i][l+1]+1;
                }
            }
            cost[i][p]=m-mi;
        }
        cost[i][sum[i]]=m;
        cost[i][0]=m-skip[i][sum[i]]+skip[i][1]-1;
    }
    for(i=1;i<=n;i++)
        for(j=k;j>=0;j--)
            for(p=0;p<=MIN(sum[i],j);p++)
        {
            if(dp[j]<dp[j-p]+cost[i][p])
                dp[j]=dp[j-p]+cost[i][p];
        }
    printf("%d\n",n*m-dp[k]);
    return 0;
}


#include "stdio.h"
const int inf=0x3f3f3f3f;
char clas[505];
int sum[505];
int skip[505][505];
int cost[505][505];
int dp[505];
int MIN(int x,int y)
{
    if(x<y)
        return x;
    else return y;
}
int MAX(int x,int y)
{
    if(x>y)
        return x;
    else return y;
}
int main()
{
    int n,m,k,j,i,p,r,l,mi;
    scanf("%d%d%d",&n,&m,&k);
    for(i=1;i<=n;i++)
    {
        scanf("%s",clas+1);
        for(j=1;j<=m;j++)
        {
            if(clas[j]=='1')
                {
                    sum[i]++;
                    skip[i][sum[i]]=j;
                }
        }

        for(p=0;p<=sum[i]-1;p++)
        {
            mi=inf;
            for(l=0;l<=sum[i]-1;l++)
            {
                if(p-l<0)
                    break;
                r=p-l;
                mi=MIN(mi,skip[i][sum[i]-r]-skip[i][l+1]+1);
            }
            cost[i][p]=m-mi;
        }
        cost[i][sum[i]]=m;
    }
    for(i=1;i<=n;i++)
        for(j=k;j>=0;j--)
            for(p=0;p<=MIN(sum[i],j);p++)
        {
            dp[j]=MAX(dp[j],dp[j-p]+cost[i][p]);
        }
    printf("%d\n",n*m-dp[k]);
    return 0;
}


#include "stdio.h"
#include "string.h"
const int inf=0x3f3f3f3f;
char clas[505];
int sum[505];
int skip[505][505];
int cost[505][505];
int dp[505];
int MIN(int x,int y)
{
    if(x<y)
        return x;
    else return y;
}
int main()
{
    memset(sum,0,sizeof(sum));
    memset(skip,0,sizeof(skip));
    memset(cost,0,sizeof(cost));
    memset(dp,0,sizeof(dp));
    int n,m,k,j,i,p,r,l,mi;
    scanf("%d%d%d",&n,&m,&k);
    for(i=1;i<=n;i++)
    {
        scanf("%s",clas+1);
        for(j=1;j<=m;j++)
        {
            if(clas[j]=='1')
                {
                    sum[i]++;
                    skip[i][sum[i]]=j;
                }
        }

        for(p=1;p<=sum[i]-1;p++)
        {
            mi=inf;
            for(r=0;r<=p-1;r++)
            {
                l=p-r;
                if(skip[i][sum[i]-r]-skip[i][l+1]+1<mi)
                {
                    mi=skip[i][sum[i]-r]-skip[i][l+1]+1;
                }
            }
            cost[i][p]=m-mi;
        }
        cost[i][sum[i]]=m;
        cost[i][0]=m-skip[i][sum[i]]+skip[i][1]-1;
        if(sum[i]==0)
            cost[i][0]=m;

    }
    for(i=1;i<=n;i++)
        for(j=k;j>=0;j--)
            for(p=0;p<=MIN(sum[i],j);p++)
        {
            if(dp[j]<dp[j-p]+cost[i][p])
                dp[j]=dp[j-p]+cost[i][p];
        }
    printf("%d\n",n*m-dp[k]);
    return 0;
}


#include "stdio.h"
const int inf=0x3f3f3f3f;
using namespace std;
char clas[505];
int sum[505];
int skip[505][505];
int cost[505][505];
int dp[505];
int MIN(int x,int y)
{
    if(x<y)
        return x;
    else return y;
}
int main()
{
    int n,m,k,j,i,p,r,l,mi;
    scanf("%d%d%d",&n,&m,&k);
    for(i=1;i<=n;i++)
    {
        scanf("%s",clas+1);
        for(j=1;j<=m;j++)
        {
            if(clas[j]=='1')
                {
                    sum[i]++;
                    skip[i][sum[i]]=j;
                }
        }

        for(p=1;p<=sum[i]-1;p++)
        {
            mi=inf;
            for(r=0;r<=p-1;r++)
            {
                l=p-r;
                if(skip[i][sum[i]-r]-skip[i][l+1]+1<mi)
                {
                    mi=skip[i][sum[i]-r]-skip[i][l+1]+1;
                }
            }
            cost[i][p]=m-mi;
        }
        cost[i][sum[i]]=m;
        cost[i][0]=m-skip[i][sum[i]]+skip[i][1]-1;
    }
    for(i=1;i<=n;i++)
        for(j=k;j>=0;j--)
            for(p=0;p<=MIN(sum[i],j);p++)
        {
            if(dp[j]<dp[j-p]+cost[i][p])
                dp[j]=dp[j-p]+cost[i][p];
        }
    printf("%d\n",n*m-dp[k]);
    return 0;
}


#include "stdio.h"
#include <iostream>
#include<algorithm>
const int inf=0x3f3f3f3f;
int n,m,k,j,i,p,r,l,min;
char clas[505];
int sum[505]={0};
int skip[505][505];
int cost[505][505];
int dp[505]={0};
int MIN(int x,int y)
{
    if(x<y)
        return x;
    else return y;
}
int main()
{
    scanf("%d%d%d",&n,&m,&k);
    for(i=1;i<=n;i++)
    {
        scanf("%s",clas+1);
        for(j=1;j<=m;j++)
        {
            if(clas[j]=='1')
                {
                    sum[i]++;
                    skip[i][sum[i]]=j;
                }
        }

        for(p=1;p<=sum[i]-1;p++)
        {
            min=inf;
            for(r=0;r<=p-1;r++)
            {
                l=p-r;
                if(skip[i][sum[i]-r]-skip[i][l+1]+1<min)
                {
                    min=skip[i][sum[i]-r]-skip[i][l+1]+1;
                }
            }
            cost[i][p]=m-min;
        }
        cost[i][sum[i]]=m;
        cost[i][0]=m-skip[i][sum[i]]+skip[i][1]-1;
    }
    for(i=1;i<=n;i++)
        for(j=k;j>=0;j--)
            for(p=0;p<=MIN(sum[i],j);p++)
        {
            if(dp[j]<dp[j-p]+cost[i][p])
                dp[j]=dp[j-p]+cost[i][p];
        }
    printf("%d\n",n*m-dp[k]);
    return 0;
}