Under construction

Still being built. Things may change

Bitovi

Time limit1sMemory limit1024 MB

Summary
Given two sets A and B of N numbers below 2^15, output single-bit flips that turn A into B, where each target must not already be in A.
Level

Hard8 of 10

Topics
Graph, BFS, Greedy
Solved
No attempts yet

Problem

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 010120101_2. In one move, it can become 13=1101213 = 1101_2, 1=000121 = 0001_2, 7=011127 = 0111_2, or 4=010024 = 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.

Input

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

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

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

Output

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

In the remaining lines, print the numbers xx and yy (0≤x,y<2150 \le x, y < 2^{15}). This means 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.

Examples3

  1. Example 1

    Input
    3
    0 1 2
    1 2 3
    
    Expected output
    2
    1 3
    0 1
    
  2. Example 2

    Input
    3
    4 8 31
    0 4 8
    
    Expected output
    5
    31 30
    30 28
    28 24
    24 16
    16 0
    
  3. Example 3

    Input
    5
    0 1 2 4 5
    7 6 5 3 2
    
    Expected output
    9
    1 3
    3 7
    0 1
    1 0
    2 6
    0 2
    7 3
    5 7
    4 5