#include<bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define pdd pair<double,double>
#define pii pair<int,int>
#define pll pair<LL,LL>
#define mp make_pair
#define LL long long
#define ULL unsigned long long
#define sqr(x) ((x)*(x))
#define pi acos(-1)
using namespace std;
#define MXN 200005
void solve(){
    int n;
    scanf("%d",&n);
    int a[200005],b[200005],p[200005];
    for(int i = 0;i<n;i++)scanf("%d",&a[i]);
    for(int i = 0;i<n;i++)scanf("%d",&b[i]);
    for(int i = 0;i<n;i++)scanf("%d",&p[i]),p[i]--;
    for(int i = 0;i<n;i++){
        if(a[i]<=b[p[i]]&&p[i]!=i){
            printf("-1\n");
            return ;
        }
    }
    priority_queue<pii> pq;
    for(int i = 0;i<n;i++){
        pq.push(mp(a[i],i));
    }
    vector<pii> ans;
    while(!pq.empty()){
        pii pp=pq.top();
        pq.pop();
        while(p[pp.y]!=pp.y){
            ans.pb(mp(p[pp.y],pp.y));
            swap(p[pp.y],p[p[pp.y]]);
        }
    }
    printf("%d\n",ans.size());
    for(auto it:ans){
        printf("%d %d\n",it.x+1,it.y+1);
    }
}
//a*10 b*10/m

//b*10%m
int main(){
    int t=1;
    //scanf("%d",&t);
    //int n;
    while(t--){
        solve();
    }
}
/*
the first two line contains string "x" followed by two space followed by number one followed by two space followed by string "y".
 */
#include <bits/stdc++.h>
using namespace std;

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  for (int i=0;i<n;i++) cin >> a[i];
  b = a;
  sort(b.begin(),b.end());
  reverse(b.begin(),b.end());
  int ans = 0;
  for (int i=0;i<n;i++) {
    int len = 0;
    for (int j=0;j<n;j++) {
      if (a[j] >= b[i]) {
        len++;
      }
      else {
        ans = max(ans,b[i]*len);
        len = 0;
      }
    }
    ans = max(ans,b[i]*len);
  }
  cout << ans << endl;
}
