#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    int n;
    cin >> n;
    int x[n+1], y[n+1], z[n+1];
    
    for (int i = 1; i <= n; i++)
    {
        cin >> x[i];
    }
    for (int i = 1; i <= n; i++)
    {
        cin >> y[i];
    }
    for (int i = 1; i <= n; i++)
    {
        cin >> z[i];
    }

    for (int i = 1; i <= n; i++)
    {
        
    }
    
    int recepti[n+1];
    int jela[n+1];
    for (int i = 1; i <= n; i++)
    {
        recepti[i] = 0;
        jela[i] = 0;
    }
    
    for (int i = 1; i <= n; i++)
    {
        recepti[z[i]]++;
    }

    for (int i = 1; i <= n; i++)
    {
        jela[y[i]] += recepti[i];
    }    

    ll c = 0;

    for (int i = 1; i <= n; i++)
    {
        c+= jela[x[i]];
    }

    cout << c << "\n";

    return 0;
}