//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
//const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

ll modpow(ll x, ll n, const ll mo) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) (res *= x) %= mo;
		(x *= x) %= mo;
		n >>= 1;
	}
	return res;
}

struct RollingHash {
	static const int base1 = 1007, base2 = 2009;
	static const int mod1 = 1000000007, mod2 = 1000000009;
	vector<long long> hash1, hash2;
	string S;
	int idx;
	long long pow1, pow2;

	// construct
	RollingHash(const string &S):S(S),idx(0) {
		int n = (int)S.size();
		hash1.assign(n + 1, 0);
		hash2.assign(n + 1, 0);
		for (int i = 0; i < n; ++i) {
			hash1[i + 1] = (hash1[i] * base1 + S[i]) % mod1;
			hash2[i + 1] = (hash2[i] * base2 + S[i]) % mod2;
		}
		pow1 = modpow(base1, SZ(S) - 1, mod1);
		pow2 = modpow(base2, SZ(S) - 1, mod2);
	}

	void Shift()
	{
		hash1[SZ(S)] = (hash1[SZ(S)] - ((S[idx] * pow1) % mod1) + mod1) % mod1;
		hash1[SZ(S)] *= base1;
		hash1[SZ(S)] %= mod1;
		hash1[SZ(S)] += S[idx];
		hash1[SZ(S)] %= mod1;

		hash2[SZ(S)] = (hash2[SZ(S)] - ((S[idx] * pow2) % mod2) + mod2) % mod2;
		hash2[SZ(S)] *= base2;
		hash2[SZ(S)] %= mod2;
		hash2[SZ(S)] += S[idx];
		hash2[SZ(S)] %= mod2;
		idx++;
	}
};

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	vector<int> A(N), B(N);
	rep(i, 0, N)
	{
		cin >> A[i];
		//A[i] = 1;
	}
	rep(i, 0, N)
	{
		cin >> B[i];
		//B[i] = 1;
	}

	vector<string> S(32), RS(32), AS(32);
	rrep(i, 0, 32)
	{
		S[i].resize(N);
		RS[i].resize(N);
		AS[i].resize(N);
		rep(j, 0, N)
		{
			int ad = ((A[j] >> i) & 1);
			int bd = ((B[j] >> i) & 1);

			S[i][j]=((char)('0' + bd));
			RS[i][j]=((char)('0' + (bd ^ 1)));
			AS[i][j]=((char)('0' + ad));
		}
	}

	vector<RollingHash> RHS, RHRS, RHAS;

	rep(i, 0, 32)
	{
		RHS.emplace_back(RollingHash(S[i]));
		RHRS.emplace_back(RollingHash(RS[i]));
		RHAS.emplace_back(RollingHash(AS[i]));
	}

	//cout << "a" << endl;

	rep(k, 0, N)
	{
		int x = 0;
		bool ok = true;
		rep(d, 0, 32)
		{
			if (RHAS[d].hash1.back() == RHS[d].hash1.back() && RHAS[d].hash2.back() == RHS[d].hash2.back())
			{

			}
			else if (RHAS[d].hash1.back() == RHRS[d].hash1.back() && RHAS[d].hash2.back() == RHRS[d].hash2.back())
			{
				x |= (1LL << d);
			}
			else
			{
				ok = false;
			}
			RHAS[d].Shift();
		}
		if (ok)
		{
			cout << k << " " << x << endl;
		}
	}

	//cout << "a" << endl;

	return 0;
}

Measured memory_bytes: 346368