program cojs918;
var
i,j,k,m,n:longint;
c:array['A'..'Z'] of longint;
dx,dy,t:longint;
s:ansistring;
begin
assign(input,'android.in');
assign(output,'android.out');
reset(input);
rewrite(output);
readln(s);
readln(t);
n:=length(s);
for i:=1 to n do
inc(c[s[i]]);
dy:=dy+c['N']-c['S'];
dx:=dx+c['E']-c['W'];
k:=t div n;
dy:=k*dy;
dx:=k*dx;
t:=t mod n;
for i:=1 to t do
case s[i] of
'N':inc(dy);
'S':dec(dy);
'E':inc(dx);
'W':dec(dx);
end;
writeln(dx,' ',dy);
close(input);
close(output);
end.