#include <iostream>
#include <cstring>
using namespace std;

struct State {
    int num, demand;    // (テ」ツつーテ」ツδォテ」ツδシテ」ツδ療ヲツ閉ー, テヲツ慊?・ツ、ツァテヲツ環妥・ツ按カテゥツ慊?ィツヲツ?テヲツ慊?・ツーツ湘・ツ個?)
    State() {}
    State(int num, int demand) : num(num), demand(demand) {}

    /*
    bool operator>(const State& st) const {
        return num != st.num ? (num > st.num) : (demand < st.demand);
    }
    */
};

bool is_better(State s1, State s2) {
    return s1.num != s2.num ? (s1.num > s2.num) : (s1.demand > s2.demand);
}

const int INF = 1 << 28;

int u[40][40], cum_u[40][40];
State table[40][40][40][40];

bool used[40][40][40][40];

int h, w, s, all_demand;

int calc_sum(int t, int b, int l, int r) {
    int res = cum_u[b][r];
    if (l > 0) res -= cum_u[b][l - 1];
    if (t > 0) res -= cum_u[t - 1][r];
    if (l > 0 && t > 0) res += cum_u[t - 1][l - 1];
    return res;
}

State solve(int to, int bo, int le, int ri) {
    if (used[to][bo][le][ri]) {
        // cerr << "テ」ツ?禿」ツ?ョテゥツ?佚・ツ淞淌・ツ??」ツ?ョテゥツ慊?ィツヲツ?ゥツ?湘」ツ?ッ" << calc_sum(to, bo, le, ri) << endl;
        return table[to][bo][le][ri];
    }
    used[to][bo][le][ri] = true;

    /*
    cerr << "(to, bo, le, ri) " << to << ", " << bo << ", " << le << ", " << ri << endl;
    */
    int x = calc_sum(to, bo, le, ri);
    if (all_demand - s > x) {
        return table[to][bo][le][ri] = State(-INF, -INF);
    }
    // cerr << "(to, bo, le, ri) " << to << ", " << bo << ", " << le << ", " << ri << endl;
    State res = State(1, x);
    for (int r = to; r + 1 <= bo; r++) {
        State st;
        auto res1 = solve(to, r, le, ri),
             res2 = solve(r + 1, bo, le, ri);
        st = State(res1.num + res2.num, min(res1.demand, res2.demand));
        if (all_demand - s > st.demand) continue;
        if (is_better(st, res)) {
            res = st;
        }
    }
    for (int c = le; c + 1 <= ri; c++) {
        State st;
        auto res1 = solve(to, bo, le, c),
             res2 = solve(to, bo, c + 1, ri);
        st = State(res1.num + res2.num, min(res1.demand, res2.demand));
        if (all_demand - s > st.demand) continue;
        if (is_better(st, res)) {
            res = st;
        }
    }
    return table[to][bo][le][ri] = res;
}

int main() {
    while (cin >> h >> w >> s, h | w | s) {
        memset(cum_u, 0, sizeof(cum_u));
        memset(used, 0, sizeof(used));
        for (int r1 = 0; r1 < 40; r1++) {
            for (int c1 = 0; c1 < 40; c1++) {
                for (int r2 = 0; r2 < 40; r2++) {
                    for (int c2 = 0; c2 < 40; c2++) {
                        table[r1][c1][r2][c2] = State(-INF, INF);
                    }
                }
            }
        }

        for (int r = 0; r < h; r++) {
            for (int c = 0; c < w; c++) {
                cin >> u[r][c];
            }
        }

        for (int r = 0; r < h; r++) {
            for (int c = 0; c < w; c++) {
                cum_u[r][c] = u[r][c];
                if (c > 0) cum_u[r][c] += cum_u[r][c - 1];
            }
            if (r == 0) continue;
            for (int c = 0; c < w; c++) {
                cum_u[r][c] += cum_u[r - 1][c];
            }
        }

        all_demand = cum_u[h - 1][w - 1];

        auto res = solve(0, h - 1, 0, w - 1);
        cout << res.num << " " << s - (all_demand - res.demand) << endl;

        /*
        cerr << "debug" << endl;
        int r1, r2, c1, c2;

        while (cin >> r1 >> r2 >> c1 >> c2, r1 >= 0 && c1 >= 0) {
            auto res = solve(r1, r2, c1, c2);
            cout << "テゥツ慊?ィツヲツ?ゥツ?湘」ツ?ョテ・ツ青暗ィツィツ暗」ツ?ッ" << calc_sum(r1, r2, c1, c2) << endl;
            cout << "num: " << res.num << " " << "demand: " << res.demand << endl;
        }
        */
    }
    return 0;
}

Measured memory_bytes: 25568