#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <chrono>
#include <random>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int H, W, K;
VVI c;

void out(const VVI &vv) {
    FORE(v, vv) {
        FORE(e, v) cout << e;
        cout << endl;
    }
}

bool check(const VVI &vv) {
    int now = -1, cnt = -1;
    REP(i, H) {
        now = 0; cnt = 1;
        REP(j, W) {
            if (vv[i][j] == 0 || vv[i][j] != now) {
                if (cnt >= K) return true;
                now = (vv[i][j]) ? vv[i][j] : -1;
                cnt = 1;
            } else {
                cnt++;
            }
        }
    }
    return false;
}

void padding(VVI &vv) {
    REP(j, W) {
        int nxt = H - 1;
        RREP(i, H) {
            if (vv[i][j]) {
                vv[nxt][j] = vv[i][j];
                nxt--;
            }
        }
        REP(i, nxt + 1) {
            vv[i][j] = 0;
        }
    }
}

LL del(VVI &vv) {
    LL res = 0;
    REP(i, H) {
        int now = 0, cnt = 1;
        REP(j, W) {
            if (vv[i][j] == 0 || vv[i][j] != now) {
                if (j && vv[i][j - 1] > 0 && cnt >= K) {
                    res += cnt * now;
                    for (int k = j - 1; cnt; cnt--, k--) {
                        vv[i][k] = 0;
                    }
                }
                now = vv[i][j] > 0 ? vv[i][j] : -1;
                cnt = 1;
            } else {
                cnt++;
            }
        }
    }
    padding(vv);
    return res;
}

LL func(VVI vv, int ii, int jj) {
    LL res = del(c);
    LL num = res ? 2 : 1;
    vv[ii][jj] = 0;
    padding(vv);
    while (check(vv)) {
        res += del(vv) * num;
        num <<= 1;
    }
    //cout << ii << " "  << jj << " " << res << endl;
    return res;
}

int main(void) {
    scanf("%d%d%d", &H, &W, &K);
    c.resize(H, VI(++W));
    REP(i, H) {
        string s; cin >> s;
        REP(j, W) c[i][j] = s[j] - '0';
        c[i][W - 1] = -INF;
    }
    if (K > W) {
        cout << 0 << endl;
        return 0;
    }
    LL ans = 0;
    REP(i, H)REP(j, W) {
        ans = max(ans, func(c, i, j));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256