#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

template <typename T>
struct RollingHash
{
	int size;
	int n;
	ll factor = 1;
	ll b = 0;
	ll mod = 0;
	ll hash = 0;
	vector<T> list;
	int num = 0;
	int head = 0;

	void init(int _n, ll _b = (ll)1e8 + 7, ll _mod = (ll)1e9 + 7)
	{
		n = _n;
		b = _b;
		list.reserve(n);
		mod = _mod;
		auto temp = 1ll;
		for (auto i = 0; i < n; ++i)
		{
			factor = temp;
			temp = temp * b % mod;
		}
	}

	void add(ll val)
	{
		if ((int)list.size() >= n)
		{
			hash = (((hash - list[head] * factor) % mod) + mod) % mod;
			list[head] = val;
			head = (head + 1) % n;
		}
		else
		{
			list.push_back(val);
		}
		hash = hash * b % mod;
		hash = (hash + val) % mod;
	}

	ll getHash() { return hash; }
};

ll calcHash(vector<ll>& list, ll factor, ll mod)
{
	auto hash = 0ll;
	for (auto i = 0; i < (int)list.size(); ++i)
	{
		hash = hash * factor % mod;
		hash = (hash + list[i]) % mod;
	}

	return hash;
}

int main()
{
	int N;
	cin >> N;
	vector<ll> a(N);
	vector<ll> b(N);
	for (auto i = 0; i < N; ++i)
	{
		ll temp;
		cin >> temp;
		a[i] = temp;
		a.push_back(temp);
	}
	for (auto& temp : b)
	{
		cin >> temp;
	}

	vector<ll> x;
	for (auto i = 0; i < N; ++i)
	{
		x.push_back(b[0] ^ a[i]);
	}

	auto bitNum = 31;
	auto mod = (ll)1e9 + 7;
	vector<ll> rollingHashFactor = { (ll)1e8 + 7 };
	vector<vector<vector<RollingHash<ll>>>> hashA
		(bitNum, vector<vector<RollingHash<ll>>>(2, vector<RollingHash<ll>>((int)rollingHashFactor.size())));
	vector<vector<RollingHash<ll>>> hashB
		(bitNum, vector<RollingHash<ll>>((int)rollingHashFactor.size()));

	for (auto i = 0; i < bitNum; ++i)
	{
		for (auto k = 0; k < N; ++k)
		{
			auto val = (b[k] >> i) & 1;
			for (auto l = 0; l < (int)rollingHashFactor.size(); ++l)
			{
				if (k == 0)
				{
					hashB[i][l].init(N, rollingHashFactor[l], mod);
				}
				hashB[i][l].add(val);
			}
		}
	}

	vector<ll> factor;
	for (auto i = 0; i < (int)rollingHashFactor.size(); ++i)
	{
		auto temp = 1ll;
		for (auto j = 0; j < bitNum; ++j)
		{
			temp = temp * rollingHashFactor[i] % mod;
		}
		factor.push_back(temp);
	}

	vector<ll> correct;
	for (auto i = 0; i < (int)rollingHashFactor.size(); ++i)
	{
		vector<ll> list;
		for (auto j = 0; j < bitNum; ++j)
		{
			list.push_back(hashB[j][i].getHash());
		}
		correct.push_back(calcHash(list, factor[i], mod));
	}

	for (auto i = 0; i < bitNum; ++i)
	{
		for (auto j = 0; j < 2; ++j)
		{
			for (auto k = 0; k < N; ++k)
			{
				auto val = ((a[k] >> i) ^ j) & 1;
				for (auto l = 0; l < (int)rollingHashFactor.size(); ++l)
				{
					if (k == 0)
					{
						hashA[i][j][l].init(N, rollingHashFactor[l]);
					}
					hashA[i][j][l].add(val);
				}
			}
		}
	}

	vector<pair<int, ll>> ans;
	for (auto k = 0; k < N; ++k)
	{
		vector<vector<ll>> list((int)rollingHashFactor.size());
		for (auto i = 0; i < bitNum; ++i)
		{
			int j = (x[k] >> i) & 1;
			for (auto l = 0; l < (int)rollingHashFactor.size(); ++l)
			{
				list[l].push_back(hashA[i][j][l].getHash());
			}
		}

		auto match = true;
		for (auto i = 0; i < (int)rollingHashFactor.size(); ++i)
		{
			auto hash = calcHash(list[i], factor[i], mod);
			if (hash != correct[i])
			{
				match = false;
			}
		}

		if (match != false)
		{
			ans.push_back({ k, x[k] });
		}

		for (auto i = 0; i < bitNum; ++i)
		{
			for (auto j = 0; j < 2; ++j)
			{
				auto val = ((a[k + N] >> i) ^ j) & 1;
				for (auto l = 0; l < (int)rollingHashFactor.size(); ++l)
				{
					hashA[i][j][l].add(val);
				}
			}
		}
	}

	for (auto& pair : ans)
	{
		cout << pair.first << " " << pair.second << endl;
	}

	return 0;
}
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;


int main(void)
{
	int h, w;
	int d_max=80*80;
	while(scanf("%d%d", &h, &w)==2)
	{
		vvi a(h), b(h), c(h);
		for(int y=0;y<h;y++)
		{
			a[y].resize(w);
			for(int x=0;x<w;x++) scanf("%d", &a[y][x]);
		}
		for(int y=0;y<h;y++)
		{
			b[y].resize(w);
			for(int x=0;x<w;x++) scanf("%d", &b[y][x]);
		}

		for(int y=0;y<h;y++)
		{
			c[y].resize(w);
			for(int x=0;x<w;x++) c[y][x]=abs(a[y][x]-b[y][x]);
		}

		vector<vector<vector<bool> > > dp(h);
		for(int y=0;y<h;y++)
		{
			dp[y].resize(w);
			for(int x=0;x<w;x++)
			{
				dp[y][x].assign(d_max+1, false);
			}
		}

		dp[0][0][c[0][0]]=true;
		for(int y=0;y<h;y++)
		{
			for(int x=0;x<w;x++)
			{
				for(int i=0;i<=d_max;i++)
				{
					if(dp[y][x][i]==false) continue;

					if(y+1<h)
					{
						int nbp=i+c[y+1][x];
						int nbn=abs(i-c[y+1][x]);
						dp[y+1][x][nbn]=true;
						if(nbp<=d_max) dp[y+1][x][nbp]=true;
					}
					if(x+1<w)
					{
						int nbp=i+c[y][x+1];
						int nbn=abs(i-c[y][x+1]);
						dp[y][x+1][nbn]=true;
						if(nbp<=d_max) dp[y][x+1][nbp]=true;
					}
				}
			}
		}
		int ans=0;
		for(ans=0;ans<=d_max && dp[h-1][w-1][ans]==false;ans++)
		{
			
		}
if(0)
{
		for(int y=0;y<h;y++)
		{
			for(int x=0;x<w;x++)
			{
				printf("%d ", c[y][x]);
			}
			printf("\n");
		}
		for(int y=0;y<h;y++)
		{
			for(int x=0;x<w;x++)
			{
				printf(" [");
				for(int i=0;i<=d_max;i++) if(dp[y][x][i]) printf(" %d", i);
				printf(" ]");
			}
			printf("\n");
		}
}
		printf("%d\n", ans);
	}
	return 0;
}
