#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
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 FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector< vector<int> > block_base(H + 2, vector<int>(W + 2, -1));
    vector< vector<int> > block(H + 2, vector<int>(W + 2, -1));

    FOR(i, 1, H) {
        string s;
        cin >> s;
        FOR(j, 1, W) {
            block_base[i][j] = int(s[j-1] - '0');
        }
    }
    int ans = 0;

    FOR(i_rm, 1, H)
        FOR(j_rm, 1, W) {
            FOR(i, 0, H+1) FOR(j,0, W+1) block[i][j] = block_base[i][j];

            // cerr << "remove : (" << i_rm << ", " << j_rm << ")" << endl;
            block[i_rm][j_rm] = 0;
            REP(z, H) {
                FORR(i, H, 1) {
                    FOR(j, 1, W) {
                        if(block[i][j] == 0) {
                            block[i][j] = block[i-1][j];
                            block[i-1][j] = 0;
                        }
                    }
                }
            }

            // cerr << "------------------------" << endl;
            // FOR(i, 1, H) {
            //     FOR(j, 1, W) cerr << block[i][j];
            //     cerr << endl;
            // }
            // cerr << "------------------------" << endl;
            
            bool update = true;

            int ans_cand = 0, t = 0;
            while(update) {
                update = false;
                int t_th_sum = 0;
                FOR(i, 1, H) {
                    int prev = -1, cont = 1;
                    FOR(j, 1, W+1) {
                        if(block[i][j] != prev) {
                            if(cont >= K) {
                                // cerr << "prev: " << prev << " cont: " << cont << endl;
                                t_th_sum += prev * cont;
                                REP(k, cont) block[i][j - 1 - k] = 0;
                                update = true;
                            }
                            cont = 1;
                            prev = block[i][j];
                        } else if(block[i][j] > 0) {
                            cont++;
                        }
                    }
                }

                REP(z, H) {
                    FORR(i, H, 1) {
                        FOR(j, 1, W) {
                            if(block[i][j] == 0) {
                                block[i][j] = block[i-1][j];
                                block[i-1][j] = 0;;
                            }
                        }
                    }
                }
                // cerr << "t: " << t << " t_th_sum: " << t_th_sum << endl;
                ans_cand += pow(2, t++) * t_th_sum;
            }
            ans = max(ans, ans_cand);
        }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4044