#include <stdio.h>

const int e = 100;
int n, m, g, f[e*e], vis[e*e], cycle[e*e], l[e*e], start, it;
char ch, a[e][e];

void dfs(int v)
{
	vis[v] = it;
	int x = v / m, y = v % m;
	if (a[x][y] == 'n')
	{
		if (vis[v - m] == it)
			cycle[v - m] = 1;
		if (!vis[v - m])
			dfs(v - m);
	}
	if (a[x][y] == 'e')
	{
		if (vis[v + 1] == it)
			cycle[v + 1] = 1;
		if (!vis[v + 1])
			dfs(v + 1);
	}
	if (a[x][y] == 's')
	{
		if (vis[v + m] == it)
			cycle[v + m] = 1;
		if (!vis[v + m])
			dfs(v + m);
	}
	if (a[x][y] == 'w')
	{
		if (vis[v - 1] == it)
			cycle[v - 1] = 1;
		if (!vis[v - 1])
			dfs(v - 1);
	}
}

void dfsl(int v, int k)
{
	int x = v / m, y = v % m;
	if (a[x][y] == 'n')
	{
		if (v - m == start)
			l[start] = k;
		else
			dfsl(v - m, k + 1);
	}
	if (a[x][y] == 'e')
	{
		if (v + 1 == start)
			l[start] = k;
		else
			dfsl(v + 1, k + 1);
	}
	if (a[x][y] == 's')
	{
		if (v + m == start)
			l[start] = k;
		else
			dfsl(v + m, k + 1);
	}
	if (a[x][y] == 'w')
	{
		if (v - 1 == start)
			l[start] = k;
		else
			dfsl(v - 1, k + 1);
	}
}

int main()
{
	freopen("robots.in", "r", stdin);
	freopen("robots.out", "w", stdout);
	scanf("%d%d%d\n", &n, &m, &g);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			scanf("%c", &ch);
			if (ch >= 'A' && ch <= 'Z')
			{
				ch = ch - 'A' + 'a';
				f[i * m + j] = 1;
			}
			a[i][j] = ch;
		}
		scanf("\n");
	}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (!vis[i * m + j])
			{
				it++;
				dfs(i * m + j);
			}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			if (cycle[i * m + j])
			{
				start = i * m + j;
				dfsl(i * m + j, 1);
			}
	int ans = 0;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			ans += l[i * m + j];
	printf("%d", ans);
	return 0;
}