#K52677. Treasure Hunt Coordinates

    ID: 29363 Type: Default 1000ms 256MiB

Treasure Hunt Coordinates

Treasure Hunt Coordinates

You are tasked with finding the final coordinates on a plane after following a series of directional instructions that are mixed with random characters. Each instruction consists of one of the directions N (north), S (south), E (east), or W (west) immediately followed by an integer (which may be negative) representing the distance to move in that direction.

The movements affect the coordinates as follows:

  • N: increases the y-coordinate by the given distance.
  • S: decreases the y-coordinate by the given distance.
  • E: increases the x-coordinate by the given distance.
  • W: decreases the x-coordinate by the given distance.

Mathematically, if you denote the final coordinates as \( (x, y) \), then the update rules are:

[ \begin{aligned} \text{For } N: \quad & y \mathrel{+}= d, \ \text{For } S: \quad & y \mathrel{-}= d, \ \text{For } E: \quad & x \mathrel{+}= d, \ \text{For } W: \quad & x \mathrel{-}= d. \end{aligned} ]

Your task is to process the input string and output the final coordinates as two space-separated integers.

inputFormat

The input consists of a single line containing a string s that includes directional characters (N, S, E, W) intermingled with numbers and other random characters. The numbers immediately following a direction represent the distance to move and may have a leading minus sign or leading zeros.

It is guaranteed that the string is non-empty.

outputFormat

Output the final coordinate as two space-separated integers representing the x and y coordinates. For example, if the final coordinate is \( (2, 6) \), output:

2 6

## sample
H3ll5oWor1dN10S4E2
2 6