#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//---------------------------------------------------------------------------
ll modpow(ll a, ll n) {//a^n(MOD)を求める
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;//次の準備
        n >>= 1;
    }
    return res;
}
//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll h,w,k;cin>>h>>w>>k;
    ll a[30][30];
    for(ll i=0;i<h;i++){
        for(ll j=0;j<w;j++){
            char c;cin>>c;
            a[i][j]=c-'0';
        }
    }
    ll ans=0;
    for(ll i=0;i<h;i++){
        for(ll j=0;j<w;j++){
            ll b[30][30];
            for(ll x=0;x<h;x++){
                for(ll y=0;y<w;y++){
                    b[x][y]=a[x][y];
                }
            }
            b[i][j]=0;
            queue<Pll>del;
            del.push(mp(i,j));
            ll cnt=0;
            ll turn=0;
            
            
            //cout<<1<<endl;
            while(!del.empty()){
                //delete
                map<Pll,ll>m;
                while(!del.empty()){
                Pll p=del.front();del.pop();
                m[p]++;
                }
            
            //move
            
            for(ll x=0;x<w;x++){
                for(ll y=h-1;y>=0;y--){
                    if(m[{y,x}]){
                        bool xyz=0;
                        for(ll z=y-1;z>=0;z--){
                            if(m[{z,x}]==0){
                                b[y][x]=b[z][x];
                                m[{z,x}]=1;
                                xyz=1;
                                break;
                            }
                        }
                        if(xyz==0)
                            b[y][x]=-1;
                    }
                }
            }
                
            
            //push
            ll tmp=0;
            for(ll x=0;x<h;x++){
                for(ll y=0;y<w-k+1;y++){
                    ll prey=y;
                    if(b[x][y]==-1)continue;
                    bool xyz=1;
                    for(ll z=y+1;z<y+k;z++){
                        if(b[x][z]!=b[x][z-1]){
                            xyz=0;
                            break;
                        }
                    }
                    if(xyz==1){
                        for(ll z=y;z<w;z++){
                            if(b[x][z]==b[x][y]){
                            del.push(mp(x,z));
                            tmp+=b[x][z];
                              
                                prey=z;
                            }
                            else{
                                break;
                            }
                        }
                    }
                    y=prey;
                }
            }
   
            //if(i==3&&j==2)cout<<tmp<<endl;
            cnt+=modpow(2,turn)*tmp;
            turn++;
            }
            //cout<<cnt<<endl;
            chmax(ans,cnt);
        }
    }

    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------
/*
int n;cin>>n;
vector<int>a(n);
for(int i=0;i<n;i++)
    cin>>a[i];
*/


Measured memory_bytes: 384