#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main(){
  int N;
  cin>>N;
  int t;
  map<int,int> A;
  for(int i=0;i<N;i++){
    cin>>t;
    A[t]+=1;
  }
  vector<int> B;
  for(int i=0;i<N;i++){
    cin>>t;
    B.push_back(t);
  }
  unsigned long long r=0;
  for(int i=0;i<N;i++){
    cin>>t;
    r+=A[B[t-1]];
  }
  cout<<r<<endl;
}
#include <bits/stdc++.h>

#define vi vector<int>
#define tests int t; cin>>t; while(t--)
#define ll long long
#define vll vector<long long>
#define srt(v) sort(v.begin(), v.end())
#define srtg(v) sort(v.begin(), v.end(), greater<int> ())
#define FOR(k, n) for(int k=0; k<n; k++)
#define pb push_back
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl



using namespace std;


char nums[10] = { '0','1','2','3','4','5','6','7','8','9' };
char alphsl[26] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
const int MOD = 1000000007;
char alphs[26] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };


void solve() {
    
    int n;
    cin>>n;
    vi v(n);
    for(auto& x : v) cin>>x;
    int ans=v[0];
    for(int i=1; i<n; i++){
        ans=__gcd(ans, v[i]);
    }
    
    cout<<ans<<endl;
    
}


int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

        
        solve();


    return 0;
}