#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )

#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

typedef vector<PII> VP;
typedef vector<VP> VVP;
typedef vector<VVP> VVVP;
typedef vector<VVVP> VVVVP;

struct Solver
{
	const int H, W, S;
	VVI board, csum;
	VVVVP dp;

	Solver( int h, int w, int s ) :
		H( h ), W( w ), S( s ),
		board( H, VI( W ) ),
		csum( H + 1, VI( 1, 0 ) ),
		dp( H, VVVP( W, VVP( H, VP( W, MP( -1, -1 ) ) ) ) )
	{
		REP( i, 0, H )
		{
			REP( j, 0, W )
			{
				cin >> board[i][j];
			}
		}

		REP( i, 0, H )
		{
			partial_sum( ALL( board[i] ), back_inserter( csum[ i + 1 ] ) );
		}
		csum[0].resize( W + 1, 0 );
		REP( x, 0, W + 1 )
		{
			REP( y, 0, H )
			{
				csum[ y + 1 ][x] += csum[y][x];
			}
		}

		return;
	}

	PII solve()
	{
		return rec( 0, 0, H - 1, W - 1 );
	}

	PII rec( int y1, int x1, int y2, int x2 )
	{
		PII &memoized = dp[ y1 ][ x1 ][ y2 ][ x2 ];
		if ( memoized.fst != -1 )
		{
			return memoized;
		}

		if ( S < areaSum( 0, 0, H - 1, W - 1 ) - areaSum( y1, x1, y2, x2 ) )
		{
			return MP( -1, -1 );
		}

		PII res = MP( -1, -1 );
		REP( ix, x1, x2 )
		{
			PII cut1 = rec( y1, x1, y2, ix );
			PII cut2 = rec( y1, ix + 1, y2, x2 );
			
			if ( min( cut1, cut2 ).fst == -1 )
			{
				continue;
			}

			res = max( res, MP( cut1.fst + cut2.fst, min( cut1.snd, cut2.snd ) ) );
		}

		REP( iy, y1, y2 )
		{
			PII cut1 = rec( y1, x1, iy, x2 );
			PII cut2 = rec( iy + 1, x1, y2, x2 );

			if ( min( cut1, cut2 ).fst == -1 )
			{
				continue;
			}
			
			res = max( res, MP( cut1.fst + cut2.fst, min( cut1.snd, cut2.snd ) ) );
		}

		
		if ( res.fst == -1 )
		{
			return memoized = MP( 1, S - ( areaSum( 0, 0, H - 1, W - 1 ) - areaSum( y1, x1, y2, x2 ) ) );
		}
		else
		{
			return memoized = res;
		}
	}

	int areaSum( int y1, int x1, int y2, int x2 )
	{
		return csum[ y2 + 1 ][ x2 + 1 ] - csum[ y1 ][ x2 + 1 ] - csum[ y2 + 1 ][ x1 ] + csum[ y1 ][ x1 ];
	}
};

int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );

	while ( true )
	{
		int h, w, s;
		cin >> h >> w >> s;

		if ( !( h | w | s ) )
		{
			break;
		}

		PII res( Solver( h, w, s ).solve() );
		cout << res.fst << ' ' << res.snd << endl;
	}

	return 0;
}

Measured memory_bytes: 10976