Description
In the fantasy township, Dongfeng Gu Yingmio is known as up to the control of high school students Zhai Witch. One day, the early seedlings finally started the latest model of Steel dam. As the latest steel dam, of course, there is a different function with the past, that is, it can walk automatically, powerful (OK, my self-respect). The new model of early seedling can be moved according to the input command, which contains the four kinds of ' E ', ' S ', ' W ' and ' N ', corresponding to four different directions, which are East, south, west and north respectively. When a command is executed, it moves a unit in the corresponding direction. As a new type of robot, nature will not simply execute a command, it can execute command string. For the input command string, each second it acts as a command. After the last command of the command string is executed, the loop is automatically started from the beginning. At 0, the early seedling placed the steel dam in the position of the (0,0) and entered the command string. She wanted to know the coordinates of the steel dam where the T-second was.
Input
Line 1th: A string that represents the command string entered by the early seedling, guaranteeing at least 1 commands
Line 2nd: A positive integer t
Output
Line 1th: Two integers representing the coordinates of the steel dam at T sec
Sample Input
Nswwnsneewn
12
Sample Output
-1 3
Hint
For 60% data: T <= 500,000 and command string length <= 5,000
For 100% data: T <= 2,000,000,000 and command string length <= 5,000
Move eastward, change the coordinate change to (x+1,y);
Moving southward, the change of coordinate changed to (X,Y-1);
Moving westward, the change of coordinate changed to (x-1,y);
Moving northward, the change of coordinate changed to (x,y+1);
Simulation:
X[i] means to go before I command horizontal +x[i]
Y[i] Represents the previous command ordinate +y[i]
Then T-seconds can be executed how many times the entire command string is incremented X[l],yl
Then add the remaining t (T mod command string length) to the transverse ordinate to bring the change x[t],y[t].
var
x,y:array [0..5000] of Longint;
s:ansistring;
I,l,o,ansx,ansy:longint;
Begin
Readln (s);
READLN (o);
L:=length (s);
x[0]:=0; y[0]:=0;
For I:=1 to L do
begin
x[i]:=x[i-1]; y[i]:=y[i-1];
Case S[i] of
' E ': Inc (X[i]);
' S ':d EC (y[i]);
' W ':d EC (x[i]);
' N ': Inc (Y[i]);
End;
End;
For I:=1 to O Div. l do
begin
Ansx:=ansx+x[l];
ANSY:=ANSY+Y[L];
End;
Ansx:=ansx+x[o MoD l];
Ansy:=ansy+y[o MoD l];
Writeln (ANSX, ', ansy);
End.