#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int partition(int *A, int p, int r){
    int x=A[r];
    int i=p-1;
    for(int j=p;j<r;j++){
        if(A[j]<=x){
            i++;
            int tmp=A[i];
            A[i]=A[j];
            A[j]=tmp;
        }
    }
    int tmp=A[i+1];
    A[i+1]=A[r];
    A[r]=tmp;

    return i+1;
}

int main(){
    int n, A[100000];
    cin >> n;    
    for(int i=0;i<n;i++) cin >> A[i];

    int q = partition(A, 0, n-1);
    for(int i=0;i<q;i++){
        if(i>0) cout << ' ';
        cout << A[i];
    }
    cout << " [" << A[q] << ']';
    for(int i=q+1;i<n;i++) cout << ' ' << A[i];
    cout << endl;

    return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

vector<int> Zalgorithm(vector<int> S) {
    vector<int> A(S.size());
    A[0] = S.size();
    int i = 1, j = 0;
    while (i < S.size()) {
        while (i+j < S.size() && S[j] == S[i+j]) ++j;
        A[i] = j;
        if (j == 0) { ++i; continue;}
        int k = 1;
        while (i+k < S.size() && k+A[k] < j) A[i+k] = A[k], ++k;
        i += k; j -= k;
    }
    return A;
}

int main() {
    int N;
    cin >> N;
    vector<int> a(N), b(N), S(3 * N);
    rep(i, N) cin >> a[i];
    rep(i, N) cin >> b[i];
    rep(i, N) {
        S[i] = b[i] ^ b[(i + 1) % N];
        S[N + i] = a[i] ^ a[(i + 1) % N];
        S[N + N + i] = a[i] ^ a[(i + 1) % N];
    }
    auto A = Zalgorithm(S);
    rep(i, N) {
        if (A[N + i] >= N) {
            cout << i << " " << (a[i] ^ b[0]) << "\n";
        }
    }
}