#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------
using vvint = vector<vector<int>>;

void printBoard(vvint &a, int w, int h)
{
    cout << "--------------------------------------" << endl;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cout << a[i][j] << ' ';
        }
        cout << endl;
    }
    cout << "--------------------------------------" << endl;
}

void Arrange(vvint &a, int h, int w)
{
    // 整列する
    for (int x = 0; x < w; x++)
    {
        // fi:元々何番目だったか, se:そのマスの値
        vector<pair<int, int>> rec(h);
        // マスの値を一時保存
        vector<int> rec2(h);
        int cnt = 0;
        for (int y = 0; y < h; y++)
        {
            rec[y].first = y;
            if (a[y][x] == -1)
            {
                rec[y].second = -INF;
            }
            else
            {
                rec[y].second = cnt;
                cnt++;
            }
        }
        sort(ALL(rec), [](const auto &p, const auto &q) { return p.second < q.second; });
        for (int i = 0; i < h; i++)
        {
            rec2[i] = a[i][x];
        }
        for (int i = 0; i < h; i++)
        {
            a[i][x] = rec2[rec[i].first];
        }
    }
}

int del(vvint &a, int h, int w, int k)
{
    // 消えたところは一旦-1にする
    int sum = 0;
    for (int y = 0; y < h; y++)
    {
        for (int x = 0; x < w - k + 1; x++)
        {
            if (a[y][x] == -1)
            {
                continue;
            }
            int r = x;
            while (r + 1 < w && a[y][r + 1] == a[y][x])
            {
                r++;
            }
            if (r - x + 1 >= k)
            {
                for (int i = x; i <= r; i++)
                {
                    sum += a[y][i];
                    a[y][i] = -1;
                }
                x = r;
            }
        }
    }
    // 整列する
    Arrange(a, h, w);

    return sum;
}

ll power(ll n, ll k)
{
    if (k == 0)
    {
        return 1;
    }
    else if (k % 2 == 1)
    {
        return power(n, k - 1) * n;
    }
    else
    {
        ll t = power(n, k / 2);
        return t * t;
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w, k;
    cin >> h >> w >> k;
    vvint b(h, vector<int>(w));
    for (int i = 0; i < h; i++)
    {
        string s;
        cin >> s;
        for (int j = 0; j < w; j++)
        {
            b[i][j] = int(s[j] - '0');
        }
    }
    ll ans = -LLINF;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            vvint a = b;
            ll res = 0;
            a[i][j] = -1;
            ll cnt = 0;
            Arrange(a, h, w);
            // if(i == 3 && j == 2){
            //     printBoard(a,w,h);
            // }
            while (1)
            {
                int tmp = del(a, h, w, k);
                // if (i == 3 && j == 2)
                // {
                //     printBoard(a, w, h);
                //     cout << power(2LL, cnt) * tmp << endl;
                // }
                res += power(2LL, cnt) * tmp;
                if (tmp == 0)
                {
                    break;
                }
                cnt++;
            }
            chmax(ans, res);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256