#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

const int maxh = 35, maxw = 35;
int csum[maxh][maxw];
void init(VVI vec) {
  assert(vec.size());
  REP(i, vec.size()) REP(j, vec[0].size()) {
    if(!i && !j) csum[i][j] = vec[i][j];
    else if(!i) csum[i][j] = csum[i][j-1] + vec[i][j];
    else if(!j) csum[i][j] = csum[i-1][j] + vec[i][j];
    else csum[i][j] = csum[i-1][j] + csum[i][j-1] - csum[i-1][j-1] + vec[i][j];
  }
}
// 閉区間, 0-indexedで矩形範囲の合計
int cumsum(int sx, int sy, int gx, int gy) {
  if(!sx && !sy) return csum[gy][gx];
  if(!sx) return csum[gy][gx] - csum[sy-1][gx];
  if(!sy) return csum[gy][gx] - csum[gy][sx-1];
  return csum[gy][gx] - csum[gy][sx-1] - csum[sy-1][gx] + csum[sy-1][sx-1];
}

int h, w, s;
PII dp[35][35][35][35];
PII func(int sx, int sy, int gx, int gy) {
  // cout << sx << " " << sy << " " << gx << " " << gy << endl;
  if(dp[sx][sy][gx][gy] != PII{-1, -1}) return dp[sx][sy][gx][gy];
  // cout << cumsum(0, 0, w-1, h-1) << " " << cumsum(sx, sy, gx, gy) << endl;
  if(cumsum(0, 0, w-1, h-1) - cumsum(sx, sy, gx, gy) > s) return {-1, -1};
  // 分割しない
  int group = 1, ret = cumsum(sx, sy, gx, gy);
  // 縦で割る
  FOR(i, sx, gx) {
    // cout << "i:" << i << endl;
    PII vl = func(sx, sy, i, gy);
    PII vr = func(i+1, sy, gx, gy);
    if(group < vl.first + vr.first || (group == vl.first+vr.first && ret < min(vl.second, vr.second))) {
      group = vl.first + vr.first;
      ret = min(vl.second, vr.second);
    }
  }
  // 横で割る
  FOR(i, sy, gy) {
    // cout << "i;" << i << endl;
    PII vl = func(sx, sy, gx, i);
    PII vr = func(sx, i+1, gx, gy);
    if(group < vl.first + vr.first || (group == vl.first+vr.first && ret < min(vl.second, vr.second))) {
      group = vl.first + vr.first;
      ret = min(vl.second, vr.second);
    }
  }
  // cout << sx << " " << sy << " " << gx << " " << gy << " " << group << "," << ret << endl;
  return dp[sx][sy][gx][gy] = {group, ret};
}

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

  while(true) {
    cin >> h >> w >> s;
    if(!h) break;
    VVI vec(h, VI(w));
    REP(i, h) REP(j, w) cin >> vec[i][j];

    init(vec);
    REP(i1, 35) REP(i2, 35) REP(i3, 35) REP(i4, 35) dp[i1][i2][i3][i4] = {-1, -1};
    PII ret = func(0, 0, w-1, h-1);
    cout << ret.first << " " << s - cumsum(0,0,w-1,h-1) + ret.second << endl;
  }

  return 0;
}



Measured memory_bytes: 26708