#include <bits/stdc++.h>

using namespace std;

#define next dfogjofdiofgj

const int maxn = 1000;

int n, m, g;
char is_robot[maxn][maxn];
pair<int, int> next[maxn][maxn];

char used[maxn][maxn];
int dist[maxn][maxn];
pair<int, int> root[maxn][maxn];
int cnt[maxn][maxn];
int len[maxn][maxn];

void dfs(int x, int y, int &px, int &py, int d=0) {
    if (used[x][y]) {
        if (root[x][y].first == -1) {
            px = x; py = y;
            len[px][py] = d - dist[px][py];
        } else {
            tie(px, py) = root[x][y];
        }
        return;
    }
    used[x][y] = true;
    dist[x][y] = d;
    int nx, ny;
    tie(nx, ny) = next[x][y];
    dfs(nx, ny, px, py, d + 1);
}

void dfs2(int x, int y, int px, int py) {
    if (root[x][y].first != -1) return;
    root[x][y] = {px, py};
    if (is_robot[x][y]) cnt[px][py]++;
    int nx, ny;
    tie(nx, ny) = next[x][y];
    dfs2(nx, ny, px, py);
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);

    cin >> n >> m >> g;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < m; j++) {
            if ('A' <= s[j] && s[j] <= 'Z') {
                is_robot[i][j] = true;
                s[j] += 'a' - 'A';
            }
            if (s[j] == 'n') next[i][j] = {i - 1, j};
            else if (s[j] == 's') next[i][j] = {i + 1, j};
            else if (s[j] == 'e') next[i][j] = {i, j + 1};
            else if (s[j] == 'w') next[i][j] = {i, j - 1};
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            root[i][j] = {-1, -1};
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            int px, py;
            dfs(i, j, px, py);
            dfs2(i, j, px, py);
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            //cerr << "(" << root[i][j].first << ' ' << root[i][j].second << ") ";
            ans += min(len[i][j], cnt[i][j]);
        }
        //cerr << endl;
    }

    cout << ans << '\n';
}

