class Array
	def accum
		ac = Array.new(size + 1)
		ac[0] = 0
		(1..size).each do |i|
			ac[i] = ac[i-1] + self[i-1]
		end
		ac
	end

	def accum_2d
		ac = map{|r| r.accum}
		(1..size-1).each{|i|
			(1..ac[0].size-1).each{|j|
				ac[i][j] += ac[i-1][j]
			}
		}
		ac.unshift([0] * ac[0].size)
		ac
	end
end		

def encode(i1, i2, j1, j2)
    (i1 << 18) + (i2 << 12) + (j1 << 6) + j2
end

def f(i1, i2, j1, j2)
    key = encode(i1, i2, j1, j2)
    cache = $memo[key]
    return cache if cache

    x = $a[i2][j2] - $a[i2][j1-1] - $a[i1-1][j2] + $a[i1-1][j1-1]
    return nil if x < $target

    if i1 == i2 && j1 == j2
        return $memo[key] = [1, x - $target]
    end

    best_num = 1
    best_afford = x - $target

    if i1 < i2
        (i1+1..i2).each do |i|
            n1, a1 = f(i1, i-1, j1, j2)
            next unless n1
            n2, a2 = f(i, i2, j1, j2)
            next unless n2
            if n1 + n2 > (best_num || 0)
                best_num = n1 + n2
                best_afford = [a1, a2].min
            elsif n1 + n2 == best_num
                m = [a1, a2].min
                best_afford = m if m > best_afford
            end
        end
    end

    if j1 < j2
        (j1+1..j2).each do |j|
            n1, a1 = f(i1, i2, j1, j-1)
            next unless n1
            n2, a2 = f(i1, i2, j, j2)
            next unless n2
            if n1 + n2 > (best_num || 0)
                best_num = n1 + n2
                best_afford = [a1, a2].min
            elsif n1 + n2 == best_num
                m = [a1, a2].min
                best_afford = m if m > best_afford
            end
        end
    end

    $memo[key] = [best_num, best_afford]
end

loop do
    h, w, s = gets.split.map(&:to_i)
    break if h == 0
    $a = (1..h).map {gets.split.map(&:to_i)}.accum_2d
    $target = $a[-1][-1] - s
    $memo = {}

    puts f(1, h, 1, w) * ' '
end