#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#include <cctype>
#include <list>
#include <cassert>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define ll long long
#define repi(i,a,b) for(ll i=a;i<b;++i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

using namespace std;
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; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
using vvv = vector<vector<vector<ll>>>;
using vv = vector<vector<ll>>;
using vec = vector<ll>;
using P = pair<ll, ll>;

int main(void){
    ll n; cin >> n;
    vec al(n), bl(n), cl(n);
    rep(i, n) cin >> al[i];
    rep(i, n) cin >> bl[i];
    rep(i, n) cin >> cl[i];
    map<ll, ll> amp;
    map<ll, ll> bmp;
    
    rep(i, n){
        amp[al[i]]++;
    }
    
    rep(i, n){
        bmp[bl[cl[i] - 1]]++;
    }
    
    ll ans = 0;
    for(auto item : amp){
        ans += bmp[item.first] * item.second;
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define indexed_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
//find_by_order = returns pointer to element at that pos
//order_of_key = returns pos of the given element
#define indexed_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define all(x)  (x).begin(),(x).end() 
#define mem1(a)  memset(a,-1,sizeof(a))
#define mem0(a)  memset(a,0,sizeof(a))  
#define int long long
#define endl "\n"
typedef vector<int> vi;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for (int i = a; i <b; i++)
#define MOD 1000000007
#define boost
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.F>>a.S;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.F<<" "<<a.S;return out;}
template<class _T>inline void read(_T &_a)
{
    bool f=0; char _c=getchar(); _a=0;
    while(_c<'0'||_c>'9'){ if(_c=='-') f=1; _c=getchar(); }
    while(_c>='0'&&_c<='9'){ _a=(_a<<3)+(_a<<1)-'0'+_c; _c=getchar(); }
    if(f) _a=-_a;
}
int pw(int a,int b,int p){
    if(b==0)return 1;
    int t=pw(a,b/2,p);
    if(b%2)return (((a*t)%p)*t)%p;
    else return ((t*t)%p);
}

const long long INF=1e18;
int T=1;
int n;
vi a;

bool good(int x)
{
    
    rep(i,0,n)
    {
        if(__gcd(x,a[i])==1)
        return false;
    }
    return true;
}
vector<int> pdivs;
void solve2(int x) {
	for(int i=2; i*i <= x; i++) {
		if(x % i == 0) {
			pdivs.push_back(i);
			while(x % i==0) x /= i;
		}
	}
	if(x > 1) pdivs.push_back(x);
}

int32_t main()
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  /*   cin>>T; */
      while(T--)
   {
       
       cin>>n;
    a.resize(n);
    int ans=INF;
       rep(i,0,n)
       cin>>a[i];
       vi primes = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
       rep(i,0,1LL<<15)
       {
           int x=1;
           rep(j,0,15)
           {
               if(i&(1LL<<j))
               x=x*primes[j];
           }
           bool res = good(x);
           if(res)
           {
               ans=min(ans,x);
           }
       }
       cout<<ans<<endl;
     

        
   }
   
	// you should actually read the stuff at the bottom
 
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/
return 0;
}