#include <iostream>

using namespace std;

int main()
{
    unsigned n;
    cin >> n;
    unsigned x[10^5];
    unsigned y[10^5];
    unsigned z[10^5];

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

    unsigned s = 0;
    for (unsigned i = 1; i <= n; i++)
    {
        for (unsigned j = 1; j <= n; j++)
        {
            if (x[i] == y[j])
            {
                for (unsigned k = 1; k <= n; k++)
                {
                    if (j == z[k]) {s++;}
                }
            }
        }
    }
    cout << s << endl;

    return 0;
}