#include <bits/stdc++.h>

#define mid(l,r) ((l + r) >> 1)
#define lsb(x) (x & (-x))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define FOR(X,L,R) for(int X=L;X<R;++X)
#define endl '\n'
#define int long long
#define MOD ((int)1e9 + 7)
#define INF (0x3f3f3f3f)
#define LLINF (0x3f3f3f3f3f3f3f3fLL)

using namespace std;

template<typename T>
inline void input(vector<T>& v)
{
    for(T& x: v)
        cin >> x;
}

void solve()
{
    int n; cin >> n;
    vector<int> a(n), b(n), c(n);
    input(a); input(b); input(c);

    vector<int> cnt_pos(n);
    FOR(i, 0, n)
    {
        cnt_pos[c[i] - 1] ++;
    }

    vector<int> sum_pos(n);
    FOR(i, 0, n)
    {
        sum_pos[b[i] - 1] += cnt_pos[i];
    }

    int ans = 0;
    FOR(i, 0, n)
    {
        ans += sum_pos[a[i] - 1];
    }
    cout << ans << endl;
}

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);

    #if defined(CODEFORCES) || defined(CF)
        int t; cin >> t;
        while(t--) solve();
    #else
        solve();
    #endif

    return 0;
}
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <limits.h>
#include <stdio.h>
using namespace std;
 
int main()
{
    int n;
    cin >> n;
    
    int a[n];
    for(int i=0; i<n; i++){
        int tmp;
        cin >> tmp;
        a[i] = tmp;
    }
    
    int mx = 0;
    int ans = 2;
    for(int i=2; i<=1000; i++){
        int cnt = 0;
         for(int j=0; j<n; j++){
             if(a[j]%i == 0){
                 cnt++;
             }
         }
        if(mx < cnt){
            mx = cnt;
            ans = i;
        }
    }
    cout << ans << endl;
    
    return 0;
}