/**
 *    author:  zjsdut
 *    created: 2020/01/18 16:00:40
 **/
#include <bits/stdc++.h>

using namespace std;

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

template <typename A, typename B> bool chkmin(A &a, const B &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

template <typename A, typename B> bool chkmax(A &a, const B &b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}

template <typename T> istream &operator>>(istream &stream, vector<T> &vec) {
  for (auto &x : vec)
    stream >> x;
  return stream;
}

void scan() {}

template <class T, class... Args> void scan(T &a, Args &... rest) {
  cin >> a;
  scan(rest...);
}

using ll = long long;
using vl = vector<ll>;
using vb = vector<bool>;
using vi = vector<int>;
using pii = pair<int, int>;
template <typename T> using vv = vector<vector<T>>;
#define rng(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define up(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define down(i, b, a) for (int i = int(b); i >= int(a); i--)
#define rep(n)                                                                 \
  for (int _iter_##n = 0, _num_##n = (int)n; _iter_##n < _num_##n; ++_iter_##n)
#define FOR(x, cont) for (const auto &x : cont)
#define For(x, cont) for (auto &x : cont)
#define all(x) begin(x), end(x)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ep emplace
#define SZ(x) (int)(x).size()
#define UNIQ(vec) (vec).erase(unique(all(vec)), end(vec))
#define LB(cont, x) int(lower_bound(all(cont), x) - begin(cont))
#define UB(cont, x) int(upper_bound(all(cont), x) - begin(cont))

template <typename T>
ostream &operator<<(ostream &stream, const vector<T> &vec) {
  if (!vec.empty()) {
    stream << vec[0];
    for (size_t i = 1; i != vec.size(); ++i)
      stream << ' ' << vec[i];
  }
  return stream;
}

template <typename T> void print(const vector<T> &t) { cout << t << '\n'; }

template <typename T> void print(const vector<vector<T>> &t) {
  for (const auto &row : t) {
    print(row);
  }
}

template <typename T> void print(const T &t) { cout << t << ' '; }

template <typename T, typename... Args>
void print(const T &t, const Args &... rest) {
  print(t);
  print(rest...);
}

template <typename T> void println(const T &t) { cout << t << '\n'; }

template <typename T, typename... Args>
void println(const T &t, const Args &... rest) {
  print(t);
  println(rest...);
}

template <typename T>
int get_next(const T *P, const vector<int> &fail, const T ch, int i) {
  while (i != -1 && P[i] != ch)
    i = fail[i];
  return i + 1;
}

template <typename T>
vector<int> get_fail(const T *pattern, const int len_pattern) {
  assert(len_pattern > 0);
  vector<int> fail(len_pattern + 1);
  fail[0] = -1;
  for (int i = 1; i <= len_pattern; i++) {
    fail[i] = get_next(pattern, fail, pattern[i - 1], fail[i - 1]);
  }
  return fail;
}

template <typename T>
vector<int> KMP_match(const T *pattern, const int len_pattern, const T *text,
                      const int len_text, const vector<int> &fail) {
  vector<int> match_positions;
  for (int i = 0, j = 0; i < len_text; ++i) {
    j = get_next(pattern, fail, text[i], j);
    if (j == len_pattern) {
      j = fail[j];
      match_positions.push_back(i + 1 - len_pattern);
    }
  }
  return match_positions;
}

template <typename T> int get_bit(T a, int i) { return a >> i & 1; }

int main() {
#if defined LOCAL
  ifstream in("in.txt");
  cin.rdbuf(in.rdbuf());
#endif
  // If n is odd, x is determined. we can expand a and try to match a'.
  // The hard part is when n is even.
  // Note that we can consider each bit independently.
  // Then the problem becomes: given a 01 sequence A of length 2*n-1, try to
  // match another 01 sequnce B of length N in A. Then flip all bits of A and do
  // the match again. Note that if K is a shift for the first search, it must
  // not be a shift for the second search where the text string is flipped, and
  // vice versa.
  int n;
  scan(n);
  vi a(n), b(n);
  scan(a, b);
  rng(i, 0, n - 1) { a.pb(a[i]); }
  vv<int> match(30, vi(n, -1));
  rng(i, 0, 30) {
    vi pattern(n);
    rng(j, 0, n) { pattern[j] = get_bit(b[j], i); }
    auto fail = get_fail(pattern.data(), n);
    rng(j, 0, 2) {
      vi t(2 * n - 1);
      rng(k, 0, 2 * n - 1) { t[k] = get_bit(a[k], i) ^ j; }
      auto shifts = KMP_match(pattern.data(), n, t.data(), 2 * n - 1, fail);
      FOR(x, shifts) { match[i][x] = j; }
    }
  }
  rng(k, 0, n) {
    bool flag = true;
    rng(i, 0, 30) {
      if (match[i][k] == -1) {
        flag = false;
        break;
      }
    }
    if (flag) {
      int x = 0;
      rng(i, 0, 30) {
        if (match[i][k]) {
          x += 1 << i;
        }
      }
      println(k, x);
    }
  }
  return 0;
}

Measured memory_bytes: 31044