import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as C
import Data.List
import Control.Monad
import Data.Ord
import Data.Maybe
import qualified Data.IntMap as IM
import Numeric
import Data.Char
import Text.Printf

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine


r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine


main :: IO ()
main = do
    [h,w,k] <- r'
    choco <- replicateM h (map (read.pure) <$> getLine) :: IO[[Int]]
    let sepH = seps (h-1)
    let vert = map (maximum . map ((sepW k 0 0).(foldzip sum)) . (\s->sepBy s choco)) sepH
    print $ minimum (zipWith (+) (map sum sepH) vert)

sepW _ _ ac [] = ac
sepW lim count ac (x:xs) = if x+count > lim then sepW lim x (ac+1) xs else sepW lim (x+count) ac xs


foldzip :: ([Int] -> Int) -> [[Int]] -> [Int]
foldzip f xs
    | null (head xs) = []
    | otherwise = f (map head xs):foldzip f (map tail xs)

sepBy :: [Int] -> [a] -> [[a]]
sepBy [] xs = [xs]
sepBy (0:sp) (x:xs) = (x:) `onHeadOf` (sepBy sp xs)
sepBy (1:sp) (x:xs) = [x]:(sepBy sp xs)

f `onHeadOf` (x:xs) = (f x):xs

seps :: Int -> [[Int]]
seps n = map ((map (read.pure)).(printf ("%0"++show n++"b"))) [0..(2^n :: Int)-1]