/*
Author : Chandan Agrawal
College : Poornima College of Engg. jaipur, Raj
Mail : chandanagrawal23@gmail.com
 
" when you are not practicing someone else is ,
 and the day u meet them u will lose "
 
*/
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX 10000050
 
#define ll long long
#define ld long double
#define lli long long int
 
#define pb push_back
#define INF 1000000000000
#define mod 1000000007
 
// trignometric function always give value in Radians only
#define PI acos(-1) //3.1415926535897932384626433832795028
#define dsin(degree) sin(degree*(PI/180.0))
#define dcos(degree) cos(degree*(PI/180.0))
#define dtan(degree) tan(degree*(PI/180.0))
 
#define rsin(radian) sin(radian)
#define rcos(radian) cos(radian)
#define rtan(radian) tan(radian)
 
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
 
#define loop(i,n)  for (lli i = 0; i < n; i++)
#define FOR(i,a,b) for (lli i = a; i < b; i++)
 
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define makeuniq(v) v.resize(unique(all(v)) - v.begin()); //only uniq element in vector after this
#define sz(x) int(x.size())
#define F first
#define S second
 
#define mii map<lli,lli>
 
#define pii pair<lli,lli>
 
#define vi vector<lli>
#define vvi vector<vi>
#define vpi vector<pii>
#define vbool vector<bool>
 
#define seti set<lli>
 
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (a/gcd(a,b))*b
#define abs(x) ((x < 0)?-(x):x)
 
#define endl '\n'
 
template <typename Head>
void print(Head&& head)
{
    cout<<head<<endl;
}
template <typename Head, typename... Tail>
void print(Head&& head, Tail... tail)
{
    cout<<head<<" ";
    print(tail...);
}
 
#define scanarr(a,n) for(lli i=0;i<n;i++)    cin>>a[i];
#define scanvec(a,n) for(lli i=0;i<n;i++){ lli x ; cin>>x; a.pb(x);}
 
#define printarr(a,n) for(lli i=0;i<n;i++)   cout<<a[i]<<" "; cout<<endl;
#define printvec(vec) for(auto xt : vec) cout<<xt<<" ";    cout<<"\n";
 
#define FD(N) fixed<<setprecision(N)
 
#define deb(x) cout<<#x<<" "<<x<<endl;
 
/*
1D vector -  vi dp(n,value);
2D vector -  vvi dp(n,vi(n,value));
*/
 
// chandan1,2
void chandan1(){int y=1;return;}
void chandan2(){
        loop(i,10){
        lli x=1;
    }
    return(chandan1());
}
 
 
//---------------------------------------------------BIT----------------------------------------------------------------------
 
lli BIT[MAX], a[MAX], n;
void update(lli x , lli val)
{
    while(x<MAX)
    {
        BIT[x] += val;
        x += (x&-x);
    }
}
 
lli query(lli x)
{
     lli sum = 0;
     while(x>0)
     {
        sum += BIT[x];
        x -= (x&-x);
     }
     
     return sum;
}
 
//--------------------------------------------------BIT------------------------------------------------------------------------
 
 
int main(){
fastio
lli t=1;
//cin>>t;
chandan2();
while(t--) {
    cin>>n;
    lli maxi = -1;
    FOR(i,1,n+1)
    {
        cin>>a[i];
        a[i]++;
        maxi = max(maxi ,a[i]);
    }
    lli cnt =0;
    FOR(i , 1, n+1)
    {
        cnt += (query(MAX)-query(a[i]));
        update(a[i],1);
    }

    FOR(i,1,n+1)
    {
        print(cnt);
        cnt = cnt - (a[i]-1) + (n-a[i]);
        /*
        after shifing a element K from front to back 
        how many inversion pairs we loose ? K-1 as there are K-1 values less than K
        and how mnany new inversion pair get ? (N-K) as there are N-K values greater than K
        */
    }
    mem0(BIT);
  }
return 0;
} 
#include <bits/stdc++.h>
using namespace std;

const int N = 200000 + 9;

int a[N], b[N], p[N], sk[N], top;

bool vis[N];

inline bool check(int j){
    return !(a[j] <= b[p[j]] && p[j] != j);
}

int main(){
    int n; scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", a + i);
    for (int i = 1; i <= n; ++i) scanf("%d", b + i);
    for (int i = 1; i <= n; ++i) scanf("%d", p + i);
    bool f = true;
    vector<pair<int, int>> ans;
    for (int i = 1; i <= n; ++i){
        if (!vis[i]){
            int j = i;
            if (!check(j)){ f = false; break; }
            sk[++top] = j;
            vis[j] = true;
            while (!vis[p[j]]){
                j = p[j];
                if (!check(j)){ f = false; break; }
                if (a[j] <= a[sk[top]]){
                    ans.push_back({j, sk[top]});
                    p[sk[top]] = p[j];
                }
                else {
                    sk[++top] = j;
                }
                vis[j] = true;
            }
            if (!f) break;
            for (j = 1; j < top; ++j){
                ans.push_back({sk[j], sk[top]});
            }
            top = 0;
        }
    }
    if (f){
        printf("%d\n", (int)ans.size());
        for (auto it : ans){
            printf("%d %d\n", it.first, it.second);
        }
    }
    else {
        printf("-1\n");
    }
    return 0;
}