#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <set>
#include <map>
#include <bitset>

using namespace std;

const int N = 1005;

char f[N][N];

bool used[N][N];
int cused[N][N];
int pre[N][N];
int res[N][N];

pair<int, int> go(int x, int y, char c) {
    if (c == 'e' || c == 'E') ++y;
    if (c == 'w' || c == 'W') --y;
    if (c == 's' || c == 'S') ++x;
    if (c == 'n' || c == 'N') --x;
    return make_pair(x, y);
}

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

    int n, m, g;
    scanf("%d%d%d", &n, &m, &g);
    for (int i = 0; i < n; ++i) {
        scanf("%s", f[i]);
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (used[i][j]) continue;
            for (int x = 0; x < n; ++x) {
                for (int y = 0; y < m; ++y) {
                    cused[x][y] = 0;
                }
            }
            vector<pair<int, int>> was;
            int cx = i, cy = j;
            int curans = 0;
            int ctime = 1;
            bool fl = false;
            while (true) {
                if (used[cx][cy]) {
                    if (res[cx][cy] == 0) {
                        curans = ctime - cused[cx][cy];
                        fl = true;
                    } else {
                        curans = res[cx][cy];
                    }
                    break;
                }
                cused[cx][cy] = ctime;
                was.push_back(make_pair(cx, cy));
                used[cx][cy] = true;
                pair<int, int> to = go(cx, cy, f[cx][cy]);
                cx = to.first, cy = to.second;
                ++ctime;
            }
            if (curans > 0) {
                for (pair<int, int> cp : was) {
                    res[cp.first][cp.second] = curans;
                }
                if (fl) ans += curans;
            }
            //cout << i << ' ' << j << ' ' << curans << '\n';
        }
    }
    cout << ans;
    return 0;
}