#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<list>
#include<queue>
#include<string.h>
#include<functional>
#include<stack>
#include<deque>
#include<string>
#include<limits.h>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
using namespace std;

string e[50];
int dp[50][50][4][1 << 11];//??¨??£??????1
int d[4] = { 9,11,11,9 };
int dx[4][11] = {
	{-3,-2,-2,-1,-1,-1,0,0,0},{-2,-2,-1,-1,-1,0,0,0,1,1,1},{-1,-1,-1,0,0,0,1,1,1,2,2},{0,0,0,1,1,1,2,2,3}
};
int dy[4][11] = {
	{0,-1,0,-2,-1,0,-3,-2,-1},{0,1,-1,0,1,-2,-1,1,-2,-1,0},{0,1,2,-1,1,2,-1,0,1,-1,0},{1,2,3,0,1,2,0,1,0}
};
bool used[50][50];
signed main() {
	int a, b, c; cin >> a >> b >> c;
	for (int i = 0; i < a; i++)cin >> e[i];
	memset(dp, -1, sizeof(dp));
	if (e[0][1] >= '1'&&e[0][1] <= '9') {
		dp[0][1][0][0] = e[0][1] - '0';
	}
	else if (e[0][1] == '.') {
		dp[0][1][0][0] = 0;
	}
	if (e[1][0] >= '1'&&e[1][0] <= '9') {
		dp[1][0][0][0] = e[1][0] - '0';
	}
	else if (e[1][0] == '.') {
		dp[1][0][0][0] = 0;
	}
	for (int i = 0; i < a + b + c * 2 + 8; i++) {
		for (int j = 0; j < a; j++) {
			for (int k = 0; k <= c; k++) {
				int l = i - j - k*2;
				if (l<0 || l>=b)continue;
				//??? j????¨? l ?????° k
				if (e[j][l] == '#')continue;
				for (int m = 0; m < (1 << d[k]); m++) {
					memset(used, false, sizeof(used));
					if (dp[j][l][k][m] == -1)continue;
					for (int r = 0; r < d[k]; r++) {
						if (m&(1 << r)) {
							used[j + dx[k][r]][l + dy[k][r]] = true;
						}
					}
					if (e[j][l] >= '1'&&e[j][l] <= '9') {
						used[j][l] = true;
					}
					//???
					if (j + 1 < a) {
						int sum = dp[j][l][k][m];
						if (e[j + 1][l] >= '1'&&e[j + 1][l] <= '9' && !used[j + 1][l]) {
							sum += e[j + 1][l] - '0';
						}
						int bit = 0;
						for (int i = 0; i < d[k]; i++) {
							int x = j + 1 + dx[k][i], y = l + dy[k][i];
							if (x >= 0 && x < a&&y >= 0 && y < b&&e[x][y] >= '1'&&e[x][y] <= '9'&&used[x][y]) {
								bit |= (1 << i);
							}
						}
						dp[j + 1][l][k][bit] = max(dp[j + 1][l][k][bit], sum);
					}
					//???
					if (l + 1 < b) {
						int sum = dp[j][l][k][m];
						if (e[j][l + 1] >= '1'&&e[j][l + 1] <= '9' && !used[j][l + 1]) {
							sum += e[j][l + 1] - '0';
						}
						int bit = 0;
						for (int i = 0; i < d[k]; i++) {
							int x = j + dx[k][i], y = l + 1 + dy[k][i];
							if (x >= 0 && x < a&&y >= 0 && y < b&&e[x][y] >= '1'&&e[x][y] <= '9' && used[x][y]) {
								bit |= 1 << i;
							}
						}
						dp[j][l + 1][k][bit] = max(dp[j][l + 1][k][bit], sum);
					}
					//???
					if (j - 1 >= 0&&k<c) {
						int sum = dp[j][l][k][m];
						if (e[j - 1][l] >= '1'&&e[j - 1][l] <= '9' && !used[j - 1][l]) {
							sum += e[j - 1][l] - '0';
						}
						int bit = 0;
						for (int i = 0; i < d[k+1]; i++) {
							int x = j - 1 + dx[k+1][i], y = l + dy[k+1][i];
							if (x >= 0 && x < a&&y >= 0 && y < b&&e[x][y] >= '1'&&e[x][y] <= '9' && used[x][y]) {
								bit |= 1 << i;
							}
						}
						dp[j - 1][l][k + 1][bit] = max(dp[j - 1][l][k + 1][bit], sum);
					}
					//???
					if (l - 1 >= 0&&k<c) {
						int sum = dp[j][l][k][m];
						if (e[j][l - 1] >= '1'&&e[j][l - 1] <= '9' && !used[j][l - 1]) {
							sum += e[j][l - 1] - '0';
						}
						int bit = 0;
						for (int i = 0; i < d[k+1]; i++) {
							int x = j + dx[k + 1][i], y = l - 1 + dy[k + 1][i];
							if (x >= 0 && x < a&&y >= 0 && y < b&&e[x][y] >= '1'&&e[x][y] <= '9' && used[x][y]) {
								bit |= 1 << i;
							}
						}
						dp[j][l - 1][k + 1][bit] = max(dp[j][l - 1][k + 1][bit], sum);
					}
				}
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < (1 << d[i]); j++) {
			ans = max(ans, dp[a - 1][b - 1][i][j]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 83164