#include <bits/stdc++.h>
using namespace std;
#define PI pair<int,int>
const int maxm=2e5+5;
int mark[maxm];
int a[maxm];
int b[maxm];
int p[maxm];
int n;
vector<PI>ans;
signed main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        cin>>b[i];
    }
    for(int i=1;i<=n;i++){
        cin>>p[i];
        if(p[i]!=i&&b[p[i]]>=a[i]){//不合法
            return cout<<-1<<endl,0;
        }
    }
    for(int i=1;i<=n;i++){
        if(!mark[i]){
            //求环
            vector<int>temp;
            int x=i;
            while(!mark[x]){
                mark[x]=1;
                x=p[x];
                temp.push_back(x);
            }
            //找重量最大的最为传递员
            int ma=0;
            for(int j=0;j<temp.size();j++){
                if(a[temp[j]]>a[temp[ma]]){
                    ma=j;
                }
            }
            //走一圈,和每个人交换
            for(int j=temp[ma];p[j]!=temp[ma];j=p[j]){
                ans.push_back({temp[ma],p[j]});
            }
        }
    }
    cout<<ans.size()<<endl;
    for(auto i:ans){
        cout<<i.first<<' '<<i.second<<endl;
    }
    return 0;
}
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

int search(int& idx, map<int, int>& mp) {
    if (mp[idx] != idx) return mp[idx] = search(mp[idx], mp);
    else return idx;
}
void unite(int& id1, int& id2, map<int, int>& mp) {
    int l = search(id1, mp);
    int r = search(id2, mp);
    if (l < r) mp[r] = mp[l];
    else mp[l] = mp[r];
}

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  map<int, int> mp;
  rep(i, n) mp[a[i]] = a[i];

  int ans {};
  rep(i, n/2) {
    if (search(a[i], mp) != search(a[n-i-1], mp)) {
        unite(a[i], a[n-i-1], mp);
        ++ans;
    }
  }

  cout << ans << '\n';
}
