Space-A
InterviewTime limit1sMemory limit1024 MB
Given a fixed string of R, U, X moves and a list of target points, count how many points the robot can reach by picking a subsequence of moves.
Problem
Seonu is in charge of Space-A, the core space exploration project of Ajuguk. Seonu uses an exploration robot to explore a newly discovered unknown planet.
The area to explore on the planet can be represented as a two-dimensional plane. The robot starts at . The robot can make three kinds of moves.
R: moves one cell in the direction in which the coordinate increases.U: moves one cell in the direction in which the coordinate increases.X: moves one cell diagonally, increasing both the and coordinates.
The order of the robot's moves is fixed in advance. Seonu picks some of the fixed moves at will and moves the robot with them. For example, suppose the fixed order is URURR. If Seonu picks the first, third, and fourth moves, the robot moves in the order UUR.
Given the points Seonu must explore on the planet, find how many of them can be explored by choosing the robot's moves appropriately.
Note that the task is to count the points reachable from the starting point, not the points the robot passes through on the way. The robot's starting position can always be explored.
Input
The first line contains the number of robot moves .
The second line contains the fixed order of the robot's moves as a string of length .
The third line contains the number of points Seonu wants to explore with the robot.
The next lines each contain the and coordinates of a point to explore, separated by a space.
No coordinate pair is given more than once.
Output
Print the number of points to explore, among the given points, that the robot can reach by choosing its moves appropriately.