#include<bits/stdc++.h>
using namespace std;
 
const int MaxN=1e5;
int A[MaxN+1]={}; // counting_sort
int B[MaxN+1];
int main(){
	int N, a, c;
 
	cin>>N;
	for(int i=1;i<=N;i+=1){
		cin>>a;  A[a]+=1;
	}
	for(int i=1;i<=N;i+=1)
		cin>>B[i];
 
	long ans=0;
	for(int i=1;i<=N;i+=1){
		cin>>c;
		ans+= A[ B[c] ] ;
	}
	cout<<ans<<'\n';
}
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <ios>
#include <iostream>
#include <iterator>
#include <string_view>
#include <utility>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <climits>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <regex>
#include <set>
#include <bitset>
#include <list>

const int64_t infl = 1LL << 60;
const int64_t cc = pow(10, 9) + 7;
bool sort_pair(std::pair<int64_t, char> origin,std::pair<int64_t, int64_t> another) {return origin.first < another.first; }
template <typename T> bool chmin(T &a, const T& b) {if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b) {if(a < b) {a = b;return true; } return false; }

int main()
{
    int64_t q,k,s,h,w,d,m,n;
    std::cin>> n;
 
    std::vector< int64_t > list( n );
    q = 0;
    
    for( int i = 0; i < n; i++ )
    {
        std::cin>> list[i];
        q += list[i];
    }

    bool dp[n+1][q+1];
    std::memset( dp, 0, sizeof(dp) );
    dp[0][0] = true;

    for( int r = 0; r < n; r++ )
    {
        for( int t = 0; t <= q; t++ )
        {
            dp[r+1][t] |= dp[r][t];
            
            if( list[r] <= t )
            {
                dp[r+1][t] |= dp[r][t-list[r]];
            }                
        }
    }

    k = infl;
    for( int64_t i = 1; i <= q; i++ )
    {
        if( dp[n][i] )
        {
            chmin( k, std::max( i, q - i ) );
        }
    }
    
    std::cout<< k;
}
