#include <bits/stdc++.h>
typedef long long ll ;

using namespace std;

int main() {
	int n; cin >> n;
	vector<int> a(n),b(n),c(n), hash(n,0);
	for (int i = 0; i < n ; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		cin >> b[i];
	for (int i = 0; i < n; i++)
		cin >> c[i];
	for (int i = 0; i < n ; i++)
		hash[a[i]-1]++;
	ll ans = 0;
	for (int i = 0; i < n; i++)
		ans += hash[b[c[i]-1]-1];
	cout << ans;
	return 0;
}
// Whatever doesn't kill you simply makes you stronger.
// Every single thing is destined, everything is written.
#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 ll long long
#define hii cout << "hii" << endl
#define int long long
#define endl '\n'
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define all(s) s.begin(), s.end()

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
 
const int N = 5e5 + 5;
const int MAXN = 1e7 + 5;
const int M = 1000 + 5;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int INF = 1e17 + 8;
const int INFF = 1e18 + 8;
const int LG = 21;

int arr[N];
int cnt[N];

void solve()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		cin >> arr[i];
		cnt[arr[i]]++;
	}
	int mx = 0;
	int no = -1;
	for(int i = 2; i < N; i++)
	{
		int check = 0;
		for(int j = i; j < N; j += i)
		{
			check += cnt[j];
		}
		if(check > mx)
		{
			mx = check;
			no = i;
		}
	}
	cout << no << endl;
}
 
int32_t main() 
{	
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	#ifndef ONLINE_JUDGE
	  freopen("input.txt", "r", stdin);
	  freopen("output1.txt", "w", stdout);
 	#endif
	int t = 1;
	// cin >> t;
	while(t--)
	{
		solve();
	}
	return 0;
}