Toy Marbles
시간 제한2초메모리 제한256 MB
각 컨테이너에 구슬이 하나씩 들어 있을 때, 교환과 이동만으로 모든 구슬을 제 색 컨테이너로 옮기는 최소 동작 순서를 구한다.
문제
Busy Beaver has discovered that someone has mixed up his toy marbles!
There are containers, numbered from to . The -th container currently contains a single marble of color .
Busy Beaver wants to tidy up his marbles so that the -th container only contains marbles of color . To achieve this, he can perform either of the following actions any number of times (possibly zero):
- Swap the marbles in two containers and . After this action, all marbles from container move to container , and vice versa.
- Move all the marbles from one container to another container . After this action, container becomes empty, and all its marbles are moved to container .
Find a way to organize the marbles using the minimum number of actions.
입력
The first line contains an integer () — the number of containers.
The second line contains integers () — the marble initially in each container.
출력
On the first line, print a single integer — the minimum number of actions required.
On the next lines, describe the actions in order, one per line. Each action should be in one of the following formats:
1: Swap the marbles in containers and (; ).2: Move all marbles from container to container (; ).
If there are multiple ways to achieve the goal in the minimum number of actions, you may print any valid solution.