#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include<bitset>
#include<cstdlib>
#include<set>
#include<unordered_map>
#define l(x) (x<<1)
#define r(x) ((x<<1)|1)
#define low(x) (x&(-x))
#define IL inline
#define reg register
#define LL long long
#define N 500010
#define MOD 998244353
#define MO 1000000007
#define INF 0x3f3f3f3f
using namespace std;

int T,n,m,i,j,k,x,y,z,sum,cnt;
int b[N],p[N],q[N];

struct Data{
	int x,y,id,p;
}a[N],Ans[N];

IL int Abs(int x){return (x<0)?-x:x;}
IL void Swap(int &a,int &b){a^=b^=a^=b;}
IL int Min(int a,int b){return (a<b)?a:b;}
IL int Max(int a,int b){return (a>b)?a:b;}

IL bool cmp(const Data a,const Data b){return (a.x==b.x)?a.y<b.y:a.x<b.x;}

IL LL Mi(LL x,LL y){
	LL p=x,t=1,Res=1;
	for (;t<=y;(t&y)?Res=(Res*p)%MOD:0,p=(p*p)%MOD,t<<=1);
	return Res;
}

IL int read(){
	int p=0,f=1;	char	c=getchar();
	while (c<48||c>57)	{if (c=='-')	f=-1;	c=getchar();}
	while (c>=48&&c<=57)	p=(p<<1)+(p<<3)+c-48,c=getchar();
	return p*f;
}

int main(){
	#ifdef __Marvolo
	freopen("zht.in","r",stdin);
	freopen("zht.out","w",stdout);
	#endif
	n=read();
	for (i=1;i<=n;i++)	a[i].x=read(),a[i].p=i;
	for (i=1;i<=n;i++)	b[i]=read();
	for (i=1;i<=n;i++)	a[i].id=read(),a[i].y=b[a[i].id];
	
	for (i=1;i<=n;i++){
		if (a[i].id==i)	continue;
		if (a[i].y>=a[i].x)	{
			puts("-1");	return 0;
		}
	}

	for (i=1;i<=n;i++)	p[a[i].id]=i;
	for (i=1;i<=n;i++)	q[i]=a[i].id;

	sort(a+1,a+1+n,cmp);
	for (i=1;i<=n;i++){
		x=p[a[i].p];	y=q[a[i].p];
		if (x==a[i].p)	continue;
		p[a[i].p]=q[a[i].p]=a[i].p;
		p[y]=x;	q[x]=y;

		cnt++;
		Ans[cnt].x=a[i].p;	Ans[cnt].y=x;
		
	}

	cout<<cnt<<endl;
	for (i=1;i<=cnt;i++)
		printf("%d %d\n",Ans[i].x,Ans[i].y);
	return 0;
}
#include<bits/stdc++.h>
#define pb push_back
#define endl ("\n")
#define mp make_pair
#define lb lower_bound
#define ff first
#define ss second
#define cn continue
#define br break
#define ins insert
#define int long long
#define bit(x) __builtin_popcount(x)
#define all(x) x.begin(),x.end()
#define up upper_bound
#define read(a,n) rep(i,0,n){cin>>a[i];}
#define print(a,n) rep(i,0,n) cout<<a[i]<<" ";
#define rep(i, a, n) for(int i = a; i < n; i++)
#define mod 1000000007
#define yy cout<<"YES"<<endl;
#define nn cout<<"NO"<<endl;
using namespace std;


int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1 ;
    //cin >> t ;

    while (t--)
    {
        int n;
        cin >> n;
        int p = log2(n);
        int q = pow(2, p);
        int v = n / q, s = n % q;
        int a = p + v + s;

        while (p > 0) {
            a = min(a, p + v + s);
            q /= 2; p--;
            if (q == 0)
                break;
            v = n / q; s = n % q;
        }

        cout << a << endl;

    }
    return 0;
}