#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;

    vector<int> emisije(n);
    vector<int> recepti(n);
    vector<int> scenario(n);

    for (int i = 0; i < n; i++) {
        cin >> emisije[i];
    }

    for (int i = 0; i < n; i++) {
        cin >> recepti[i];
    }

    for (int i = 0; i < n; i++) {
        cin >> scenario[i];
    }

    vector<int> seen;
    vector<int> vrednosti;

    int sve = 0;

    vector<int> trenRecepti;

    for (int j = 0; j < n; j++) {
        vector<int> ponavljanja;
        int ukupno = 0;

        for (int i = 0; i < n; i++) {
            if (recepti[i] == emisije[j]) {
                ponavljanja.push_back(i + 1);
                int r = i + 1;

                if (find(seen.begin(), seen.end(), r) != seen.end()) {
                    ukupno += vrednosti[distance(seen.begin(), find(seen.begin(), seen.end(), r))];
                    continue;
                }

                int vrednost = count(scenario.begin(), scenario.end(), r);
                vrednosti.push_back(vrednost);
                seen.push_back(r);

                ukupno += vrednost;
            }
        }

        sve += ukupno;
    }

    cout << sve << endl;

    return 0;
}