#K79547. Robot's Visited Points

    ID: 35332 Type: Default 1000ms 256MiB

Robot's Visited Points

Robot's Visited Points

A robot is placed at the origin ((0,0)) of an infinite two-dimensional grid. It then follows a sequence of moves, where each move is one of the following four directions: 'U' (up), 'D' (down), 'L' (left), and 'R' (right). The robot records every grid point it visits, including the starting point ((0,0)).

You are given the length (n) of the move sequence, the move sequence itself, and a list of (m) grid points. Your task is to determine how many of the provided grid points have been visited by the robot at least once.

The input is provided via standard input and the output should be printed to standard output.

inputFormat

The input consists of multiple lines:

  1. The first line contains an integer (n), the length of the move sequence.
  2. The second line contains a string of (n) characters: each character is 'U', 'D', 'L', or 'R'.
  3. The third line contains an integer (m), the number of grid points to check.
  4. The following (m) lines each contain two space-separated integers (x) and (y) representing a grid point.

outputFormat

Output a single integer representing the number of grid points from the list that have been visited by the robot at least once.## sample

6
URRDUL
5
0 0
1 1
1 0
0 1
-1 0
3