#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define newline putchar('\n')
#define leave_space putchar(' ')
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
const int MAXN = 32;
int n, m, k;
char maze[MAXN][MAXN];
int use[MAXN][MAXN], cpy[MAXN][MAXN];
inline void falldown(int x, int y) {
	while (x && use[x - 1][y]) {
		swap(use[x][y], use[x - 1][y]); --x;
	}
}
inline lint dfs() {
	lint ret = 0;
	rep (i, 1, n) {
		int las = 0;
		vector<int> FD;
		rep (j, 1, m) {
			if (!use[i][j]) las = 0;
			else if (use[i][j] == use[i][j - 1]) ++las;
			else las = 1;
			if (las >= k) {
				ret += use[i][j];
				if (las == k) {
					ret += use[i][j] * (k - 1);
					rep (K, j - k + 1, j) {
						FD.pb(K);
					}
				} else {
					FD.pb(j);
				}
			}
		}
		for (auto p : FD) {
			use[i][p] = 0;
			falldown(i, p);
		}
	}
	if (ret) ret += dfs() * 2;
	return ret;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	cin >> n >> m >> k;
	rep (i, 1, n) {
		cin >> (maze[i] + 1);
		rep (j, 1, m) {
			cpy[i][j] = maze[i][j] - '0';
		}
	}
	lint ans = 0;
	rep (i, 1, n) {
		rep (j, 1, m) {
			memcpy(use, cpy, sizeof(use));
			use[i][j] = 0;
			falldown(i, j);
			ans = max(ans, dfs());
		}
	}
	cout << ans << endl;
	return 0;
}