#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int h, w, d;
cin >> h >> w >> d;
vector<string> g(h);
queue<pair<int,int>> q;
vector<vector<int>> dist(h, vector<int>(w, -1));
for (int i = 0; i < h; i++) {
cin >> g[i];
for (int j = 0; j < w; j++) {
if (g[i][j] == 'H') {
dist[i][j] = 0;
q.push({i, j});
}
}
}
int dr[] = {-1,1,0,0};
int dc[] = {0,0,-1,1};
while (!q.empty()) {
auto [r, c] = q.front(); q.pop();
if (dist[r][c] >= d) continue;
for (int k = 0; k < 4; k++) {
int nr = r + dr[k], nc = c + dc[k];
if (nr < 0 || nr >= h || nc < 0 || nc >= w) continue;
if (g[nr][nc] == '#') continue;
if (dist[nr][nc] != -1) continue;
dist[nr][nc] = dist[r][c] + 1;
q.push({nr, nc});
}
}
int cnt = 0;
for (int i = 0; i < h; i++)
for (int j = 0; j < w; j++)
if (dist[i][j] != -1) cnt++;
cout << cnt << "\n";
return 0;
}