Uses
  Math;
Const
  qwe:array[0..7]of char=('N','E','S','W','n','e','s','w');
  dx:array[0..3]of longint=(0,1,0,-1);
  dy:array[0..3]of longint=(-1,0,1,0);
Var
  n,m,g,i,j,z,ans,kol:longint;c:char;
  a,p:array[0..1001,0..1001]of byte;
  tw,tm,kolkl:array[0..1001,0..1001]of longint;
  ln,vs:array[1..1000000]of longint;
Procedure DFS(y,x,tk,numb,tkklet:longint);
Var
  ew:longint;
Begin
  if tw[y,x]=tk then
    begin
      ln[tk]:=tkklet-kolkl[y,x]+1;
      vs[tk]:=numb;
      exit;            
    end;
  if tw[y,x]<>0 then
    begin
      ln[tk]:=0;
      vs[tk]:=0;
      inc(vs[tw[y,x]],numb);
      exit;
    end;
  inc(tkklet);
  kolkl[y,x]:=tkklet;
  tw[y,x]:=tk;
  inc(numb,a[y,x]);
  tm[y,x]:=numb;
  ew:=p[y,x];
  inc(x,dx[ew]);
  inc(y,dy[ew]);
  dfs(y,x,tk,numb,tkklet);
end;
begin
//  assign(input,'input.txt');assign(output,'output.txt');
  assign(input,'robots.in');assign(output,'robots.out');
  readln(n,m,g);
  for i:=1 to n do
    begin
      for j:=1 to m do
        begin
          read(c);
          for z:=0 to 7 do
            if c=qwe[z] then
              begin
                a[i,j]:=1-(z div 4);
                p[i,j]:=z mod 4;
                break;
              end;
        end;
      readln;
    end;
  if g=0 then
    begin
      ans:=0;
      fillchar(tw,sizeof(tw),0);
      fillchar(tm,sizeof(tm),0);
      fillchar(ln,sizeof(ln),0);
      fillchar(vs,sizeof(vs),0);
      for i:=1 to n do
        for j:=1 to m do
          if (a[i,j]<=3)and(tw[i,j]=0) then
            begin
              inc(kol);
              DFS(i,j,kol,0,0);
            end;
      for i:=1 to kol do
        inc(ans,min(ln[i],vs[i]));
      writeln(ans);
    end;
end.
