#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

long long mod_pow(long long n, long long p, long long m) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        long long t = mod_pow(n, p / 2, m);
        return (t * t) % m;
    }
    return n * mod_pow(n, p - 1, m) % m;
}

int h, w, k;
int a[35][35], b[35][35];

void erasing() {
    rep(i, w) {
        vector<int>exist;
        rep(j, h) {
            if (a[j][i] != 0) exist.push_back(a[j][i]);
        }
        reverse(exist.begin(), exist.end());
        int kaisuu = h - (int)exist.size();
        rep(bou, kaisuu) exist.push_back(0);
        reverse(exist.begin(), exist.end());
        rep(j, h) a[j][i] = exist[j];
    }
}

int pop() {
    int res = 0;
    rep(bou, 100) {
        int sum = 0;
        bool erase = false;
        rep(i, h) {
            int cnt = 1, num = a[i][0];
            for (int j = 1; j < w; ++j) {
                if (a[i][j] == a[i][j - 1]) {
                    cnt++;
                }
                else {
                    if (cnt >= k && num != 0) {
                        for (int l = j - cnt; l < j; l++) {
                            erase = true;
                            sum += a[i][l];
                            a[i][l] = 0;
                        }
                    }
                    cnt = 1; num = a[i][j];
                }
            }
            if (cnt >= k && num != 0) {
                for (int l = w - cnt; l < w; l++) {
                    erase = true;
                    sum += a[i][l];
                    a[i][l] = 0;
                }
            }
        }
        if (!erase) break;
        erasing();
        res += sum * mod_pow(2, bou, 1e9 + 7);
    }
    rep(l, h) {
        rep(m, w) {
            a[l][m] = b[l][m];
        }
    }
    return res;
}

int pop2() {
    int res = 0;
    rep(bou, 100) {
        rep(i, h) {
            rep(j, w) {
                cout << a[i][j] << " ";
            }
            cout << endl;
        }
        cout << endl;
        int sum = 0;
        bool erase = false;
        rep(i, h) {
            int cnt = 1, num = a[i][0];
            for (int j = 1; j < w; ++j) {
                if (a[i][j] == a[i][j - 1]) {
                    cnt++;
                }
                else {
                    if (cnt >= k && num != 0) {
                        for (int l = j - cnt; l < j; l++) {
                            erase = true;
                            sum += a[i][l];
                            a[i][l] = 0;
                        }
                    }
                    cnt = 1; num = a[i][j];
                }
            }
            if (cnt >= k && num != 0) {
                for (int l = w - cnt; l < w; l++) {
                    erase = true;
                    sum += a[i][l];
                    a[i][l] = 0;
                }
            }
        }
        if (!erase) break;
        erasing();
        res += sum * mod_pow(2, bou, 1e9 + 7);
    }
    rep(l, h) {
        rep(m, w) {
            a[l][m] = b[l][m];
        }
    }
    return res;
}

int main() {
    cin >> h >> w >> k;
    rep(i, h) {
        rep(j, w) {
            char c;
            cin >> c;
            int now = c - '0';
            a[i][j] = now, b[i][j] = now;
        }
    }
    int ans = 0;

    rep(i, h) {
        rep(j, w) {
            a[i][j] = 0;
            erasing();
            int now = pop();
            //cout << i << " " << j << " " << now << endl;
            ans = max(ans, now);

        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3468