#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
#define Rep(i,n) for (int i=1; i<=(n); i++)
typedef long long ll;
using namespace std;

int main(){
    int N; cin >> N;
    vector <int> P(N);
    vector <int> Q(N);

    rep(i,N) cin >> P[i];
    rep(i,N) cin >> Q[i];
    
    int cnt=0;
    int ans1=0;
    int ans2=0;
    
    if (P==Q){
        cout << 0;
        return 0;
    }
    
    else if (N==2){
        for (int i=1; i<=N; i++){
            for (int j=1; j<=N; j++){
                if (i==j) continue;
                cnt+=1;
                
                if (P[0]==i && P[1]==j) ans1=cnt;
                if (Q[0]==i and Q[1]==j) ans2=cnt;                
            }
        }
    }
    
    else if (N==3){
        for (int i=1; i<=N; i++){
            for (int j=1; j<=N; j++){
                if (i==j) continue;
                for (int k=1; k<=N; k++){
                    if (i==k || j==k) continue;
                    cnt+=1;
                
                    if (P[0]==i && P[1]==j && P[2]==k) ans1=cnt;
                    if (Q[0]==i and Q[1]==j && Q[2]==k) ans2=cnt;     
                }
            }
        }
    }

    else if (N==4){
        for (int i=1; i<=N; i++){
            for (int j=1; j<=N; j++){
                if (i==j) continue;
                for (int k=1; k<=N; k++){
                    if (i==k || j==k) continue;
                    for (int a=1; a<=N; a++){
                        if (a==i || a==j ||a==k) continue;
                        cnt+=1;
                        
                        if (P[0]==i && P[1]==j && P[2]==k && P[3]==a) ans1=cnt;
                        if (Q[0]==i and Q[1]==j && Q[2]==k && Q[3]==a) ans2=cnt; 
                    }
                }
            }
        }
    }

    else if (N==5){
        for (int i=1; i<=N; i++){
            for (int j=1; j<=N; j++){
                if (i==j) continue;
                for (int k=1; k<=N; k++){
                    if (i==k || j==k) continue;
                    for (int a=1; a<=N; a++){
                        if (a==i || a==j ||a==k) continue;
                        for (int b=1; b<=N; b++){
                            if(b==i || b==j || b==k ||b ==a) continue;
                            cnt+=1;
                            if (P[0]==i && P[1]==j && P[2]==k && P[3]==a && P[4]==b) ans1=cnt;
                            if (Q[0]==i and Q[1]==j && Q[2]==k && Q[3]==a && Q[4]==b) ans2=cnt; 
                        }
                    }
                }
            }
        }
    }
    
    else if (N==6){
        for (int i=1; i<=N; i++){
            for (int j=1; j<=N; j++){
                if (i==j) continue;
                for (int k=1; k<=N; k++){
                    if (i==k || j==k) continue;
                    for (int a=1; a<=N; a++){
                        if (a==i || a==j ||a==k) continue;
                        for (int b=1; b<=N; b++){
                            if(b==i || b==j || b==k ||b ==a) continue;
                            for (int c=1; c<=N; c++){
                                if(c==i || c==j || c==k || c==a|| c==b)
                                cnt+=1;
                                if (P[0]==i && P[1]==j && P[2]==k && P[3]==a && P[4]==b && P[5]==c) ans1=cnt;
                                if (Q[0]==i and Q[1]==j && Q[2]==k && Q[3]==a && Q[4]==b && Q[5]==c) ans2=cnt;
                            }
                             
                        }
                    }
                }
            }
        }
    }
    
    else if (N==7){
        for (int i=1; i<=N; i++){
            for (int j=1; j<=N; j++){
                if (i==j) continue;
                for (int k=1; k<=N; k++){
                    if (i==k || j==k) continue;
                    for (int a=1; a<=N; a++){
                        if (a==i || a==j ||a==k) continue;
                        for (int b=1; b<=N; b++){
                            if(b==i || b==j || b==k ||b ==a) continue;
                            for (int c=1; c<=N; c++){
                                if(c==i || c==j || c==k || c==a|| c==b) continue;
                                for (int d=1; d<=N; d++){
                                    if (d==i || d==j || d==k || d==a || d==b || d==c ) continue;
                                    cnt+=1;
                                    if (P[0]==i && P[1]==j && P[2]==k && P[3]==a && P[4]==b && P[5]==c && P[6]==d) ans1=cnt;
                                    if (Q[0]==i and Q[1]==j && Q[2]==k && Q[3]==a && Q[4]==b && Q[5]==c && Q[6]==d) ans2=cnt;
                                }
                                
                            }
                             
                        }
                    }
                }
            }
        }
    }
    
    else if (N==8){
        for (int i=1; i<=N; i++){
            for (int j=1; j<=N; j++){
                if (i==j) continue;
                for (int k=1; k<=N; k++){
                    if (i==k || j==k) continue;
                    for (int a=1; a<=N; a++){
                        if (a==i || a==j ||a==k) continue;
                        for (int b=1; b<=N; b++){
                            if(b==i || b==j || b==k ||b ==a) continue;
                            for (int c=1; c<=N; c++){
                                if(c==i || c==j || c==k || c==a|| c==b) continue;
                                for (int d=1; d<=N; d++){
                                    if (d==i || d==j || d==k || d==a || d==b || d==c ) continue;
                                    for (int e=1; e<=N; e++){
                                        if (e==i || e==j || e==k || e==a || e==b || e==c || e==d) continue;
                                        cnt+=1;
                                        if (P[0]==i && P[1]==j && P[2]==k && P[3]==a && P[4]==b && P[5]==c && P[6]==d && P[7]==e) ans1=cnt;
                                        if (Q[0]==i and Q[1]==j && Q[2]==k && Q[3]==a && Q[4]==b && Q[5]==c && Q[6]==d && Q[7]==e) ans2=cnt;
                                    }
                                    
                                }
                                
                            }
                             
                        }
                    }
                }
            }
        }
    }    
    
    
    cout << abs(ans1-ans2);
    
    
    
}

Measured memory_bytes: 256