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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

struct rolling_hash {
    using ull = unsigned long long;
    static constexpr ull MASK30 = (1ULL << 30) - 1;
    static constexpr ull MASK31 = (1ULL << 31) - 1;
    static constexpr ull MOD = (1ULL << 61) - 1;
    static constexpr ull POSITIVIZER = MOD << 2;
    static std::vector<std::pair<ull, ull>> pow_base;
    int n;
    std::vector<std::pair<ull, ull>> hash;
    static ull rng() {
        std::random_device rd;
        return std::uniform_int_distribution<ull>(MOD >> 1, MOD - 1)(rd);
    }
    static ull mul(ull a, ull b) {
        ull au = a >> 31;
        ull ad = a & MASK31;
        ull bu = b >> 31;
        ull bd = b & MASK31;
        ull mid = ad * bu + au * bd;
        return (au * bu << 1) + (mid >> 30) + ((mid & MASK30) << 31) + ad * bd;
    }
    static ull calc_mod(ull val) {
        val = (val & MOD) + (val >> 61);
        if (val >= MOD) { val -= MOD; }
        return val;
    }
    static std::pair<ull, ull> connect(const std::pair<ull, ull> &lhs, const std::pair<ull, ull> &rhs, int rn) {
        return {calc_mod(mul(lhs.first, pow_base[rn].first) + rhs.first),
                calc_mod(mul(lhs.second, pow_base[rn].second) + rhs.second)};
    }
    template<typename I> rolling_hash(I begin, I end): n(end - begin) {
        hash.push_back({0, 0});
        for (auto itr = begin; itr != end; itr++) {
            hash.push_back({calc_mod((mul(hash.back().first, pow_base[1].first) + *itr)),
                            calc_mod((mul(hash.back().second, pow_base[1].second) + *itr))});
        }
        while (pow_base.size() <= n) {
            pow_base.push_back({calc_mod(mul(pow_base.back().first, pow_base[1].first)),
                                calc_mod(mul(pow_base.back().second, pow_base[1].second))});
        }
    }
    std::pair<ull, ull> get_hash(int l, int r) const {
        return {calc_mod(POSITIVIZER - mul(hash[l].first, pow_base[r - l].first) + hash[r].first),
                calc_mod(POSITIVIZER - mul(hash[l].second, pow_base[r - l].second) + hash[r].second)};
    }
};
std::vector<std::pair<rolling_hash::ull, rolling_hash::ull>> rolling_hash::pow_base{{1, 1}, {rng(), rng()}};

int N;
int a[220000], b[220000];
bool ng[220000];
int ans[220000];
signed main() {
    cin >> N;
    rep(i, N) { cin >> a[i]; }
    rep(i, N) { cin >> b[i]; }
    rep(i, 30) {
        vector<bool> omote(N), ura(N), bit_b(N);
        rep(j, N) {
            omote[j] = (a[j] >> i) & 1LL;
            ura[j] = !omote[j];
            bit_b[j] = (b[j] >> i) & 1LL;
        }
        rolling_hash rh_omote(all(omote)), rh_ura(all(ura)), rh_b(all(bit_b));
        auto hb = rh_b.get_hash(0, N);
        rep(k, N) {
            auto ho = rh_omote.connect(rh_omote.get_hash(k, N), rh_omote.get_hash(0, k), k);
            auto hu = rh_ura.connect(rh_ura.get_hash(k, N), rh_ura.get_hash(0, k), k);
            if (ho == hb) {
            } else if (hu == hb) {
                ans[k] += bit(i);
            } else {
                ng[k] = true;
            }
        }
    }
    rep(i, N) {
        if (!ng[i]) { cout << i << " " << ans[i] << endl; }
    }
}

Measured memory_bytes: 23228