Bitovi

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

요약
집합 A의 원소 하나에서 비트 하나를 뒤집어 다른 수로 바꾸되, 바뀐 수가 그 시점의 A에 없어야 한다. A를 B로 만드는 아무 순서열이나 출력한다.
난이도

어려움10점 중 8점

유형
그래프, BFS, 그리디, 비트 연산
정답자
아직 제출이 없습니다

문제

What came first, the chicken or the egg? Is it better to live a hundred years as a millionaire or seven days in poverty? How to become a chess grandmaster? How to raise blinds? How to pass the final exams? How to train a dragon? These are interesting questions we can ponder only after the competition, but now we offer one less interesting computer science problem.

You are given two sets of numbers AA and BB of size NN. In one move, you can select an arbitrary element from set AA and change one arbitrary digit (bit) in its binary representation. The resulting number must not be an element of set AA immediately before the change.

For example, the number 55 in binary is 0101_20101\_2. In one move, it can become 13=1101_213 = 1101\_2, 1=0001_21 = 0001\_2, 7=0111_27 = 0111\_2, or 4=0100_24 = 0100\_2 if we change its 44th, 33rd, 22nd, or 11st bit, respectively.

Determine a sequence of moves by which set AA becomes equal to set BB. Sets are equal if they have the same size and there is no element in set AA that does not belong to set BB.

Note: The number of moves does not have to be minimal, but it must satisfy the task constraints.

입력

The first line contains the integer NN (1≤N≤2151 ≤ N ≤ 2^{15}), the size of the sets AA and BB.

The second line contains NN different integers a_ia\_i (0≤a_i<2150 ≤ a\_i < 2^{15}), the elements of the set AA.

The third line contains NN different integers b_ib\_i (0≤b_i<2150 ≤ b\_i < 2^{15}), the elements of the set BB.

출력

In the first line, print the number of required moves.

In the remaining lines, print the numbers xx and yy (0≤x,y<2150 ≤ x, y < 2^{15}) – we change the number xx from set AA to the number yy. The numbers xx and yy must differ by exactly one bit, and x∈Ax \in A and y∉Ay \not\in A must hold at the moment we execute the move.

예제3

  1. 예제 1

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

    입력
    3
    4 8 31
    0 4 8
    
    예상 출력
    5
    31 30
    30 28
    28 24
    24 16
    16 0
    
  3. 예제 3

    입력
    5
    0 1 2 4 5
    7 6 5 3 2
    
    예상 출력
    9
    1 3
    3 7
    0 1
    1 0
    2 6
    0 2
    7 3
    5 7
    4 5