Public Judge

pjudge

時間限制: 1 s 記憶體限制: 512 MB 總分: 100

#21791. 【NOIP Round #6】Exploration

统计

You have a robot moving on an infinite plane, starting at $(0,0)$.

You send it a sequence of instructions, each being one of L, R, U, D. If the robot's current position is $(x,y)$, these four instructions move it to $(x-1,y)$, $(x+1,y)$, $(x,y+1)$, and $(x,y-1)$, respectively.

There may be several obstacles on the plane, but you do not know their exact locations. When the robot attempts to move, it first checks if the target position contains an obstacle; if an obstacle exists, it ignores the instruction.

Given an instruction sequence of length $n$, determine all possible positions where the robot could be after executing these $n$ instructions.

Input

The first line contains a positive integer $n$.

The second line contains a string of length $n$ consisting of L, U, R, D, representing the sequence of operations.

Output

The first line contains a positive integer $k$, representing the number of possible positions.

The next $k$ lines each contain two integers $x_i, y_i$, representing a possible position. You must output all positions sorted in ascending order, using $x$ as the primary key and $y$ as the secondary key.

Examples

Input 1

2
RU

Output 1

4
0 0
0 1
1 0
1 1

Note 1

One possible scenario is that there is an obstacle at $(1,0)$ but not at $(0,1)$. In this case, the robot ignores the first instruction and then executes the second instruction, arriving at $(0,1)$.

Input 2

4
LRUD

Output 2

4
0 -1
0 0
1 -1
1 0

Constraints

For $20\%$ of the data, $1\le n\le 2$.

For $40\%$ of the data, $1\le n\le 4$.

For all data, $1\le n\le 20$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.