#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T iabs(const T& x) { return max(x, -x); }
// #define abs gabs

template<unsigned long long M, unsigned long long B>
struct BasicRollingHash {
  using Uint = unsigned long long;
  using U128 = unsigned long long;
  vector<Uint> hashes, pows;

  template<class T>
  BasicRollingHash(const T& s) { init(s); }

  template<class T>
  void init(const T& s) {
    size_t n = s.size();
    hashes.assign(n + 1, 0);
    pows.assign(n + 1, 0);
    pows[0] = 1;
    for (size_t i = 1; i <= n; ++i) {
      hashes[i] = U128(hashes[i - 1] + s[i - 1]) * B % M;
      pows[i] = U128(pows[i - 1]) * B % M;
    }
  }
  
  template<class T>
  static Uint hash_once(const T& s) {
    Uint h = 0;
    for (size_t i = 1; i <= s.size(); ++i) {
      h = U128(h + s[i - 1]) * B % M;
    }
    return h;
  }

  // [l, r)
  Uint hash(size_t l, size_t r) const {
    r = min(r, size());
    U128 h = M - (M - U128(hashes[r]) + U128(pows[r - l]) * hashes[l]) % M;
    return h;
  }

  size_t size() const {
    return hashes.size() - 1;
  }

  template<class T>
  vector<bool> search_all(const T& s, size_t l = 0, size_t r = 1 << 30) 
  const {
    auto h = hash_once(s);
    int n = s.size();
    vector<bool> res(size() - n);
    for (int i = l; i <= int(min(r, size() - n)); ++i) {
      if (hash(i, i + n) == h) res[i] = true;
    }
    return res;
  }
};
using RollingHash = BasicRollingHash<(1ull << 31) - 1, 263>;

int main() {
    i64 n;
    cin >> n;
    vector<i64> 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<int> res[30];
    string s(2 * n, 0), t(n, 0);
    for (int d = 0; d < 30; ++d) {
        for (int i = 0; i < n; ++i) {
            s[i] = s[n + i] = 2 + ((a[i] >> d) & 1);
            t[i] = 2 + ((b[i] >> d) & 1);
        }
        res[d].resize(n, -1);
        RollingHash rh(s);
        for (int k = 0; k <= 1; ++k) {
            auto m = rh.search_all(t);
            for (int i = 0; i < n; ++i) {
                if (m[i]) {
                    res[d][i] = k;
                }
            }
            for (int i = 0; k == 0 && i < n; ++i) {
                t[i] ^= 1;
            }
        }
    }

    for (int i = 0; i < n; ++i) {
        bool ok = true;
        i64 x = 0;
        for (int d = 0; d < 30; ++d) {
            x |= res[d][i] << d;
            if (res[d][i] == -1) {
                ok = false;
                break;
            }
        }
        if (ok) {
            cout << i << ' ' << x << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 33728