#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
using pis = pair<int, string>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

void copy_field(vector<vector<int>> &field, vector<vector<int>> &original) {
  for (int i = 0; i < field.size(); i++) for (int j = 0; j < field[0].size(); j++) field[i][j] = original[i][j];
  return;
}

bool check(vector<vector<int>> &field, vector<vector<int>> &checkfield, int k) {
  int h = field.size(), w = field[0].size();
  bool flag = false;
  for (int i = 0; i < h; i++) {
    if (k == 1) {
      for (int j = 0; j < w; j++) {
        if (field[i][j] != 0) {
          checkfield[i][j] = 1;
          flag = true;
        }
      }
      continue;
    }
    int before = field[i][0], cnt = 1;
    for (int j = 1; j < w; j++) {
      if ((before != 0) && (before == field[i][j])) {
        cnt++;
        if (cnt >= k) {
          checkfield[i][j] = 1;
          flag = true;
        }
      }
      else {
        cnt = 1;
        before = field[i][j];
      }
    }
    //cout << "fin" << endl;
    for (int j = w-1; j >= k-1; j--) {
      if ((checkfield[i][j] == 1) && (checkfield[i][j-1] == 0)) {
        for (int l = 0; l < k-1; l++) {
          j--;
          checkfield[i][j] = 1;
        }
      }
    }
  }
  //cout << "all-fin" << endl;
  return flag;
}

void init_checkfield(vector<vector<int>> &checkfield) {
  for (int i = 0; i < checkfield.size(); i++) for (int j = 0; j < checkfield[0].size(); j++) checkfield[i][j] = 0;
  return;
}

void init_field(vector<vector<int>> &field, int erase) {
  int w = field[0].size();
  for (int i = erase/w; i > 0; i--) {
    field[i][erase%w] = field[i-1][erase%w];
  }
  field[0][erase%w] = 0;
}

void printfield(vector<vector<int>>&field) {
  for (int i = 0; i < field.size(); i++) {
    for (int j = 0; j < field[0].size(); j++) {
      cout << field[i][j] << " ";
    }cout << endl;
  }cout << endl;
  return;
}

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

  int h,w, k;
  cin >> h >> w >> k;
  vector<vector<int>> field(h, vector<int>(w)), original(h, vector<int>(w)), checkfield(h, vector<int>(w));
  //for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) cin >> original[i][j];
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) {
      original[i][j] = (int)(s[j] - '0');
    }
  }

  int ans = -1;
  for (int erase = 0; erase < h*w; erase++) {
    copy_field(field, original);
    init_checkfield(checkfield);
    //field[erase/h][erase%h] = 0;
    init_field(field, erase);
    int db = 1;
    int temp = 0;
    while(check(field, checkfield, k)) {
      //cout << "check" << erase << endl;
      //printfield(checkfield);
      
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          if (checkfield[i][j] == 1) {
            temp += db * field[i][j];
            field[i][j] = 0;
          }
        }
      }
      
      for (int i = h-2; i >= 0; i--) for (int j = 0; j < w; j++) checkfield[i][j] += checkfield[i+1][j];

      for (int i = h-1; i >= 0; i--) {
        for (int j = 0; j < w; j++) {
          if ((field[i][j] == 0) || (checkfield[i][j] == 0)) continue;
          if (i + checkfield[i][j] < h) {
            field[i+checkfield[i][j]][j] = field[i][j];
            field[i][j] = 0;
          }
          else field[i][j] = 0;
        }
      }
      db *= 2;
      init_checkfield(checkfield);
      //cout << "fin" << endl;
    }
    //cout << temp << endl;
    ans = max(ans, temp);
  }

  cout << ans << endl;
}


Measured memory_bytes: 3600