March First
InterviewTime limit1sMemory limit1024 MB
Move water between three sukwoo, where each move cools the water by 5 degrees, to reach the target temperatures and final arrangement in at most 40 moves.
- Level
Medium4 of 10
- Topics
- BFS, Simulation
- Solved
- No attempts yet
Problem
A tea gathering called 'March First' is held. Members often meet to share tea and dasik (Korean tea confections) and strengthen their friendship.
One day, Choseungdal, the pangju (the person who brews the tea) who leads the gathering, learned the following fact from the owner of a teahouse he often visits.
Each time hot water in a sukwoo is moved to another sukwoo, its temperature drops by ℃.
A sukwoo, also called a gongdobae, is a tea utensil used to divide brewed water or to cool the water used for brewing. Having learned that water cools each time it is moved, Choseungdal wants to use the sukwoo he owns to prepare several kinds of water at different target temperatures, so he can brew several kinds of tea at once.

Choseungdal has N sukwoo, numbered 1 to N. Sukwoo 1 to N-1 are filled in order with water 1 to N-1, and sukwoo N is empty. Each of the N-1 waters has a target temperature. The water initially placed in a sukwoo is 100℃. Water can only be moved into an empty sukwoo, and all the water in a sukwoo must be moved.
Move water between sukwoo to lower its temperature until each target is met. Then arrange water 1 to N-1 in the sukwoo so that each water is in its correct sukwoo.
Input
The first line contains the number of sukwoo N.
The second line contains the target temperatures of water 1 to N-1, separated by spaces. , is a multiple of 5$$)
The third line contains the numbers of the water that must be in sukwoo 1 to N after the moves, separated by spaces. Water numbers are distinct positive integers from 1 to N-1. An empty sukwoo is given as .
Output
If the goal cannot be reached, print on the first line.
Otherwise, print the number of moves on the first line. On each of the next lines, print , separated by a space, which means the water in sukwoo is moved to sukwoo . and are distinct positive integers.
If there are several valid methods, print any one of them.