#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool check(ll x, ll y, ll xMax, ll yMax) { return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string tostring(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
template<class T> inline T mypow(T x, ll n) { T res = 1; while (n > 0) { if (n & 1)res = res * x;	x = x * x;	n >>= 1; }return res; }
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define tostr(a)	tostring(a)
#define dump(val) 	cerr << #val " = " << val << endl;
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const ll dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = 1e17 + 9;

#define int ll
#define double ld

//dp[y][x][ty][tx] = ????§???¢(y,x,ty,tx)??§???????????¨?????§??????(?????§?????°???????????°, ?????§?????????)
P dp[32][32][32][32];

signed main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	
	int h, w, s;
	while (cin >> h >> w >> s && h) {
		rep(y, h)rep(x, w)rep(ty, h)rep(tx, w)dp[y][x][ty][tx] = P(-1, 0);
		
		int d[32][32];
		int sum = 0;
		rep(y, h)rep(x, w) {
			cin >> d[y][x];
			sum += d[y][x];
		}
		rep(y, h)rep(x, w) {
			dp[y][x][y][x] = P(sum - d[y][x] <= s ? 1 : 0, d[y][x]);
		}
		auto unite = [&](P t0, P t1) {
			if (t1.first == 0)swap(t0, t1);

			if (t0.first == 0) {
				if (t1.first <= 1) {
					auto ret = P(t1.first, t0.second + t1.second);
					if (sum - ret.second <= s)ret.first = 1;
					return ret;
				}
				return P(-1, -1);
			}

			return P(t0.first + t1.first, min(t0.second, t1.second));
		};
		
		function<P(int, int, int, int)> solve = [&](int y,int x,int ty,int tx) {
			if (dp[y][x][ty][tx].first != -1) {
				return dp[y][x][ty][tx];
			}
			P ret(-1, -1);
			for (int ay = y; ay < ty; ay++) {
				ret = max(unite(solve(y, x, ay, tx), solve(ay+1, x, ty, tx)), ret);
			}
			for (int ax = x; ax < tx; ax++) {
				ret = max(unite(solve(y, x, ty, ax), solve(y, ax+1, ty, tx)), ret);
			}
			return dp[y][x][ty][tx] = ret;
		};
		auto ans = solve(0, 0, h-1, w-1);
		ans.second = s - (sum - ans.second);
		cout << ans.first << " " << ans.second << endl;
	}

	return 0;
}

Measured memory_bytes: 19516