atcoder#ABC150F. [ABC150F] Xor Shift

[ABC150F] Xor Shift

Score : 600600 points

Problem Statement

Given are two sequences a={a0,,aN1}a=\{a_0,\ldots,a_{N-1}\} and b={b0,,bN1}b=\{b_0,\ldots,b_{N-1}\} of NN non-negative integers each.

Snuke will choose an integer kk such that 0k<N0 \leq k < N and an integer xx not less than 00, to make a new sequence of length NN, a={a0,,aN1}a'=\{a_0',\ldots,a_{N-1}'\}, as follows:

  • ai=ai+kmodN XOR xa_i'= a_{i+k \mod N}\ XOR \ x

Find all pairs (k,x)(k,x) such that aa' will be equal to bb.

What is $\text{ XOR }$?

The XOR of integers AA and BB, A XOR BA \text{ XOR } B, is defined as follows:

  • When A XOR BA \text{ XOR } B is written in base two, the digit in the 2k2^k's place (k0k \geq 0) is 11 if either AA or BB, but not both, has 11 in the 2k2^k's place, and 00 otherwise.

For example, 3 XOR 5=63 \text{ XOR } 5 = 6. (In base two: 011 XOR 101=110011 \text{ XOR } 101 = 110.)

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 0ai,bi<2300 \leq a_i,b_i < 2^{30}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

a0a_0 a1a_1 ...... aN1a_{N-1}

b0b_0 b1b_1 ...... bN1b_{N-1}

Output

Print all pairs (k,x)(k, x) such that aa' and bb will be equal, using one line for each pair, in ascending order of kk (ascending order of xx for pairs with the same kk).

If there are no such pairs, the output should be empty.

3
0 2 1
1 2 3
1 3

If (k,x)=(1,3)(k,x)=(1,3),

  • a0=(a1 XOR 3)=1a_0'=(a_1\ XOR \ 3)=1
  • a1=(a2 XOR 3)=2a_1'=(a_2\ XOR \ 3)=2
  • a2=(a0 XOR 3)=3a_2'=(a_0\ XOR \ 3)=3

and we have a=ba' = b.

5
0 0 0 0 0
2 2 2 2 2
0 2
1 2
2 2
3 2
4 2
6
0 1 3 7 6 4
1 5 4 6 2 3
2 2
5 5
2
1 2
0 0

No pairs may satisfy the condition.