#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<int, int> P;


template<typename T>
class KMP{
    vector<int> a;
    T s;

public:
    KMP(T s_arg): s(s_arg){
        int n = s_arg.size();
        a = vector<int>(n+1, -1);   // a[j+1]が[0, j]のboarderの最大の長さ
        constructBorderArray();
    }

    void constructBorderArray(){
        int j = -1;
        for(int i = 0; i < s.size(); i++){
            while(j >= 0 && s[i] != s[j]){
                j = a[j];
            }

            j++;
//            if(s[i+1] == s[j]) a[i+1] = a[j];
//            else a[i+1] = j;
            a[i+1] = j;
        }
    }

    /**
     *
     * @param x: sとマッチングさせる配列
     * @return : マッチング位置
     */
    vector<int> search(T x, int pos=0){
        int j = 0;
        vector<int> res;
        for(int i = pos; i < x.size(); i++){
            while(j >= 0 && x[i] != s[j]){
                j = a[j];
            }
            j++;
            if(j == s.size()){
                res.push_back(i - j + 1);
                j = a[j];
            }
        }
        return res;
    }

    int periodicity(int pos){
        return pos - a[pos];
    }

};



int main(){
    int N;  cin >> N;
    vector<int> a(N), b(N);
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    for(int i = 0; i < N; i++){
        cin >> b[i];
    }

    vector<vector<int>> a2(31, vector<int>(N, 0));
    vector<vector<int>> b2(31, vector<int>(2 * N-1, 0));
    vector<vector<int>> b3(31, vector<int>(2 * N-1, 0));
    vector<vector<bool>> state(N, vector<bool>(31, false));

    for(int i = 0; i < N; i++){
        for(int j = 0; j < 31; j++){
            a2[j][i] = (a[i] >> j) % 2;
            b2[j][i] = (b[i] >> j) % 2;
            if(i + N < 2 * N - 1) b2[j][i+N] = (b[i] >> j) % 2;
            b3[j][i] = 1 - b2[j][i];
            if(i + N < 2 * N - 1) b3[j][i+N] = 1 - b2[j][i+N];
         }
    }


    for(int i = 0; i < 31; i++){
        KMP<vector<int>> kmp(a2[i]);
        vector<int> res = kmp.search(b2[i]);
        vector<int> res2 = kmp.search(b3[i]);
        for(auto e: res){
            state[e][i] = true;
        }
        for(auto e: res2){
            state[e][i] = true;
        }
    }

    vector<P> results;
    for(int i = 0; i < N; i++){
        bool ok = true;
        for(int j = 0; j < 31; j++){
            if(!state[i][j]){
                ok = false;
                break;
            }
        }
        if(ok){
            int x = a[0] ^ b[i];
            int k = (i == 0) ? 0 : N - i;
            results.emplace_back(P(k, x));
        }
    }

    sort(results.begin(), results.end());
    for(auto res: results){
        cout << res.fs << " " << res.sc << endl;
    }


    return 0;
}

Measured memory_bytes: 144384