#include <bits/stdc++.h>
using namespace std;
#define fst ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endk cout<<"\n";
typedef long long int ll;
typedef long int l;
#define l(i,a,b) for(i=a;i<b;i++)
#define lo(i,a,b) for(i=a;i>=b;i--)
#define s(v) sort(v.begin(),v.end());
#define pb push_back;
#define vll vector<ll>
#define vint vector<int>
#define test() ll t;cin>>t;while(t--){solve();};
#define test1() int t=1;while(t--){solve();};
bool isprime(ll x)
{
    if(x==1) return false;
    if(x==2 || x==3) return true;
    if(x%2==0 || x%3==0) return false;
    for(ll i=5;i*i<=x;i+=6)
    {
        if(x%i==0 || x%(i+2)==0) return false;
    }
    return true;
}
ll power(ll x,ll y)
{
	ll ans=1;
	while(y>0)
	{
		if(y&1) ans=ans*x;
		x=x*x;
		y=y>>1;
	}
	return ans;
}
int solve()
{
    ll n,i,ans=0;
    cin>>n;
    vector<ll> a(n),b(n),c(n);
    map<ll,ll> m;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n;i++)
    {
        cin>>b[i];
    }
    for(i=0;i<n;i++)
    {
        cin>>c[i];
        c[i]=b[c[i]-1];
        m[c[i]]++;
    }
    for(i=0;i<n;i++)
    {
        ans+=m[a[i]];
    }
    cout<<ans;
    return 0;
}
int main()
{
    fst;
    test1();
    return 0;
}

#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#define ll long long
using namespace std;

//take care of long long

//fast I/O 
auto optimizer = []() {  // makes I/O fast
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  return 0;
}();

int main() {
	ll t=1;
	//cin>>t;
	while(t--)
	{
	    ll n;
	    cin>>n;
	    vector<ll> vc(n);
	    ll sum=0;
	    for(ll i=0;i<n;i++)
	    {
	        cin>>vc[i];
	        sum+=vc[i];
	    }
	    vector<vector<ll>> dp(sum+1, vector<ll>(n,0));
	    sort(vc.begin(),vc.end());
	    ll ans=INT_MAX;
	    for(ll sm=1;sm<=dp.size()-1;sm++)
	    {
	        for(ll i=0;i<n;i++)
	        {
	            if(i>0&&dp[sm][i-1])
	            {
	                dp[sm][i]=1;
	            }
	            else
	            {
	                if(sm<vc[i])
	                {
	                    dp[sm][i]=0;
	                }
	                else if(sm==vc[i] || (i>=1 && dp[sm-vc[i]][i-1]) )
	                {
	                    dp[sm][i]=1;
	                }
	                else
	                {
	                    dp[sm][i]=0;
	                }
	            }
	        }
	        if(dp[sm][n-1])
	        {
	            //cout<<sm<<endl;
	            ans=min(ans,max(sm,sum-sm));
	        }
	    }
	    cout<<ans<<endl;
	}
	return 0;
}