#include <bits/stdc++.h>
using namespace std;

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    while(true){
        int h,w,s;
        cin >> h >> w >> s;
        if(h==0 and w==0 and s==0) break;

        vector<vector<int>> u(h,vector<int>(w));
        rep(i,0,h) rep(j,0,w) cin >> u[i][j];

        vector<vector<int>> sum(h,vector<int>(w,0));
        rep(y,0,h){
            sum[y][0]=u[y][0];
            rep(x,1,w) sum[y][x]=sum[y][x-1]+u[y][x];
        }
        rep(x,0,w) rep(y,1,h) sum[y][x]=sum[y-1][x]+sum[y][x];
        auto calc_sum=[&](const int y1,const int x1,const int y2,const int x2){
            int res=sum[y2][x2];
            if(y1!=0) res-=sum[y1-1][x2];
            if(x1!=0) res-=sum[y2][x1-1];
            if(y1!=0 and x1!=0) res+=sum[y1-1][x1-1];
            return res;
        };

        static int memo1[32][32][32][32];
        static int memo2[32][32][32][32];
        fill_n((int*)memo1,32*32*32*32,0);
        fill_n((int*)memo2,32*32*32*32,inf);
        rep(i,0,h) rep(j,0,w){
            memo1[i][j][i][j]=1;
            memo2[i][j][i][j]=u[i][j];
        }
        const int all=calc_sum(0,0,h-1,w-1);
        function<pii(int,int,int,int)> rec=[&](const int y1,const int x1,const int y2,const int x2){
            int& res1=memo1[y1][x1][y2][x2],& res2=memo2[y1][x1][y2][x2];
            if(res1!=0) return make_pair(res1,res2);
            res1=1;
            res2=calc_sum(y1,x1,y2,x2);
            rep(y,y1,y2){
                if(all-calc_sum(y1,x1,y,x2)>s or all-calc_sum(y+1,x1,y2,x2)>s) continue;
                const auto tmp1=rec(y1,x1,y,x2),tmp2=rec(y+1,x1,y2,x2);
                if(tmp1.first+tmp2.first>res1){
                    res1=tmp1.first+tmp2.first;
                    res2=min(tmp1.second,tmp2.second);
                }else if(tmp1.first+tmp2.first==res1) res2=max(res2,min(tmp1.second,tmp2.second));
            }
            rep(x,x1,x2){
                if(all-calc_sum(y1,x1,y2,x)>s or all-calc_sum(y1,x+1,y2,x2)>s) continue;
                const auto tmp1=rec(y1,x1,y2,x),tmp2=rec(y1,x+1,y2,x2);
                if(tmp1.first+tmp2.first>res1){
                    res1=tmp1.first+tmp2.first;
                    res2=min(tmp1.second,tmp2.second);
                }else if(tmp1.first+tmp2.first==res1) res2=max(res2,min(tmp1.second,tmp2.second));
            }
            return make_pair(res1,res2);
        };
        auto ans=rec(0,0,h-1,w-1);
        cout << ans.first << " " << s-(all-ans.second) << endl;
    }
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cout << fixed << setprecision(8);
    solve();
    return 0;
}

Measured memory_bytes: 11468