Frog Freddy

mediumlinked list

Genie has been enjoying his vacations by a pond, while his pet frog Freddy is enjoying the pond.

The pond contains $$$n$$$ floating leaves, each defined by an $$$x$$$ and $$$y$$$ coordinate when viewed from above. From such a leaf $$$(x, y)$$$ Freddy can jump to:

  • $$$(x + d, y + d)$$$, where $$$d$$$ is any natural number. Call this direction $$$A$$$.

  • $$$(x + d, y - d)$$$, where $$$d$$$ is any natural number. Call this direction $$$B$$$.

  • $$$(x - d, y + d)$$$, where $$$d$$$ is any natural number. Call this direction $$$C$$$.

  • $$$(x - d, y - d)$$$, where $$$d$$$ is any natural number. Call this direction $$$D$$$.

Genie shouts one of the directions for Freddy to jump in $$$m$$$ times. Freddy jumps to the first leaf in the chosen direction. Once Freddy jumps from a leaf, it immediately sinks and disappears forever.

Freddy starts from the first leaf. Given all of Genie's commands, your task is to determine which leaf Freddy ends up on after all commands have been given.

Note that if there is no available leaf to jump to, the command will be skipped and Freddy will stay completely still.

Input Format:

The first line of input contains 2 integers $$$n$$$ and $$$m(1 \le n, m \le 10^5)$$$ — the number of leaves in the pond and the number of commands Genie shouts, respectively.

The second line of input contains a string of $$$m(A \le m_i \le D)$$$ characters — commands given out by Genie in sequence.

The next $$$n$$$ lines contain 2 integers $$$x_i$$$ and $$$y_i$$$ — representing the $$$x$$$ and $$$y(-10^9 \le x, y \le 10^9)$$$ coordinates of the $$$i^{th}$$$ leaf.

Output Format:

Output 2 integers, the final $$$x$$$ and $$$y$$$ coordinates of Freddy the Frog.

Examples:

Example 1:

Input:

7 5
ACDBB
5 6
8 9
4 13
1 10
7 4
10 9
3 7

Output:

7 4

Code

Loading Editor...