P1724 Sanae Kochiya

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 $\verb|E|$, $\verb|S|$, $\verb|W|$, $\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 $0$, Sanae places the Gundam at position $(0,0)$ and inputs the command string. She wants to know the coordinates of the Gundam after $T$ seconds. Assume the current position of the Gundam is $(x,y)$. For moves in the four directions, its coordinates change as follows: - Move east: the coordinates change to $(x+1,y)$. - Move south: the coordinates change to $(x,y-1)$. - Move west: the coordinates change to $(x-1,y)$. - Move north: the coordinates change to $(x,y+1)$.

Input Format

The first line contains a string $S$, the command string Sanae inputs, which is guaranteed to contain at least $1$ command. The second line contains a positive integer $T$.

Output Format

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

Explanation/Hint

Let $|S|$ denote the length of the command string Sanae inputs. - For $60\%$ of the testdata, $T \le 5\times 10^5$, $|S| \le 5\times 10^3$. - For $100\%$ of the testdata, $T \le 2\times 10^9$, $|S| \le 5\times 10^3$. Translated by ChatGPT 5