//#pragma GCC optimize ("O2")
//#pragma GCC optimize ("Ofast")
// IN THE NAME OF GOD
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;

template<typename Head>
inline void dout(Head in) {
  cerr << in << '\n';
} 

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> b(n);
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  vector<int> cnt(n + 1, 0);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    cnt[b[x - 1]]++;
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += cnt[a[i]];
  }
  cout << ans;
  return 0;
}
#include <bits/stdc++.h>
#include <unordered_set>
#include <algorithm>
 
using namespace std;
 
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repll(i,n) for (ll i = 0; i < (ll)(n); i++)
#define fore(x,a) for(auto&(x) : (a))
 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
#define ALL(a) (a).begin(), (a).end()
 
const ll INFL = 1e18;
const int INFI = 1e9;
const int MOD = 1e9 + 7;
 
int main(){
  int N;
  cin >> N;
  vi es = {2,3,5};

  set<int> ans;
  vi base;
  rep(i, 3) {
    int res = 1;
    rep(j, 3){
      if(i !=  j) res *=  es[2-j]; 
    }
    base.push_back(res);
  }

  int max = 0;
  fore(x, base) chmax(max, x);

  fore(x, base){
    int tmp = x;
    while(tmp <= 10000){
      if(tmp > max) ans.insert(tmp);
      tmp += x;
    }
  }
  fore(x, ans) base.push_back(x);

  rep(i, N){
    cout << base[i] << " ";
  }
  cout << endl;
}