#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < b; ++i)

int debug = 0;

const int N = 5e5;

int n, strong, cur, start, was[N], a[N], b[N], p[N];
vector <array <int, 2>> ans;

void fail() {
    puts("-1");
    exit(0);
}

void sw(int i, int j) {
    swap(p[i], p[j]);
    ans.push_back({i, j});
}

main() {
    cin >> n;
    rep(i, 1, n + 1) { cin >> a[i]; }
    rep(i, 1, n + 1) { cin >> b[i]; }
    rep(i, 1, n + 1) { cin >> p[i]; }
    rep(i, 1, n + 1) { 
        if (i != p[i] && a[i] <= b[p[i]]) {
            fail();
        }
    }
    rep(i, 1, n + 1) {
        if (debug) {
            cerr << " i: "<< i << '\n';
        }
        if (!was[i]) {
            strong = i;
            start = i;
            was[start] = 1;
            cur = p[start];
            while (cur != start) {
                was[cur] = 1;
                if (a[cur] > a[strong]) {
                    strong = cur;
                }
                cur = p[cur];
            }

            while (p[strong] != strong) {
                if (debug) { cerr << " strong: " << strong << ' ' << p[strong] << '\n'; }
                sw(strong, p[strong]);
            }
        }
    }
    cout << ans.size() << '\n';
    for (auto i : ans) {
        cout << i[0] << ' ' << i[1] << '\n';
    }
}

#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (ll i = ((n) - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

// inputs
#define VLLIN(x, n) vll x(n); REP(i, n) cin >> x[i];
#define VIIN(x, n) vin x(n); REP(i, n) cin >> x[i];
#define VLDIN(x, n) vld x(n); REP(i, n) cin >> x[i];
#define SIN(s, n) string s; cin >> s;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

template <typename T>
void print(vector<T>& x) {
    int N = x.size();
    REP(i, N) {
        if (i > 0) cout << " ";
        cout << x[i];
    }
    cout << "\n";
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int n; cin >> n;
    string s1, s2; cin >> s1 >> s2;

    int c1 = 0, c2 = 0;
    REP(i, n) {
        c1 += s1[i] == '1';
        c2 += s2[i] == '1';
    }

    if (c1 != c2) {
        print(-1);
        return 0;
    }

    stack<int> q1, q2;
    REP(i, n) {
        if (s1[i] == '0') q1.push(i);
        if (s2[i] == '0') q2.push(i);
    }

    int ans = 0;
    assert(q1.size() == q2.size());
    while(q1.size()) {
        auto a = q1.top(); q1.pop();
        auto b = q2.top(); q2.pop();
        ans += a != b;
    }

    print(ans);

}
