#include <bits/stdc++.h>

using namespace std;
vector < pair<int, int> > edg;
vector <int> used;
vector <int> kol, col;
vector <int> circ;
int ans = 0, uk;

void dfs (int v, int gl, int k){
    kol[v] = gl;
    used[v] = 1;
    col[v] = uk;
    if (used[edg[v].first] == 1){
        ans += min(k, (gl - kol[edg[v].first]) + 1);
        circ[uk] = (max(0, (gl - kol[edg[v].first]) + 1 - k));
    }
    if (used[edg[v].first] == 0)
        if (edg[edg[v].first].second == 0) dfs(edg[v].first, gl+1, k+1);
        else dfs(edg[v].first, gl+1, k);
    if (used[edg[v].first] == 2){
        if (circ[col[edg[v].first]] != 0){
            circ[col[edg[v].first]]--;
            ans++;
        }
    }
    used[v] = 2;
}

int main(){
    freopen("robots.in", "r", stdin);
    freopen("robots.out", "w", stdout);
    int n, m, g;
    cin >> n >> m >> g;
    edg.resize(n*m);
    used.resize(n*m, 0);
    kol.resize(n*m, 0);
    col.resize(n*m, -1);
    circ.resize(n, 0);
    for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++){
        char c;
        cin >> c;
        if (c == 'S' || c == 's'){
            edg[m*i + j].first = m*(i+1) + j;
            if (c == 'S') edg[m*i + j].second = 0;
            else edg[m*i + j].second = 1;
        }
        if (c == 'N' || c == 'n'){
            edg[m*i + j].first = m*(i-1) + j;
            if (c == 'N') edg[m*i + j].second = 0;
            else edg[m*i + j].second = 1;
        }
        if (c == 'E' || c == 'e'){
            edg[m*i + j].first = m*i + j+1;
            if (c == 'E') edg[m*i + j].second = 0;
            else edg[m*i + j].second = 1;
        }
        if (c == 'W' || c == 'w'){
            edg[m*i + j].first = m*i + j-1;
            if (c == 'W') edg[m*i + j].second = 0;
            else edg[m*i + j].second = 1;
        }
    }
    for (int i = 0; i < n*m; i++)
        if (used[i] == 0){
            uk = i;
            if (edg[i].second == 0) dfs(i, 1, 1);
            else dfs(i, 1, 0);
        }
    cout << ans << "\n";
    return 0;
}
