#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
    int h,w,k;
    std::cin >> h>>w>>k;
    vvector(fi,int,w,h,0);
    rep(j,h){
        string s;
        std::cin >> s;
        rep(i,w)fi[i][j]=s[i]-'0';
    }
    int ans=0;
    //std::cout << fi[0][3] << std::endl;
    rep(j,h){
        rep(i,w){
            vvector(dum,int,w,h,0);
            rep(jj,h){
               rep(ii,w)dum[ii][jj]=fi[ii][jj];
            }

           // std::cout << 3 << std::endl;
            dum[i][j]=0;
/*          rep(jj,h){
               rep(ii,w){
                   std::cout << dum[ii][jj];
               }
               std::cout  << std::endl;
            }*/
          //  std::cout << std::endl;
            int point=0;
            int ccounter=1;
            for(int bai=0;ccounter!=0;bai++){
            int counter=1;
            ccounter=0;
            for(;counter!=0;){//落下
            counter=0;
            rep(jj,h){
               rep(ii,w){
                   
                   if(dum[ii][jj]==0&&jj!=0){
                        for (int kk = jj; kk > 0; kk--) {
                            /* code */
                            counter+=abs(dum[ii][kk-1]-dum[ii][kk]);
                            dum[ii][kk]=dum[ii][kk-1];
                            
                            
                        }
                        dum[ii][0]=0;
                   }
                   
               }
            }
            
            }//ここまで落下
            
            vvector(dumdum,int,w,h,1);
            
            rep(jj,h){
               rep(ii,w-1){
                   if(dum[ii+1][jj]!=0&&dum[ii+1][jj]==dum[ii][jj])dumdum[ii+1][jj]=dumdum[ii][jj]+1;
                   
               }
            }
            int dumpoint=0;
            rep(jj,h){
               rep(ii,w){
                   
                   if(dumdum[ii][jj]>=k&& (ii==w-1||dumdum[ii+1][jj]<dumdum[ii][jj])){
                       for (int kk = 0; kk <dumdum[ii][jj]; kk++) {
                           /* code */
                           dumpoint+=dum[ii-kk][jj];
                           dum[ii-kk][jj]=0;
                           ccounter++;
                           
                       }
                       
                   }
                   
            
               }
               
            }

            point+=dumpoint*pow(2,bai);
            }
           // std::cout << point << std::endl;
            
       //     std::cout << point << std::endl;
            ans=max(point,ans);

        }
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 256