#include<stdio.h>
#include<vector>

using namespace std;

/*
struct snm{
    vector<vector<pair<int,int> > > a;
    int n,m;
    snm(int _n, int _m){
        a.resize(n);
        for (int i = 0; i < n; i++){
            a[i].resize(m);
            for (int j = 0; j < m; j++){
                a[i][j] = pair<
            }
        }
    }
    int get(int x, int y);
};*/

struct snm{
    vector<int> a;
    vector<int> prior;
    snm(int n){
        a.resize(n);
        prior.resize(n, 1);
        for (int i = 0; i < n; i++){
            a[i] = i;
        }
    }

    int get(int x){
        if (x == a[x]){
            return x;
        }
        int g = get(a[x]);
        a[x] = g;
        return g;
    }

    void merg(int x, int y){
        x = get(x);
        y = get(y);
        if (x == y){
            return;
        }
        if (prior[x] > prior[y]){
            prior[x] += prior[y];
            a[y] = x;
        }
        else{
            prior[y] += prior[x];
            a[x] = y;
        }
    }
};

int ttime;
vector<vector<int> > col;
vector<vector<int> > a;

int dfs(int x, int y){
    col[x][y] = ttime;
    ttime++;
    int nx = x,ny = y;
    if (a[x][y] == 1){
        nx--;
    }
    if (a[x][y] == 2){
        ny++;
    }
    if (a[x][y] == 3){
        nx++;
    }
    if (a[x][y] == 4){
        ny--;
    }
    if (col[nx][ny] == 0){
        return dfs(nx, ny);
    }
    else{
        //printf("%d %d (%d): %d - %d(%d %d)\n", x, y, a[x][y], ttime, col[nx][ny], nx, ny);
        return ttime - col[nx][ny];
    }
}

int main(){
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);

    int n,m,g;
    scanf("%d %d %d", &n, &m, &g);

    bool b[n][m];
    //int a[n][m];
    a.resize(n);
    col.resize(n);
    for (int i = 0; i < n; i++){
        a[i].resize(m);
        col[i].resize(m);
    }

    for (int i = 0; i < n; i++){
        char s[m];
        scanf("%s", s);
        for (int j = 0; j < m; j++){
            if (s[j] < 'a'){
                b[i][j] = 1;
                s[j] -= 'A' - 'a';
            }
            else{
                b[i][j] = 0;
            }

            if (s[j] == 'e'){
                a[i][j] = 2;
            }
            if (s[j] == 'n'){
                a[i][j] = 1;
            }
            if (s[j] == 's'){
                a[i][j] = 3;
            }
            if (s[j] == 'w'){
                a[i][j] = 4;
            }
        }
    }

    snm sn(n*m);
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            if (a[i][j] == 1){
                sn.merg(i*m + j, (i-1)*m + j);
            }
            if (a[i][j] == 2){
                sn.merg(i*m + j, i*m + j+1);
            }
            if (a[i][j] == 3){
                sn.merg(i*m + j, (i+1)*m + j);
            }
            if (a[i][j] == 4){
                sn.merg(i*m + j, i*m + j-1);
            }
        }
    }

    int cicles[n][m];
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            cicles[i][j] = -1;
        }
    }

    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            int g = sn.get(i*m + j);
            int gx = g/m;
            int gy = g%m;
            if (cicles[gx][gy] == -1){
                ttime = 1;
                cicles[gx][gy] = dfs(gx, gy);
            }
        }
    }

    int robots[n][m];
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            robots[i][j] = 0;
        }
    }

    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            if (b[i][j]){
                int g = sn.get(i*m + j);
                int gx = g/m;
                int gy = g%m;
                robots[gx][gy]++;
            }
        }
    }

    long long out = 0;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            out += max(0, min(cicles[i][j], robots[i][j]));
        }
    }
    printf("%lld", out);
}
