#include<bits/stdc++.h>
using namespace std;
int a[200010],pos[200010],vis[200010],f[200010];
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,tot=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        pos[a[i]]=i;
    }
    for(int i=n;i>=1;i--){
        while(pos[i]!=i){
            if(vis[pos[i]]){
                cout<<-1<<"\n";
                return 0;
            }
            f[++tot]=pos[i];
            vis[pos[i]]=true;
            pos[a[pos[i]+1]]--;
            pos[i]++;
            swap(a[pos[i]-1],a[pos[i]]);
        }
    }
    if(tot!=n-1){
        cout<<-1<<"\n";
        return 0;
    }
    for(int i=1;i<=tot;i++)
    cout<<f[i]<<"\n";
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+7;
int a[N],b[N],c[N];
int main(void)
{
    int n;
    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 >> c[i];
    }
    vector<int> d;
    for(int i = 1;i<=n;i++)
    {
        int temp = b[c[i]];
        d.push_back(temp);
    }
    sort(d.begin(),d.end());
    long long ans = 0;
    for(int i = 1;i<=n;i++)
    {
        ans += upper_bound(d.begin(),d.end(),a[i])-lower_bound(d.begin(),d.end(),a[i]);
    }
    printf("%lld\n",ans);
    return 0;
}
