#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) begin(v), end(v)
using namespace std;
using P = pair<int,int>;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;

ll ll_pow(ll a, ll n) {
  ll ans = 1;
  for(ll i = 0; i < n; i++) ans *= a;
  return ans;
}

int main() {
  int n;
  ll ans = 0;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  
  vector<int> cnt(n+1);
  vector<int> cnt_s(n+1);
  
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n) cin >> c[i];
  
  rep(i,n){
      cnt_s[b[c[i]-1]]++;
  }
  
  rep(i,n){
    ans += cnt_s[a[i]];
  }
  cout << ans << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<ll>
#define pb push_back
#define ff first
#define ss second
#define inf 2e18
#define ull unsigned long long
#define pi acos(-1.0)
#define mod 1000000007
#define lop0(n) for(ll i=0;i<n;i++)
#define lop(j,n) for(ll j=0;j<n;j++)
#define lop1(n) for(ll i=1;i<=n;i++)
#define all(v) v.begin(),v.end()
ll Set(ll N,ll pos){ return N=N | (1LL<<pos); }
ll reset(ll N,ll pos){ return N= N & ~(1LL<<pos); }
bool check(ll N,ll pos){ return (bool)(N & (1LL<<pos)); }
ll dx[] = { 1,0,-1,0 };
ll dy[] = { 0,1,0,-1 };
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
ll pos[200005],arr[200005];
main()
{
   ll n;
   cin>>n;
   if(n<0) n=0;
   cout<<n;

}

