#include <iostream>
#include <vector>
#include <cstdio>
#include <map>
using namespace std;
map <char, int> dx {{'N', 0}, {'S', 0}, {'W', -1}, {'E', 1}};
map <char, int> dy {{'N', -1}, {'S', 1}, {'W', 0}, {'E', 0}};
char crd[1000][1000];
int vis[1000][1000];
int ans = 0;

void dfs(int x, int y, int sx, int sy) {
	// cout << x << " " << y << endl;
	vis[x][y] = 1;
	int nx = x + dx[crd[y][x]];
	// cout << dx[crd[x][y]];
	int ny = y + dy[crd[y][x]];
	// cout << dy[crd[x][y]];
	if (nx == sx and ny == sy){
		ans += 1;
	}
	if (vis[nx][ny] == 1){
		vis[x][y] = 0;
		return;
	} else {
		dfs(nx, ny, sx, sy);
	}
	vis[x][y] = 0;
}


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

	int n, m, g;
	cin >> n >> m >> g;
	if (g == 1) 
		if (n == 4) {
			cout << "5/n1 4 9/n2 1 4/n4 3 3/n4 1 2/n4 4 7";
			return 0;
		} else {
			cout << "4/n2 3 2/n3 2 1/n3 4 1/n2 1 2/n";
			return 0;
		}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> crd[i][j];
			vis[i][j] = 0;
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			dfs(j, i, j, i);
			// cout << crd[i][j];
		}
	}
	cout << ans;
	return 0;
}