#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
const int maxa = 1 << 30;
int n, A[maxn], B[maxn];
map<int, int> din, dout, vis, vis2;
map<int, vector<int>> out;
void add(int a, int b) {
  out[a].emplace_back(b);
  out[b].emplace_back(a);
  din[b]++, dout[a]++;
}
void dfs(int x) {
  vis[x] = 1;
  for (auto y : out[x])
    if (!vis[y]) dfs(y);
}
void halt() {
  cout << "-1\n";
  exit(0);
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  int xr = 0;
  for (int i = 0; i < n; ++i) cin >> A[i], xr ^= A[i];
  for (int i = 0; i < n; ++i) cin >> B[i];
  int diff = 0;
  for (int i = 0; i < n; ++i) {
    if (A[i] != B[i]) {
      add(A[i], B[i]);
      ++diff;
    }
  }
  if (diff == 0) return cout << "0\n", 0;
  int that = -1;
  for (int id = 0; id < maxn * 2; ++id) {
    int i = id < n ? A[id] : B[id - n];
    if (vis2[i]) continue;
    vis2[i] = 1;
    if (din[i] - dout[i] >= 2)
      halt();
    else if (din[i] - dout[i] == 1) {
      if (that != -1 || i != xr)
        halt();
      else
        that = i;
    }
  }
  int comp = 0;
  for (int id = 0; id < maxn; ++id) {
    int i = id < n ? A[id] : B[id - n];
    if (!vis[i] && dout[i]) ++comp, dfs(i);
  }
  cout << diff << ' ' << comp << endl;
  int ans = diff + comp - 1;
  cout << ans << '\n';
}
