#851
Platinum IV
TENKICI
스페셜 저지채점 준비중
시간 제한
1s
메모리 제한
32MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Mirko found a collection of NN toy tanks dating back to the Second World War on his grandfather's attic. He promptly called his friend Slavko to play with him. They made a battlefield – a wooden board consisting of squares in NN rows and NN columns.

Each tank can be moved to one of the four neighbouring squares in a single move. A tank can shoot at any square in the same row and column. The tank is said to be guarding the row and column it is in. Additionally, no two tanks can be in the same square at any time.

After many hours of play and two previous attempts, Mirko's mom yelled at them to come down for lunch again, and they decided to rearrange the tanks so that each tank guards a different row and column (meaning also that each row and column contains only one tank).

However, they want to do this using the minimum number of moves.

Write a program that finds the minimum number of moves required to rearrange the tanks so that each row and each column contains a single tank, and one such shortest sequence of moves.

입력

The first line of input contains the integer NN (5N5005 \le N \le 500).

Each of the following NN lines contains two integers RR and CC (1R,SN1 \le R, S \le N), the row and column of a single tank at the moment of mom's call. No two tanks are on the same square.

Rows and columns are marked 11 through NN, top-down and left-to-right.

출력

Output the minimum number of moves (call this number KK) on the first line.

Each of the next KK lines should contain the tank being moved and the direction it is moved in, separated by a single space.

Tanks are numbered 11 through NN, in the order in which they are given in the input.

The direction can be one of four uppercase letters: 'L' for left, 'R' for right, 'U' for up and 'D' for down.

Note: The sequence need not be unique.

채점

If both the number KK and the sequence of moves are correct, your program will score full points on the test case.

If your program outputs the correct number KK and does not output the sequence of moves, or the sequence of moves is incorrect, you will get 60% of the points for that test case.

예제 입력 1

5
1 1
1 2
1 3
1 4
1 5

예제 출력 1

10
1 D
2 D
3 D
4 D
1 D
2 D
3 D
1 D
2 D
1 D

예제 입력 2

5
2 3
3 2
3 3
3 4
4

예제 출력 2

8
1 R
1 R
2 U
2 U
4 D
4 D
5 L
5

예제 입력 3

6
1 1
1 2
2 1
5 6
6 5
6 6

예제 출력 3

8
2 R
2 D
3 D
3 R
4 U
4 L
5 L
5 U
코드 제출

이 문제는 현재 제출할 수 없습니다.

이 현상이 잘못되었다고 생각될 경우 관리자한테 문의주세요.

내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Platinum IV1명 투표· 약 1개월 전
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.