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

문제

Mirko received a birthday present from his aunt in the US – a brand-new doubly-linked list. The list contains NN nodes numbered 11 through NN. Two types of moves can be done on the list:

  • A) Move node XX in front of node YY.
  • B) Move node XX after node YY.

Mirko played with his new toy for hours, writing down each move on a piece of paper so that he can reconstruct the list's initial state (nodes 11 through NN in order from left to right).

When he decided to reconstruct the list, Mirko was astonished to find that there is no easy way to invert the moves and restore the list's initial state. Mirko cannot know where node XX was prior to each move, only where it ended up.

Seeing how Mirko is still recovering from the shock, write a program that finds a minimal sequence of moves that restored the list's initial state from Mirko's logs.

입력

The first line of input contains two integers NN and MM (2N5000002 \leq N \leq 500\,000, 0M1000000 \leq M \leq 100\,000), the number of nodes and the number of moves made by Mirko.

Each of the next MM rows contains a description of a single move made by Mirko – the type of move ('A' or 'B') and two integers XX and YY.

출력

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

Each of the next KK lines should contain a description of a single move in the same format as in the input.

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

2 1
A 2 1

예제 출력 1

1
A 1 2

예제 입력 2

4 3
B 1 2
A 4 3
B 1 4

예제 출력 2

2
A 1 2
B 4 3

예제 입력 3

6 5
A 1 4
B 2 5
B 4 2
B 6 3
A 3 5

예제 출력 3

3
A 4 5
B 6 5
A 2 3
코드 제출

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

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

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