atcoder#ARC124B. [ARC124B] XOR Matching 2

[ARC124B] XOR Matching 2

Score : 400400 points

Problem Statement

Given are sequences aa and bb, each of length NN, consisting of non-negative integers. The ii-th elements of aa and bb are aia_i and bib_i, respectively.

A non-negative integer xx is said to be good when the following condition is satisfied:

  • Condition: It is possible to permute bb so that ai XOR bi=xa_i \text{ XOR } b_i = x holds for every integer ii such that 1iN1 \leq i \leq N, where XOR \text{XOR } is the bitwise XOR.

List all good integers in ascending order.

What is $\mathrm{XOR}$?

The bitwise XOR\mathrm{XOR} of integers xx and yy, x XOR yx\ \mathrm{XOR}\ y, is defined as follows:

  • When x XOR yx\ \mathrm{XOR}\ y is written in base two, the digit in the 2k2^k's place (k0k \geq 0) is 11 if exactly one of xx and yy is 11, and 00 otherwise.
$$3\ \mathrm{XOR}\ 5 = 6$$$$011\ \mathrm{XOR}\ 101 = 110 $$

Constraints

  • All values in input are integers.
  • 1N20001 \leq N \leq 2000
  • 0ai,bi<2300 \leq a_i, b_i < 2^{30}

Input

Input is given from Standard Input in the following format:

NN

a1a_1 \cdots aNa_N

b1b_1 \cdots bNb_N

Output

In the first line, print KK, the number of good integers. Then, print KK more lines. In the ii-th of these KK lines, print the ii-th smallest good integer.

3
1 2 3
6 4 7
1
5
  • If we permute bb into (4,7,6)(4, 7, 6), we have $a_1 \text{ XOR } b_1 = a_2 \text{ XOR } b_2 = a_3 \text{ XOR } b_3 = 5$, so 55 is a good integer. There are no other good integers.
2
0 1
0 2
0
24
14911005 70152939 282809711 965900047 168465665 337027481 520073861 20800623 934711525 944543101 522277111 580736275 468493313 912814743 99651737 439502451 365446123 198473587 285587229 253330309 591640417 761745547 247947767 750367481
805343020 412569406 424258892 329301584 123050452 1042573510 1073384116 495212986 158432830 145726540 623594202 836660574 380872916 722447664 230460104 718360386 620079272 109804454 60321058 38178640 475708360 207775930 393038502 310271010
8
107543995
129376201
139205201
160626723
312334911
323172429
481902037
493346727