#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <unordered_map>
#include <ctime>
#include <climits>

using namespace std;

unordered_map<char, pair<int, int> > ma;
unordered_map<char, bool> upper;
int ans = 0, n, m;

vector<vector<char> > v;
vector<vector<int> > deep;
vector<vector<bool> > color, ok, used2;
vector<pair<int, int> > del;
set<pair<int, int> > leafs;

pair<int, int> nnn(pair<int, int> vvv) {
	pair<int, int> new_vect = ma[v[vvv.first][vvv.second]];
	pair<int, int> new_v = vvv;
	new_v.first += new_vect.first;
	new_v.second += new_vect.second;

	return new_v;
}


void rec2(pair<int, int> vvv) {
	if (used2[vvv.first][vvv.second]) return;
	used2[vvv.first][vvv.second] = true;
	bool f = false;
	int sss[4][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };
	for (int i = 0; i < 4; i++) {
		auto new_v = vvv;
		new_v.first += sss[i][0];
		new_v.second += sss[i][1];
		if (new_v.first < 0 || new_v.second < 0 || new_v.first >= n || new_v.second >= m) continue;

		
		if (vvv == nnn(new_v)) {
			rec2(new_v);
			f = true;
		}
	}
	if (!f) leafs.insert(vvv);
	return;
}


void rec(pair<int, int> vvv, pair<int, int> pr, int mode) {
	if (!ok[vvv.first][vvv.second]) return;
	if (mode == 2)
		del.push_back(vvv);
	if (color[vvv.first][vvv.second]) {
		int act_deep = deep[pr.first][pr.second] + upper[v[vvv.first][vvv.second]];
		if (upper[v[vvv.first][vvv.second]]) v[vvv.first][vvv.second] -= 'A' - 'a';
		int ttt = act_deep;

		if (mode == 2) {
			ans += ttt;
			return;
		}

		auto new_v = vvv;
		do {
			if (ttt == 0) break;

			if (!upper[v[new_v.first][new_v.second]]) {
				ttt--;
				v[new_v.first][new_v.second] += 'A' - 'a';
			}

			pair<int, int> new_vect = ma[v[new_v.first][new_v.second]];
			new_v.first += new_vect.first;
			new_v.second += new_vect.second;

		} while (vvv != new_v);

		return;
	}

	pair<int, int> new_vect = ma[v[vvv.first][vvv.second]];
	pair<int, int> new_v = vvv;
	new_v.first += new_vect.first;
	new_v.second += new_vect.second;

	if (new_v.first < 0 || new_v.second < 0 || new_v.first >= n || new_v.second >= m) return;

	color[vvv.first][vvv.second] = true;
	deep[vvv.first][vvv.second] = deep[pr.first][pr.second] + upper[v[vvv.first][vvv.second]];
	if (upper[v[vvv.first][vvv.second]])
		v[vvv.first][vvv.second] -= 'A' - 'a';
	rec(new_v, vvv, mode);
}


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

	int g;
	cin >> n >> m >> g;
	v.resize(n);
	char trash;
	for (int i = 0; i < n; i++) {
		scanf("%c", &trash);
		v[i].resize(m);
		for (int j = 0; j < m; j++)
			scanf("%c", &v[i][j]);
	}
	ma['n'] = ma['N'] = make_pair(-1, 0);
	ma['s'] = ma['S'] = make_pair(1, 0);
	ma['e'] = ma['E'] = make_pair(0, 1);
	ma['w'] = ma['W'] = make_pair(0, -1);

	upper['N'] = upper['E'] = upper['S'] = upper['W'] = true;
	upper['n'] = upper['e'] = upper['s'] = upper['w'] = false;

	ok.resize(n + 1);
	for (int k = 0; k <= n; k++) {
		ok[k].resize(m + 1, true);
	}
	deep.resize(n + 1);
	color.resize(n + 1);

	used2.resize(n + 1);
	for (int i = 0; i < n; i++)
		used2[i].resize(m + 1);

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			rec2(make_pair(i, j));
	
	for (auto el : leafs) {
		for (int k = 0; k <= n; k++) {
			deep[k].resize(0);
			color[k].resize(0);
			deep[k].resize(m + 1, 0);
			color[k].resize(m + 1, false);
		}

		del.resize(0);
		rec(make_pair(el.first, el.second), make_pair(n, m), 1);
		for (auto el : del) ok[el.first][el.second] = false;
	}

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) {
			for (int k = 0; k <= n; k++) {
				deep[k].resize(0);
				color[k].resize(0);
				deep[k].resize(m + 1, 0);
				color[k].resize(m + 1, false);
			}

			del.resize(0);
			rec(make_pair(i, j), make_pair(n, m), 2);
			for (auto el : del) ok[el.first][el.second] = false;
		}

	cout << ans;

	return 0;
}