#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>

using namespace std;

#define NAME "robots"
#define _NO_WARNINGS
#define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);
#define all(x) x.begin(), x.end()
#define forn(i, n) for(ll i = 0; i < n; i++)
#define ll long long
#define pii pair<ll, ll>

ll used[1001][1001];
ll pt[1001][1001], cnt[1001][1001];
pii cycle[1001][1001];
string mas[1001];
vector<ll> ans;
pii st = pii(-1, -1);
pii last = st;
ll sz = 0;
ll SIZE = 0, BIG = 0, MAY = 0;
ll num = 1;
ll pos[1001][1001], posq[1001][1001];
pii val[10000001];
ll big = 0;
vector<pii> t;

void dfs(ll i, ll j, ll c = 0) {
	used[i][j] = 1;
	t.push_back(pii(i, j));
	sz++;
	//cout << i << " " << j << "\n";
	cnt[i][j] = sz;
	char sym = toupper(mas[i][j]);
	c += (mas[i][j] == sym);
	pt[i][j] = c;
	ll i1 = i, j1 = j;
	if (sym == 'S')
		i1++;
	if (sym == 'N')
		i1--;
	if (sym == 'E')
		j1++;
	if (sym == 'W')
		j1--;
	if (used[i1][j1] == 0)
		dfs(i1, j1, c);
	else
		if (used[i1][j1] == 1) {
			st = pii(i1, j1);
			last = pii(i, j);
			SIZE = cnt[i][j] - cnt[i1][j1] + 1;
			BIG = pt[i][j] - pt[i1][j1];
			sym = toupper(mas[i1][j1]);
			BIG += (sym == mas[i1][j1]);
			big = c;
		}
		else {
			if (pos[i1][j1] != 0) {
				MAY = pos[i1][j1];
				big = c;
			}	
		}
	used[i][j] = 2;
}

void dfs2(ll i, ll j) {
	ll i1 = i, j1 = j;
	pos[i][j] = num;
	char sym = toupper(mas[i][j]);
	if (sym == 'S')
		i1++;
	if (sym == 'N')
		i1--;
	if (sym == 'E')
		j1++;
	if (sym == 'W')
		j1--;
	if (last == pii(i, j)) 
		return;
	dfs2(i1, j1);

}

int main() {
	ios_base::sync_with_stdio(0);
	FREOPEN;
	ll n, m, g;
	cin >> n >> m >> g;
	forn(i, n) {
		cin >> mas[i];
	}
	if (g == 1) {
		return 0;
	}
	ll ans = 0;
	forn(i, n)
		forn(j, m) {
			if (used[i][j] == 0) {
				//cout << i << " " << j << ":------\n";
				st = pii(-1, -1);
				sz = 0;
				BIG = 0, SIZE = 0;
				big = 0;
				MAY = 0;
				t.clear();
				dfs(i, j);
				if (st != pii(-1, -1)) {
					dfs2(i, j);
					val[num] = pii(SIZE - BIG, 0);
					ans += BIG;
					ans += min(val[num].first, big - BIG);
					val[num].first -= min(val[num].first, big - BIG);
					//cout << BIG << " " << SIZE;
					num++;
				}
				else {
					if (MAY != 0) {
						forn(i, t.size())
							pos[t[i].first][t[i].second] = MAY;
						ans += min(val[MAY].first, big - BIG);
						val[MAY].first -= min(val[MAY].first, big - BIG);
					}
				}
				//cout << "()" << ans.size() << "\n";
			}
		}
	//cout << pos[0][3];
	cout << ans;
	return 0;
}