A String Problem
시간 제한2초메모리 제한2048 MB
원 위 2N개 핀을 짝지은 N개의 현이 주어질 때, 모든 현이 평행하도록 만드는 최소 이동 횟수와 이동 순서를 구한다.
문제
Lara loves flea markets. Last Saturday, there was the Rheinaue-Flohmarkt in Bonn, one of the biggest flea markets in Germany. Of course, Lara spent the whole day there, strolling through the market, haggling over prices, and buying all kinds of curious things. The most interesting thing she brought home was a small harp in a perfectly circular shape. When she wanted to start playing it, she noticed that the strings were all over the place rather than being parallel to each other.
More specifically, there are pins distributed evenly around the circular frame. Each of the strings is held in place by two of the pins, and every pin has exactly one string attached.
Lara does not know much about harps, but she strongly suspects that the strings should be aligned so that they are parallel to each other. To fix this issue, she decides to restring the harp. In each step, she can detach one end of a string from its pin and reattach it to a different pin. During the process it is okay if the ends of multiple strings are attached to the same pin. In the end, there should be exactly one string attached to every pin once again, and the strings should be parallel to each other.
Below you can find two examples of harps with parallel strings.

Since each step of restringing is a lot of work, Lara wants to restring the harp with as few steps as possible. Help Lara find a restringing sequence that takes the minimum number of steps!
입력
The first line of input contains one integer , denoting the number of strings. The strings are numbered from to .
Then follow lines, where the th line () contains two integers and , the two pins that hold the th string in place. The pins are numbered in clockwise order from to . Every pin has exactly one string attached.
출력
Output an integer , the minimum number of steps needed to restring the harp such that all strings are parallel to each other.
Further, output lines, each containing three integers , , and , denoting that in this step of your solution, one end of the th string should be detached from pin and reattached to pin (, ).
Note that if the th string is not attached to pin at that moment, the sequence of moves is considered to be incorrect.
If several answers exist, you may print any of them. Note that partially correct answers may still score some points, as explained in the next section.
제한
- .
- .
- All and are unique.