Under construction

Still being built. Things may change

Drone Control

Interview

Time limit1sMemory limit1024 MB

Summary
Given obstacle cells and a string of U, D, R, L moves, find the drone's final position when it stays put whenever the next cell holds an obstacle.
Level

Easy2 of 10

Topics
Simulation, Hash map
Solved
No attempts yet

Problem

A drone starts at the origin of the coordinate plane. You can enter four kinds of commands.

  • U: increases the yy coordinate of the drone by 11.
  • D: decreases the yy coordinate of the drone by 11.
  • R: increases the xx coordinate of the drone by 11.
  • L: decreases the xx coordinate of the drone by 11.

There are also NN obstacles on the plane. If the cell that the drone tries to move into contains an obstacle, the drone does not move and stays where it is. Given the obstacle positions and the entered commands, find the final position of the drone.

Input

The first line contains two integers NN and KK, the number of obstacles and the number of commands, separated by a space. (1≤N,K≤5001 \leq N, K \leq 500)

The next NN lines each contain two integers xix_i and yiy_i, the coordinates of the ii-th obstacle, separated by a space. All obstacle positions are distinct, and there is no obstacle at the origin. (−500≤xi,yi≤500-500 \leq x_i, y_i \leq 500)

The (N+2)(N+2)-th line is a string of the entered commands. Each character of the string is one of U, D, R, or L.

Output

After all commands are entered, print the xx coordinate and the yy coordinate of the drone's position, separated by a space.

Examples1

  1. Example 1

    Input
    4 13
    -2 0
    1 1
    -1 -2
    2 -1
    LLLDDDRRRUUUR
    
    Expected output
    2 0