#include <bits/stdc++.h>

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

using namespace std;

using ll = long long;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

ll H, W, K;
vector<vector<ll>> c;
vector<vector<ll>> d;

void update() {
  for (int i = H - 1; i > 0; i--) {
    rep(j, W) {
      if (d.at(i).at(j) == -1) {
        int k = i - 1;
        while (k > 0 && d.at(k).at(j) == -1) {
          k--;
        }
        d.at(i).at(j) = d.at(k).at(j);
        d.at(k).at(j) = -1;
      }
    }
  }
}

void disp() {
  rep(i, H) {
    rep(j, W) {
      char buf[5];
      snprintf(buf, sizeof(buf), "%2d ", d.at(i).at(j));
      cerr << buf;
    }
    cerr << endl;
  }
  cerr << endl;
}

ll f(int y, int x) {
  d = c;
  d.at(y).at(x) = -1;

  ll ans = 0;
  ll p = 0;

  while (true) {
    update();

    vector<pair<int, pair<int, int>>> a;

    rep(i, H) {
      int st = 0;
      a.push_back({i, {st, st}});
      rep(j, W) {
        if (d.at(i).at(j) == -1) {
          st = j;
          continue;
        }

        if (d.at(i).at(j) == d.at(i).at(st)) {
          a.at(sz(a) - 1) = {i, {st, j}};
        } else {
          a.push_back({i, {st, st}});
          st = j;
        }
      }
    }

    bool found = false;
    ll p2 = pow(2, p);
    for (auto v : a) {
      int i = v.first;
      int st = v.second.first;
      int ed = v.second.second;
      if (ed - st + 1 >= K) {
        int sum = 0;
        for (int j = st; j <= ed; j++) {
          sum += d.at(i).at(j);
          d.at(i).at(j) = -1;
        }
        ans += p2 * sum;
        found = true;
      }
    }

    if (!found) break;
    p++;
  }

  return ans;
}

void solve() {
  ll ans = 0;
  rep(i, H) {
    rep(j, W) {
      ll v = f(i, j);
      ans = max(ans, v);
    }
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> H >> W >> K;
  c.resize(H, vector<ll>(W));
  rep(i, H) {
    string s;
    cin >> s;
    rep(j, W) c.at(i).at(j) = s.at(j) - '0';
  }

  solve();

  return 0;
}


Measured memory_bytes: 4048