#P1724. Automated Movement in Gensokyo

    ID: 15009 Type: Default 1000ms 256MiB

Automated Movement in Gensokyo

Automated Movement in Gensokyo

In the fantastical land of Gensokyo, the high school miko Sanae is known for her enthusiasm for Gundam models. One day, she acquires the latest Steel Dam model, which features a new function: it can move automatically. The model follows a string of commands consisting of the characters \( E \), \( S \), \( W \), and \( N \), corresponding to the directions east, south, west, and north, respectively. Each command moves the robot one unit in the specified direction.

At time \( t = 0 \), Sanae places the Steel Dam at the coordinate \( (0, 0) \) and inputs the command string. The robot executes one command per second. After executing the last command in the string, it loops back to the start and continues. Your task is to determine the final coordinates of the Steel Dam after \( T \) seconds.

The movements are defined as follows:

  • East (E): \( (x+1, \; y) \)
  • South (S): \( (x, \; y-1) \)
  • West (W): \( (x-1, \; y) \)
  • North (N): \( (x, \; y+1) \)

Good luck!

inputFormat

The input consists of two lines:

  1. An integer \( T \) representing the total number of seconds.
  2. A non-empty string representing the command sequence. The string only contains the characters E, S, W, N.

outputFormat

Output two integers separated by a space, representing the final \( x \) and \( y \) coordinates of the Steel Dam after \( T \) seconds.

sample

5
E
5 0