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: Accepted)

using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
using static Rh;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var a=sc.Ia;
		var b=sc.Ia;
		var c=new int[n];
		var d=new int[n];
		for(int i = 0;i<n;i++) {
			c[i]=a[i]^a[(i+1)%n];
			d[i]=b[i]^b[(i+1)%n];
		}
		Rh rh=new Rh(n);
		Hs ha1=c,ha2=d;
		StringBuilder sb=new StringBuilder();
		for(int i = 0;i<n;i++) {
			if(ha1==ha2){
				sb.Append(i).Append(" ").Append(a[i]^b[0]).Append("\n");
			}
			ha1-=c[i];
			ha1+=c[i];
		}
		Console.Write(sb);
	}
}
public class Rh{
	public static readonly int mod1=1073741783,mod2=1073741789;
	public static readonly int b1=1007,b2=1009+DateTime.Now.Millisecond;
	private static long[] r1,r2;
	private static int n;
	public Rh(){n=0;}
	public Rh(int n){
		Rh.n=n;
		r1=new long[n+1];
		r2=new long[n+1];
		r1[0]=r2[0]=1;
		for(int i = 1;i<=n;i++) {
			r1[i]=(r1[i-1]*b1)%mod1;
			r2[i]=(r2[i-1]*b2)%mod2;
		}
	}
	public class Hsa{
		private Hs[] hs;
		public int n;
		public Hsa(int[] a){
			n=a.Length;
			if(n>Rh.n){
				Rh.n=n;
				r1=new long[n+1];
				r2=new long[n+1];
				r1[0]=r2[0]=1;
				hs=new Hs[n+1];
				hs[0]=new Hs(0);
				for(int i = 1;i<=n;i++) {
					r1[i]=(r1[i-1]*b1)%mod1;
					r2[i]=(r2[i-1]*b2)%mod2;
					hs[i]=hs[i-1]+a[i-1];
				}
			}
			else{
				hs=new Hs[n+1];
				hs[0]=new Hs(0);
				for(int i = 1;i<=n;i++) {hs[i]=hs[i-1]+a[i-1];}
			}
		}
		public Hsa(string a){
			n=a.Length;
			if(n>Rh.n){
				Rh.n=n;
				r1=new long[n+1];
				r2=new long[n+1];
				r1[0]=r2[0]=1;
				hs=new Hs[n+1];
				hs[0]=new Hs(0);
				for(int i = 1;i<=n;i++) {
					r1[i]=(r1[i-1]*b1)%mod1;
					r2[i]=(r2[i-1]*b2)%mod2;
					hs[i]=hs[i-1]+a[i-1];
				}
			}
			else{
				hs=new Hs[n+1];
				hs[0]=new Hs(0);
				for(int i = 1;i<=n;i++) {hs[i]=hs[i-1]+a[i-1];}
			}
		}
		public static implicit operator Hsa(int[] a){return new Hsa(a);}
		public static implicit operator Hsa(string a){return new Hsa(a);}
		public Hs Get(int a,int b){return hs[b+1]-hs[a];}
		public int Bs(int a,int b){return Bs(a,b,n-Max(a,b));}
		public int Bs(int a,int b,int ub){
			int lb=-1,mid=0;
			while(ub-lb>1){
				mid=(ub+lb)/2;
				if(Get(a,a+mid)!=Get(b,b+mid)){ub=mid;}
				else{lb=mid;}
			}
			return ub;
		}
		public int Bsp(Hsa a){return Bsp(0,a);}
		public int Bsp(int k,Hsa a){
			int lb=-1,mid=0,ub=Min(n-k,a.n);
			while(ub-lb>1){
				mid=(ub+lb)/2;
				if(Get(k,mid+k)!=a.Get(0,mid)){ub=mid;}
				else{lb=mid;}
			}
			return ub;
		}
		public int Bss(Hsa a){return Bss(n-1,a);}
		public int Bss(int k,Hsa a){
			int lb=0,mid=0,ub=Min(k+1,a.n)+1;
			while(ub-lb>1){
				mid=(ub+lb)/2;
				if(Get(k+1-mid,k)!=a.Get(a.n-mid,a.n-1)){ub=mid;}
				else{lb=mid;}
			}
			return lb;
		}
	}
	public struct Hs{
		public long h1,h2;
		public int d;
		public Hs(int n){h1=h2=d=0;}
		public static implicit operator bool(Hs h){return h.d>0;}
		public static implicit operator Hs(string s){
			Hs h=new Hs(0);
			for(int i=0;i<s.Length;i++){h+=s[i];}
			return h;
		}
		public static implicit operator Hs(int[] s){
			Hs h=new Hs(0);
			for(int i=0;i<s.Length;i++){h+=s[i];}
			return h;
		}
		public static Hs operator+(Hs a,int c){
			a.h1=(a.h1*b1+c)%mod1;
			a.h2=(a.h2*b2+c)%mod2;
			a.d++;
			return a;
		}
		public static Hs operator+(Hs a,Hs p){
			a.h1=(a.h1*r1[p.d]+p.h1)%mod1;
			a.h2=(a.h2*r2[p.d]+p.h2)%mod2;
			a.d+=p.d;
			return a;
		}
		public static Hs operator-(Hs a,int c){
			a.d--;
			a.h1=(a.h1+mod1-(r1[a.d]*c%mod1))%mod1;
			a.h2=(a.h2+mod2-(r2[a.d]*c%mod2))%mod2;
			return a;
		}
		public static Hs operator-(Hs a,Hs p){
			a.d-=p.d;
			a.h1=(a.h1+mod1-(r1[a.d]*p.h1%mod1))%mod1;
			a.h2=(a.h2+mod2-(r2[a.d]*p.h2%mod2))%mod2;
			return a;
		}
		public static bool operator==(Hs a,Hs b){return a.h1==b.h1&&a.h2==b.h2&&a.d==b.d;}
		public static bool operator!=(Hs a,Hs b){return a.h1!=b.h1||a.h2!=b.h2||a.d!=b.d;}
		public override bool Equals(object obj){return false;}
		public override int GetHashCode(){return 0;}
	}
	public class Hss{
		public int n;
		public Tuple<Hs,int>[] da;
		public Hss(string[] s){
			n=s.Length;
			da=new Tuple<Hs,int>[n];
			for(int i = 0;i<n;i++) {da[i]=Tuple.Create((Hs)s[i],i);}
			Array.Sort(da,(u,v)=>u.Item1.h1.CompareTo(v.Item1.h1));
		}
		public int Eq(Hs h){
			int lb=-1,mid=0,ub=n-1;
			while(ub-lb>1){
				mid=(ub+lb)/2;
				if(da[mid].Item1.h1>=h.h1){ub=mid;}
				else{lb=mid;}
			}
			for(int i = ub;i<n&&da[i].Item1.h1==h.h1;i++) {if(da[i].Item1==h){return da[i].Item2;}}
			return -1;
		}
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}