#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <set>
#include <map>
#include <numeric>
#include <stack>

constexpr intmax_t b1 = 943681729;
constexpr intmax_t b2 = 943681733;
constexpr intmax_t b3 = 943681727;
constexpr intmax_t p1 = 1000000007;
constexpr intmax_t p2 = 998244353;
constexpr intmax_t p3 = 1000000009;

std::vector<int> f(std::vector<intmax_t> const& a, std::vector<intmax_t> const& b) {
  size_t n = a.size();
  intmax_t x1 = 0;
  intmax_t x2 = 0;
  intmax_t x3 = 0;
  intmax_t y1 = 0;
  intmax_t y2 = 0;
  intmax_t y3 = 0;
  intmax_t bp1 = 1;
  intmax_t bp2 = 1;
  intmax_t bp3 = 1;
  intmax_t t1 = 0;
  intmax_t t2 = 0;
  intmax_t t3 = 0;
  for (size_t i = 0; i < n; ++i) {
    (x1 = x1 * b1 + a[i]) %= p1;
    (x2 = x2 * b2 + a[i]) %= p2;
    (x3 = x3 * b3 + a[i]) %= p3;
    (y1 = y1 * b1 + (a[i] ^ 1)) %= p1;
    (y2 = y2 * b2 + (a[i] ^ 1)) %= p2;
    (y3 = y3 * b3 + (a[i] ^ 1)) %= p3;
    (t1 = t1 * b1 + b[i]) %= p1;
    (t2 = t2 * b2 + b[i]) %= p2;
    (t3 = t3 * b3 + b[i]) %= p3;
    if (i+1 < n) {
      (bp1 *= b1) %= p1;
      (bp2 *= b2) %= p2;
      (bp3 *= b3) %= p3;
    }
  }
  std::vector<int> res(n, -1);
  if (x1 == t1 && x2 == t2 && x3 == t3) {
    res[0] = 0;
  } else if (y1 == t1 && y2 == t2 && y3 == t3) {
    res[0] = 1;
  }
  for (size_t i = 0; i+1 < n; ++i) {
    size_t k = i+1;
    if (((x1 = (x1 - bp1 * a[i]) * b1 + a[i]) %= p1) < 0) x1 += p1;
    if (((x2 = (x2 - bp2 * a[i]) * b2 + a[i]) %= p2) < 0) x2 += p2;
    if (((x3 = (x3 - bp3 * a[i]) * b3 + a[i]) %= p3) < 0) x3 += p3;
    if (((y1 = (y1 - bp1 * (a[i] ^ 1)) * b1 + (a[i] ^ 1)) %= p1) < 0) y1 += p1;
    if (((y2 = (y2 - bp2 * (a[i] ^ 1)) * b2 + (a[i] ^ 1)) %= p2) < 0) y2 += p2;
    if (((y3 = (y3 - bp3 * (a[i] ^ 1)) * b3 + (a[i] ^ 1)) %= p3) < 0) y3 += p3;

    if (x1 == t1 && x2 == t2 && x3 == t3) {
      res[k] = 0;
    } else if (y1 == t1 && y2 == t2 && y3 == t3) {
      res[k] = 1;
    }
  }
  return res;
}

int main() {
  size_t n;
  scanf("%zu", &n);

  std::vector<intmax_t> a(n), b(n);
  for (auto& ai: a) scanf("%jd", &ai);
  for (auto& bi: b) scanf("%jd", &bi);

  size_t m = 30;
  std::vector<std::vector<int>> cand(m);
  for (size_t j = 0; j < m; ++j) {  // O(m)
    std::vector<intmax_t> aj(n), bj(n);
    for (size_t i = 0; i < n; ++i) {  // O(n)
      aj[i] = a[i] >> j & 1;
      bj[i] = b[i] >> j & 1;
    }
    cand[j] = f(aj, bj);  // O(n)
  }

  std::vector<std::pair<size_t, intmax_t>> res;
  res.reserve(n);
  // for (auto const& x: cand[0]) {  // O(n)
  //   size_t k = x.first;
  //   intmax_t y = x.second;
  //   bool valid = true;
  //   for (size_t j = 1; j < m; ++j) {  // O(m)
  //     auto it = cand[j].find(k);  // O(log n)
  //     if (it == cand[j].end()) {
  //       valid = false;
  //       break;
  //     }
  //     if (it->second) y |= 1 << j;
  //   }
  //   if (!valid) continue;
  //   res.emplace_back(k, y);
  // }

  for (size_t i = 0; i < n; ++i) {
    bool valid = true;
    intmax_t y = 0;
    for (size_t j = 0; j < m; ++j) {
      if (cand[j][i] < 0) {
        valid = false;
        break;
      }
      if (cand[j][i]) y |= 1 << j;
    }
    if (valid) res.emplace_back(i, y);
  }

  for (auto const& p: res)
    printf("%zu %jd\n", p.first, p.second);
}


Measured memory_bytes: 33096