#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int p[100][100], q[100][100], H, W, K;
int chain() {
int score = 0, cnt = 0;
while (true) {
int r = 0;
for (int i = 0; i < H; i++) {
int L = 0;
for (int j = 0; j <= W; j++) {
if (q[i][j] != q[i][L] || q[i][j] == 11) {
if (j - L >= K) {
for (int k = L; k < j; k++) { r += q[i][k]; q[i][k] = 11; }
}
L = j;
}
}
}
for (int i = 0; i < W; i++) {
vector<int>W;
for (int j = H - 1; j >= 0; j--) {
if (q[j][i] <= 9)W.push_back(q[j][i]);
}
for (int j = H - 1; j >= 0; j--) { q[j][i] = 11; }
for (int j = 0; j < W.size(); j++) { q[H - 1 - j][i] = W[j]; }
}
if (r == 0)return score;
score += r*(1 << cnt); cnt++;
}
}
int main() {
cin >> H >> W >> K;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
char c; cin >> c;
if (c == '.')p[i][j] = 11;
else { p[i][j] = c - '0'; }
}
}
int maxn = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (p[i][j] == 11)continue;
for (int k = 0; k < H; k++) {
for (int l = 0; l < W; l++)q[k][l] = p[k][l];
}
q[i][j] = 11; vector<int>V;
for (int k = H - 1; k >= 0; k--) { if (q[k][j] <= 9)V.push_back(q[k][j]); }
for (int k = H - 1; k >= 0; k--) { q[k][j] = 11; }
for (int k = 0; k < V.size(); k++) { q[H - 1 - k][j] = V[k]; }
//cout << i << ' ' << j << ' ' << chain() << endl;
maxn = max(maxn, chain());
}
}
cout << maxn << endl;
return 0;
}