/* Author : Anurag Bhatt 
 * Date   : 2021-05-22 17:35:47
 */
#include <bits/stdc++.h>

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi; 
typedef vector<pi> vpi;

#define mp make_pair
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rsz resize
#define bk back()
#define pb push_back
#define ins insert
#define del erase
#define inf INT_MAX
#define db cout << "here" << endl;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
#define nl endl
const int MOD = 1e9+7;
const ld PI = acos((ld)-1);
mt19937 rng; // or mt19937_64
template<class T> bool ckmin(T& a, const T& b) { 
    return b < a ? a = b, 1 : 0; }
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down

void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << h; if (sizeof...(t)) cerr << ", ";
    DBG(t...); }
#ifdef LOCAL // compile with -DLOCAL
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif
const int MX = 200002;
const int INF = MX+MX;  
vector<int> adj[MX];
void solve() {
    int n;
    cin >> n;
    ll a[n];
    ll b[n];
    ll c[n];
    F0R(i,n) cin >> a[i];
    F0R(i,n) cin >> b[i];
    F0R(i,n) cin >> c[i];
    ll flag[100002];
    memset(flag,0,sizeof flag);
    F0R(i,n) flag[a[i]]++;
    ll ans = 0;
    F0R(i,n) {
        ans+=flag[b[c[i]-1]];
    }
    cout << ans;

}

int main() {
    int t = 1;
    //cin >> t; //comment if there is only one test - case
    for(int i = 1; i <= t ; i++) {
        solve();
    }
}
    

#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 ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
 
#define FS              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll              long long  int
#define ld              long double
#define pb              push_back
#define bp              __builtin_popcount
#define sz              size()
#define ff              first
#define ss              second
#define vll             vector<ll>
#define vbool           vector<bool>
#define vpll            vector<pair<ll,ll>>
#define pll             pair<ll,ll>
#define vllv            vector<vector<ll>>
#define setpri(x)       cout<<setprecision(x)<<fixed;
#define all(v)          v.begin(),v.end()
 
#define allr(v)         v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll mod=998244353;

ll ceil1(ll n,ll x){return (n-1)/x+(n>0);}
 
ll gcd(ll a,ll b){return __gcd(a,b);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}
 
ll pow1(ll n,ll m ,ll mod=MOD );
ll pow2(ll n,ll k);
 
ll modinv(ll n,ll mod=MOD){  return pow1(n,mod-2,mod);}
 
bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
        if(a.ff != b.ff)return a.ff < b.ff;
        return a.ss > b.ss;
}
 
ll const N=(ll)1e5+11;
ll const LG=(ll)log2(N)+1;

vpll v[101];
void pre(){
        vll prime(101);
        for(int i=2;i<=100;i++){
                if(prime[i])continue;
                for(int j=i;j<=100;j+=i){
                        prime[j]=1;
                        int x=j;
                        int c=0;
                        while(x%i==0){
                                c++;
                                x/=i;
                        }
                        v[j].pb({i,c});
                }
        }
}
ll rem(ll n,ll m){
        if(n==0 || m==0)return 1;
        map<ll,ll> mp;
        for(int i=1;i<=n+m;i++){
                for(auto [x,y]:v[i]){
                        mp[x]+=y;
                }
        }
        for(int i=1;i<=n;i++){
                for(auto [x,y]:v[i]){
                        mp[x]-=y;
                }
        }
        for(int i=1;i<=m;i++){
                for(auto [x,y]:v[i]){
                        mp[x]-=y;
                }
        }
        ll ans=1;
        for(auto x:mp){
                ans*=pow2(x.ff,x.ss);
        }
        return ans;
        
}
void solve() {
       ll n;
    cin>>n;
    map<ll,ll> mp,mp3;
    map<ll,vll> mp2;
    vll a(n),b(n),c(n);
    for(auto &x:a)
        cin>>x,mp[x]++;
    for(auto &x:b)
        cin>>x;
    for(auto &x:c)
        cin>>x,mp3[x]++;
    for(ll i=0;i<n;i++)
    {
        mp2[b[i]].push_back(i+1);
    }
    ll ans=0;
    for(auto x:mp2)
    {
        ll t=x.first;
        vll cnt=x.second;
        for(auto y:cnt)
        {
            ans+=(mp[t]*mp3[y]);
        }
    }
    cout<<ans;
        
        
}
int main(){
        // FS;
        ll q;
        q=1;
        pre();
        // cin>>q;
        for(ll tc=1;tc<=q;tc++){
                // cout<<"Case #"<<tc<<": ";
                solve();
        }
        return 0;
}
 
 
ll pow1(ll n,ll m,ll mod){
        if(m==0)return 1;
 
        if(m%2==0)return pow1((n*n)%mod,m/2,mod);
 
        return (pow1((n*n)%mod,m/2,mod)*n)%mod;
}
 
ll pow2(ll n,ll k){
        ll ans=1;
            while(k>0){
                if(k%2==1)ans=ans*n;
                n=n*n;
                k/=2;
            }
        return ans;
}