#include <bits/stdc++.h>
#define here cerr<<"==========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#define ll long long
#define endl '\n'
#define sz(a) (ll)(a.size())
#define fi first
#define sc second
#define pll pair<ll,ll>
#define llinf 1000000000LL
#define pb push_back
using namespace std;
#define maxn 100005
ll n;
ll x[maxn],y[maxn],z[maxn];
ll val[maxn];
ll cnt[maxn];
int main()
{
    ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); cerr.tie(0);
    cin >> n;
    for(ll i = 1;i<=n;i++) cin >> x[i];
    for(ll i = 1;i<=n;i++) cin >> y[i];
    for(ll i = 1;i<=n;i++) cin >> z[i];
    for(ll i = 1;i<=n;i++) val[z[i]]++;
    for(ll i = 1;i<=n;i++) cnt[y[i]]+=val[i];
    ll ans = 0;
    for(ll i = 1;i<=n;i++) ans+=cnt[x[i]];
    cout<<ans<<endl;
    return 0;
}