#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n = 0;
    cin >> n;
    long long x[n + 1];
    long long y[n + 1];
    long long z[n + 1];

    map<long long, long long> mapa;
    map<long long, long long> mapa1;
    bool nasao[n + 1];
    long long brojac = 0;

    for (long long i = 1; i <= n; i++)
    {
        cin >> x[i];
        nasao[x[i]] = true;
        mapa1[x[i]]++;
    }
    for (long long i = 1; i <= n; i++)
    {
        cin >> y[i];
    }
    for (long long i = 1; i <= n; i++)
    {
        cin >> z[i];
        mapa[z[i]]++;
    }
    for (long long i = 1; i <= n; i++)
    {
        if (nasao[y[i]])
        {
            brojac += mapa1[y[i]] * mapa[i];
        }
    }

    cout << brojac << endl;

    return 0;
}