#pragma comment(linker, "/Stack:512000000")
#define	_CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <cctype>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long LL;
typedef double dbl;

#define all(x) (x).begin(), (x).end()

const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
const dbl EPS = 1e-9;


namespace g0 {

  vector<int> g;
  vector<int> p;
  vector<char> used;

  int dfs(int v) {
    used[v] = 1;
    p.push_back(v);

    if (used[g[v]] == 1) {
      int len = 1;
      while (p.size() && p.back() != g[v]) {
        len++;
        p.pop_back();
      }
      used[v] = 2;
      return len;
    }
    else if (!used[g[v]]) {
      int ans = dfs(g[v]);
      used[v] = 2;
      if (p.size() && p.back() == v)
        p.pop_back();
      return ans;
    }
    return 0;
  }

  void solve(int n, int m) {
    g.resize(n * m);
    used.resize(n * m);
    p.reserve(n * m);
    for (int i = 0; i < n; ++i) {
      string s;
      cin >> s;
      for (int j = 0; j < m; ++j) {
        switch (toupper(s[j])) {
        case 'N':
          g[i * m + j] = (i - 1) * m + j;
          break;
        case 'S':
          g[i * m + j] = (i + 1) * m + j;
          break;
        case 'E':
          g[i * m + j] = i * m + j + 1;
          break;
        case 'W':
          g[i * m + j] = i * m + j - 1;
          break;
        }
      }
    }

    int ans = 0;
    for (int i = 0; i < n * m; ++i)
      if (!used[i])
        ans += dfs(i);
    cout << ans << endl;
  }


}

namespace g1 {
  vector<int> g;
  void solve(int n, int m) {
    g.resize(n * m);
    for (int i = 0; i < n; ++i) {
      string s;
      cin >> s;
      for (int j = 0; j < m; ++j) {
        switch (toupper(s[j])) {
        case 'N':
          g[i * m + j] = (i - 1) * m + j;
          break;
        case 'S':
          g[i * m + j] = (i + 1) * m + j;
          break;
        case 'E':
          g[i * m + j] = i * m + j + 1;
          break;
        case 'W':
          g[i * m + j] = i * m + j - 1;
          break;
        }
      }
    }
    cout << 0 << endl;
  }
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#elif 1
#define PROB "robots"
	freopen(PROB".in", "r", stdin);
	freopen(PROB".out", "w", stdout);
#endif
	cin.tie(0);
	cin.sync_with_stdio(0);

  int n, m, g;
  cin >> n >> m >> g;

  if (!g) {
    using namespace g0;
    solve(n, m);
  }
  else {
    using namespace g1;
    solve(n, m);
  }

	return 0;
}