//做题头
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define _PI acos(-1.0)
#define INF 0x3f3f3f3f
#define esp 1e-9
#define IOS std::ios::sync_with_stdio(0);cin.tie(0);
#define FRE freopen("abc.in", "r", stdin)
#define MEM(X,Y) memset(X,Y,sizeof(X))
#define rep(i,a,b) for(int  i=a;i<b;++i)
#define rep1(i,a,b) for(int  i=a;i<=b;++i)
#define rrep(i,a,b) for(int i=b-1;i>=a;--i)
#define rrep1(i,a,b) for(int i=b;i>=a;--i)
typedef long long LL;
using namespace std;
/*===========================================*/

const int maxn = 2e5 + 5;
char str[maxn];

int main() {
	scanf("%s", str);
	int len = strlen(str);
	char last = 1;
	int lpos = -1;
	LL ret = 0;
	for (int i = 0; i <= len; ++i) {
		if (str[i] == str[i + 1] && str[i] != last)
		{
			if (~lpos)
				ret += 1LL * len - lpos;
			lpos = i;
			last = str[i];
		}
		if (str[i] == last)
			--ret;
	}
	printf("%lld", ret + 1);
}
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1<<30;
const ll inf_l = 1LL<<61;
const int MAX = 2*1e5+10;

int a[MAX], b[MAX], p[MAX], q[MAX];
vector<P> ans;
int n;

bool solve() {
    rep(i,n) {
        if (p[i] == i) continue;
        int now = i, start = i, mn = b[p[i]];
        while (q[now] != i) {
            if (chmin(mn, b[p[q[now]]])) start = q[now];
            now = q[now];
        }
        auto f = [&](int now) {
            if (a[now] <= b[p[now]]) return false;
            if (a[q[now]] <= b[p[q[now]]]) return false;
            ans.push_back(P(now + 1, q[now] + 1));
            swap(p[now], p[q[now]]);
            return true;
        };
        while (p[start] != start) {
            if (!f(start)) return false;
            start = q[start];
        }
    }
    return true;
}

int main() {
    cin >> n;
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) {
        cin >> p[i];
        p[i]--;
    }
    rep(i,n) q[p[i]] = i;
    if (!solve()) cout << -1 << endl;
    else {
        cout << (int)ans.size() << endl;
        rep(i,ans.size()) {
            cout << ans[i].first << " " << ans[i].second << endl;
        }
    }
}