#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; typedef long double ld; typedef vector <int> vi; typedef vector <ll> vll; typedef vector <string> vS; typedef vector <vector <int>> vv; typedef map<int, int> mi; typedef map<string, int> ms; typedef map<char, int> mc; typedef string S; typedef map <ll, ll> ml; typedef map <int, bool> mb; typedef vector <ld> vld; typedef vector <bool> vb; typedef map<ll, ll> mll;
#define FOR(i,N) for(int i = 0 ; i < N;i++)
#define eFOR(i,a,b) for(int i = a; i <=b;i++)
#define dFOR(i,N) for(int i = N - 1; i>=0;i--)
#define edFOR(i,a,b) for(int i = b ; i >=a;i--)
#define all(x) x.begin(),x.end()
#define SORT(x) sort(all(x))
#define RSORT(x) sort(x.rbegin(),x.rend())
#define mine(x) min_element(all(x))
#define maxe(x) max_element(all(x))
#define pb push_back
#define PI 3.14159265359
const int mod = 1e9 + 7;
int CASE = 1;
ll __gcd(ll a, ll b)
{
	return !b ? a : __gcd(b, a % b);
}
void solve()
{
	int n;
	cin >> n;
	mb mp;
	int k = 0;
	FOR(i, n)
	{
		int x;
		cin >> x;
		mp[x] = true;
		while (mp[k])
			k++;
		cout << k << endl;
	}
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int T = 1;
	while (T--)
	{
		solve();
	}
}
#include<algorithm>
#include<cstdio>
#define MaxN 200005
using namespace std;
struct Data{int u,v;}ans[MaxN];
int tot;
bool vis[MaxN];
int a[MaxN],b[MaxN],p[MaxN];
int st[MaxN],tn;
bool cmp(int A,int B)
{return a[A]>a[B];}
void solve(int u)
{
  st[tn=1]=u;
  for (int v=p[u];v!=u;v=p[v])st[++tn]=v;
  sort(st+1,st+tn+1,cmp);
  for (int k=1;k<=tn;k++){
    int i=st[k];
    if (p[i]==i)continue;
    while(p[i]!=i){
      ans[++tot]=(Data){i,p[i]};
      swap(p[i],p[p[i]]);
    }
  }
}
int n;
int main()
{
  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]);
  for (int i=1;i<=n;i++)
    if (b[p[i]]>=a[i]&&p[i]!=i)
      {puts("-1");return 0;}
  for (int i=1;i<=n;i++){
    if (vis[i])continue;
    solve(i);
  }
  printf("%d\n",tot);
  for (int i=1;i<=tot;i++)
    printf("%d %d\n",ans[i].u,ans[i].v);
  return 0;
}