#P1724. 东风谷早苗

东风谷早苗

Description

In Gensokyo, Sanae Kochiya is a high school otaku shrine maiden known as a Gundam superfan. One day, she finally got her hands on the latest Gundam model. As the newest Gundam, of course it has a new feature: it can walk automatically. Impressive, right (okay, I’ll behave). Sanae’s new model can move according to the input commands. The commands are E\verb|E|, S\verb|S|, W\verb|W|, N\verb|N|, corresponding to the four directions: east, south, west, and north, respectively. When executing a command, it moves one unit in the corresponding direction. As a new type of robot, it can execute a command string rather than a single command. For the input command string, it executes one command per second. After finishing the last command in the string, it automatically loops back to the beginning. At time 00, Sanae places the Gundam at position (0,0)(0,0) and inputs the command string. She wants to know the coordinates of the Gundam after TT seconds.

Assume the current position of the Gundam is (x,y)(x,y). For moves in the four directions, its coordinates change as follows:

  • Move east: the coordinates change to (x+1,y)(x+1,y).
  • Move south: the coordinates change to (x,y1)(x,y-1).
  • Move west: the coordinates change to (x1,y)(x-1,y).
  • Move north: the coordinates change to (x,y+1)(x,y+1).

Input Format

The first line contains a string SS, the command string Sanae inputs, which is guaranteed to contain at least 11 command. The second line contains a positive integer TT.

Output Format

Output two integers on one line, the coordinates of the Gundam at time TT seconds.

NSWWNSNEEWN
12

-1 3

Hint

Let S|S| denote the length of the command string Sanae inputs.

  • For 60%60\% of the testdata, T5×105T \le 5\times 10^5, S5×103|S| \le 5\times 10^3.
  • For 100%100\% of the testdata, T2×109T \le 2\times 10^9, S5×103|S| \le 5\times 10^3.

Translated by ChatGPT 5