#include <bits/stdc++.h>
using namespace std;
#define int              long long int
#define double           long double
#define print(a)         for(auto x : a) cout << x << " "; cout << endl


const int M = 1000000007;
const int N = 3e5+9;
const int INF = 2e9+1;
const int LINF = 2000000000000000001;

inline int power(int a, int b, int mod=M) {
    int x = 1;
    a %= mod;
    while (b) {
        if (b & 1) x = (x * a) % mod; 
        a = (a * a) % mod;
        b >>= 1;
    }
    return x;
}


//_ ***************************** START Below *******************************




vector<int> a;
vector<int> b;

//* Checking whether a occurs in subseq of b 
int subsequence(int s, int e, int n){
	
	int j = s;
	int i = 0;
	int ct = 0;
	
	while(i<n && j<=e){
		while(i<n && b[i] != a[j]) i++;
		if(i==n) break;
		
		ct++;
		i++;
		j++;
	}
	
	return ct;
}

int consistency1(int n){
	
	int maxi = 0;
	
	for(int i=0; i<n; i++){
		for(int j=i; j<n; j++){
			int ct = subsequence(i, j, n);
			maxi = max(maxi, ct);
		}
	}
	
	return n-maxi;
}





int consistency2(int n){

	int maxi = 0;
	
	for(int i=0; i<n; i++){
		
		int j = i;
		int k = 0;
		int ct = 0;
		
		while(j<n){
			while(k<n && b[k] != a[j]) k++;
			if(k==n) break;
			
			ct++;
			j++;
			k++;
		}
		
		maxi = max(maxi, ct);
	}
	
	
	
	return n-maxi;

}





int consistency3(int n){

	unordered_map<int,int> mp;
	for(int i=0; i<n; i++) mp[b[i]] = i;
	
	int maxi = 0;
	
	int i = 0;
	while(i<n){
		
		int j = i+1;
		
		while(j<n && mp[a[j]] > mp[a[j-1]]) j++;
		
		maxi = max(maxi, j-i);
		i = j;
	}
	
	return n-maxi;
}
















int practice(int n){


    return 0;
}





void solve() {
    
    int n;
    cin>> n;
    
    a.resize(n);
    for(int i=0; i<n; i++) cin >> a[i];
    
    b.resize(n);
    for(int i=0; i<n; i++) cin >> b[i];
    
    
    cout << consistency1(n) << " " << consistency2(n) << " " << consistency3(n) << endl;


}





int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}