Impact

시간 제한2초메모리 제한1024 MB

요약
두 통 사이에서 바닥에서 위로 옮기는 연산만 써서 푸딩을 다시 배치해, 두 통 모두 아래에서 위로 1..N 순서가 되도록 200,000번 이내의 연산을 출력한다.
난이도

보통10점 중 7점

유형
시뮬레이션, 그리디, 구현
정답자
아직 제출이 없습니다

문제

In the year 3025, RUN is hosting the 1015th KAIST ICPC Mock Competition! To give the NN participants a fresh impact, the organizers have prepared a total of NN different flavors of pudding for them. Since each participant has a unique taste preference distinct from others, the flavor each person desires is different and corresponds to one of the NN flavors prepared by the organizers. For each of the NN flavors, there are exactly 22 puddings available, resulting in a total of 2N2N puddings.

The organizers of this year wanted to display the puddings as beautifully as possible. Therefore, they prepared a total of 22 special containers to hold the puddings. Each container is designed to stack puddings in layers, with each container able to hold up to N+1N+1 puddings. The organizers want the flavors of the puddings in the first container to be 1,2,⋯ ,N1, 2, \cdots, N from the bottom up, and the flavors of the puddings in the second container to also be 1,2,⋯ ,N1, 2, \cdots, N from the bottom up.

The organizers asked the AI to fulfill this request, but the AI ignored the flavor conditions and randomly placed 2N2N puddings into each container! Therefore, the organizers wish to arrange the puddings as desired using the following operation.

  1. Select a container AA containing at least one pudding and a container BB capable of holding at least one additional pudding. Note that even if A=BA=B, BB must have space for at least one more pudding.
  2. Move the pudding at the bottommost of container AA to the topmost of container BB. After this, the pudding that was originally the iith from the bottom in container AA becomes the (i−1)(i-1)-th from the bottom.

The staff has limited time, so they want to perform the given operation no more than 200,000200,000 times to place all puddings into containers by flavor. Help the staff by writing a program that outputs a method to perform the operations.

입력

The first line contains a positive integer NN.

The next two lines contain the flavors of pudding in each container, separated by spaces. The first number n_in\_i on the iith line represents the number of puddings in the iith container. Following the first number on the iith line, n_in\_i integers are given. The jjth number among these represents the flavor of the jjth pudding from the bottom of the iith container.

출력

The first line outputs the number of operations MM to be performed.

The next MM lines each output two integers AA and BB. This signifies performing an operation where the pudding on bottom of the AA-th container is moved to the top of the BB-th container. It must hold that 1≤A,B≤21 \le A, B \le 2. Container AA must have contained at least one pudding, and container BB must not have been completely full of puddings.

After all operations are complete, each container must have puddings arranged so that their flavors are 1,2,⋯ ,N1, 2, \cdots, N from the bottom.

제한

  • 1≤N≤1001 \le N \le 100

힌트

The number of operations need not be minimized.

예제2

  1. 예제 1

    입력
    1
    2 1 1
    0
    
    예상 출력
    9
    1 2
    1 2
    2 1
    2 1
    1 2
    1 2
    2 1
    1 2
    2 1
    
  2. 예제 2

    입력
    2
    2 2 1
    2 2 1
    
    예상 출력
    6
    1 1
    2 2
    1 2
    2 1
    1 2
    2 1