#include <bits/stdc++.h>
using namespace std;
int GLL(long long& x) { return scanf("%lld", &x); }
int GI(int& x) { return scanf("%d", &x); }
int n;
vector<int> a, as;
vector<int> b, bs;
map<int, set<int>> misplaced;
void swapIdx(int i) {
  if (misplaced[b[i]].count(i) != 0) {
    misplaced[b[i]].erase(i);
    if (misplaced[b[i]].size() == 0) misplaced.erase(b[i]);
  }
  if (misplaced[b[n]].count(n) != 0) {
    misplaced[b[n]].erase(n);
    if (misplaced[b[n]].size() == 0) misplaced.erase(b[n]);
  }
  swap(a[i], a[n]);
  if (a[i] != b[i]) {
    misplaced[b[i]].insert(i);
  }
  if (a[n] != b[n]) {
    misplaced[b[n]].insert(n);
  }
}
int main() {
  GI(n);
  int x;
  int ax = 0;
  int bx = 0;
  for (int i = 0; i < (int)(n); i++) {
    GI(x);
    a.push_back(x);
    ax ^= x;
  }
  for (int i = 0; i < (int)(n); i++) {
    GI(x);
    b.push_back(x);
    bx ^= x;
  }
  as = a;
  a.push_back(ax);
  as.push_back(ax);
  bs = b;
  b.push_back(bx);
  bs.push_back(bx);
  sort(as.begin(), as.end());
  sort(bs.begin(), bs.end());
  if (as != bs) {
    printf("-1\n");
    return 0;
  }
  for (int i = 0; i < (int)(n + 1); i++) {
    if (a[i] != b[i]) {
      misplaced[b[i]].insert(i);
    }
  }
  int steps = 0;
  while (misplaced.size()) {
    if (misplaced.count(a[n]) != 0) {
      swapIdx(*(misplaced[a[n]].begin()));
    } else {
      int k = misplaced.begin()->first;
      swapIdx(*(misplaced[k].rend()));
    }
    steps++;
    {
      cout << "a"
           << " = ";
      for (int _ = 0; _ < (int)(n + 1); _++) cout << a[_] << ' ';
      cout << endl;
    };
    {
      cout << "b"
           << " = ";
      for (int _ = 0; _ < (int)(n + 1); _++) cout << b[_] << ' ';
      cout << endl;
    };
  }
  cout << steps << "\n";
  return 0;
}
