#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
#ifdef DEBUG
template<typename T>
class Vec : public vector<T>{
public:
    Vec(){}
    Vec(int n):vector<T>(n){}
    Vec(int n, T a):vector<T>(n,a){}
    T& operator[](long long n){
        if(n < 0 or n >= this->size())throw out_of_range("Vec");
        return this->at(n);
    }
    const T& operator[](long long n)const{
        if(n < 0 or n >= this->size())throw out_of_range("Vec");
        return this->at(n);
    }
};
#define vector Vec
template<typename T>
ostream &operator<<(ostream &os, set<T> st) {
    for(auto x : st) cerr << x << ' ';
    return os;
}
template<typename T, typename S>
ostream &operator<<(ostream &os, map<T, S> mp) {
    for(auto x : mp) cerr << x << ' ';
    return os;
}
#endif
class KMP
{
public:
    string pattern;
    int plen;
    vector<int> table;
    KMP(const string& s) : pattern(s), plen((int)pattern.size()), table(plen+1){
        table[0] = -1;
        int j = -1;
        for(int i = 0; i < plen; i++){
            while(j >= 0 && pattern[i] != pattern[j]) j = table[j];
            if(pattern[i+1] == pattern[++j]) table[i+1] = table[j];
            else table[i+1] = j;
        }
    }
    void search(const string& text, vector<int>& res){
        int head = 0, j = 0, tlen = (int)text.size();
        while(head + j < tlen){
            if(pattern[j] == text[head + j]){
                if(++j != plen) continue;
                res.push_back(head);
            }
            head += j - table[j], j = max(table[j], 0);
        }
    }
};
int n;
int ans[200005];
int cnt[200005];
void solve(int bit,bool f, string c, string d){
    for(int i = 0; i < n; i++)c.push_back(c[i]);
    show(c);
    show(d);
    KMP kmp(d);
    vector<int> res;
    kmp.search(c, res);
    show(bit, f, res);
    for(auto x : res){
        if(f)ans[x]+=1<<bit;
        cnt[x]++;
    }
}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> n;
    vector<int>a(n),b(n);
    rep(i,n)cin >> a[i];
    rep(i,n)cin >> b[i];
    for(int i = 0; i < 30; i++){
        string c, d;
        if(i==0)show(a);
        rep(j, n){
            c += 'a' + ((a[j] >> i) % 2);
            d += 'a' + ((b[j] >> i) % 2);
        }
        show(i, c, d);
        solve(i, false, c, d);
        rep(j,n){
            if(d[j] == 'a')d[j] = 'b';
            else d[j] = 'a';
        }
        solve(i, true, c, d);
    }
    for(int i = 0; i < n; i++){
        if(cnt[i] == 30){
            cout << i << " " << ans[i] << "\n";
        }
    }
}


Measured memory_bytes: 8080