Problem:
Score : 600 points

Problem Statement

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

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

a_i'= a_{i+k \mod N}\ XOR \ x

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

What is \mbox{ XOR }?

The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:

When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if either A or B, but not both, has 1 in the 2^k's place, and 0 otherwise.

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

Constraints

1 \leq N \leq 2 \times 10^5

0 \leq a_i,b_i < 2^{30}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
a_0 a_1 ... a_{N-1}
b_0 b_1 ... b_{N-1}

Output

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

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

Sample Input 1

3
0 2 1
1 2 3

Sample Output 1

1 3

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

a_0'=(a_1\ XOR \ 3)=1

a_1'=(a_2\ XOR \ 3)=2

a_2'=(a_0\ XOR \ 3)=3

and we have a' = b.

Sample Input 2

5
0 0 0 0 0
2 2 2 2 2

Sample Output 2

0 2
1 2
2 2
3 2
4 2

Sample Input 3

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

Sample Output 3

2 2
5 5

Sample Input 4

2
1 2
0 0

Sample Output 4

No pairs may satisfy the condition.

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(uint.Parse).ToArray();
        var b = Console.ReadLine().Split().Select(uint.Parse).ToArray();
        //奇数なら固定 偶数なら任意
        var xorDiff = a.Aggregate((x, y) => x ^ y) ^ b.Aggregate((x, y) => x ^ y);
        List<Tuple<int, int>> res = new List<Tuple<int, int>>();
        if (n % 2 == 1)
        {
            for (int i = 0; i < n; i++)
                a[i] ^= xorDiff;
            ModInt hashA = 0;
            ModInt hashB = 0;
            for (int i = 0; i < n; i++)
            {
                hashA = hashA * ModInt.Base + a[i];
                hashB = hashB * ModInt.Base + b[i];
            }
            for (int i = n - 1; i >= 0; i--)
            {
                if (hashA.data == hashB.data)
                {
                    res.Add(new Tuple<int, int>(i, (int)xorDiff));
                }
                hashA = (hashA - (a[n - i - 1] * ModInt.powMemo[n - 1])) * ModInt.Base + a[n - i - 1];
            }
        }
        else
        {
            int[] shifts = new int[n];
            for (int i = 0; i < 30; i++)
            {
                ModInt hashA = 0;
                ModInt hashARev = 0;
                ModInt hashB = 0;
                for (int j = 0; j < n; j++)
                {
                    var abit = (a[j] >> i & 1);
                    var bbit = (b[j] >> i & 1);
                    hashA = hashA * ModInt.Base + abit;
                    hashARev = hashARev * ModInt.Base + (abit ^ 1);
                    hashB = hashB * ModInt.Base + bbit;
                }
                for (int j = n - 1; j >= 0; j--)
                {
                    if (0 <= shifts[j])
                    {
                        if (hashA.data == hashB.data) ;
                        else if (hashARev.data == hashB.data) shifts[j] |= 1 << i;
                        else shifts[j] = -1;
                    }

                    var bit = (a[n - j - 1] >> i & 1);
                    hashA = (hashA - (bit * ModInt.powMemo[n - 1])) * ModInt.Base + bit;
                    hashARev = (hashARev - ((bit ^ 1) * ModInt.powMemo[n - 1])) * ModInt.Base + (bit ^ 1);
                }
            }
            for (int i = 0; i < shifts.Length; i++)
            {
                if (shifts[i] < 0) continue;
                res.Add(new Tuple<int, int>(n - i - 1, shifts[i]));
            }
        }
        res.Reverse();
        Console.WriteLine(string.Join("\n", res.Select(x => $"{x.Item1} {x.Item2}")));
    }
}


class FoldableQueue<T>
{
    public int Count { get; private set; }
    public T Value
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get
        {
            return
                TailValueStack.Count == 0 ? FrontValue :
                FrontIsEmpty ? TailValueStack.Peek() :
                Merge(TailValueStack.Peek(), FrontValue);
        }
    }

    bool FrontIsEmpty = true;
    T FrontValue;
    Stack<T> Fronts = new Stack<T>();
    Stack<T> TailValueStack = new Stack<T>();

    Func<T, T, T> Merge;

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public FoldableQueue(Func<T, T, T> merge) { Merge = merge; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Pop()
    {
        Validate();
        if (TailValueStack.Count == 0) Move();
        TailValueStack.Pop();
        Count--;
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Push(T item)
    {
        Fronts.Push(item);
        Count++;
        FrontValue = FrontIsEmpty ? item : Merge(FrontValue, item);
        FrontIsEmpty = false;
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    private void Move()
    {
        TailValueStack.Push(Fronts.Pop());
        while (0 < Fronts.Count)
            TailValueStack.Push(Merge(Fronts.Pop(), TailValueStack.Peek()));
        FrontIsEmpty = true;
    }

    private void Validate() { if (Count == 0) throw new Exception(); }
}

class ModInt
{
    const ulong MASK30 = (1UL << 30) - 1;
    const ulong MASK31 = (1UL << 31) - 1;
    const ulong MOD = (1UL << 61) - 1;
    const ulong POSITIVIZER = MOD * ((1UL << 3) - 1);
    public static ModInt Base;
    public static ModInt[] powMemo = new ModInt[500000 + 1];
    static ModInt()
    {
        Base = (ulong)new Random().Next(1 << 30, int.MaxValue);
        //Base = 10;
        powMemo[0] = 1;
        for (int i = 1; i < powMemo.Length; i++)
            powMemo[i] = powMemo[i - 1] * Base;
    }
   public  ulong data;
    public ModInt(ulong n) { data = CalcMod(n); }
    public static ulong operator *(ModInt l, ModInt r) => Mul(l.data, r.data);
    public static ulong Mul(ulong l, ulong r)
    {
        var lu = l >> 31;
        var ld = l & MASK31;
        var ru = r >> 31;
        var rd = r & MASK31;
        var middleBit = ld * ru + lu * rd;
        return CalcMod(((lu * ru) << 1) + ld * rd + ((middleBit & MASK30) << 31) + (middleBit >> 30));
    }
    public static ulong operator +(ModInt l, ModInt r) => CalcMod(l.data + r.data);
    public static ulong operator -(ModInt l, ModInt r) => CalcMod(l.data + POSITIVIZER - r.data);
    public static implicit operator ulong(ModInt n) => n.data;
    public static implicit operator ModInt(ulong n) => new ModInt(n);

    public static ulong CalcMod(ulong val)
    {
        val = (val & MOD) + (val >> 61);
        if (val >= MOD) val -= MOD;
        return val;
    }

    public override string ToString() => data.ToString();
}