#include <iostream>
#include <vector>

int main() {
    int N;
    std::cin >> N;
    std::vector<int> A(N), B(N), C(N);
    for (auto& x : A) {
        std::cin >> x;
        x -= 1;
    }
    for (auto& x : B) {
        std::cin >> x;
        x -= 1;
    }
    for (auto& x : C) {
        std::cin >> x;
        x -= 1;
    }
    std::vector<int> count(N);
    for (int j = 0; j < N; ++j) {
        count[B[C[j]]] += 1;
    }
    long long ans = 0;
    for (int i = 0; i < N; ++i) {
        ans += count[A[i]];
    }
    std::cout << ans << '\n';
}

//#pragma GCC optimize(2)

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <cctype>

using namespace std;

#define sync ios::sync_with_stdio ( false ); cin.tie(0); cout.tie(0)  // cin优化
#define debug freopen("data.in","r",stdin); freopen("data.out","w",stdout)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<int, PII> PIP;
typedef pair<PII, int> PPI;

const int N = 1e5 + 10, M = 500;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

/*-----------------以下正文-----------------*/

int q[4][N];
int a[N], b[N];
int cnt1[N], cnt2[N];

int main ( void )
{
    sync;

    int n;
    cin >> n;
    for ( int i = 1; i <= 3; i++ )
    {
        for ( int j = 1; j <= n; j++ ) cin >> q[i][j];
    }

    for ( int i = 1; i <= n; i++ ) a[i] = q[1][i], b[i] = q[2][q[3][i] ];

    for ( int i = 1; i <= n; i++ ) cnt1[a[i]]++, cnt2[b[i]]++;

    ll res = 0;
    for ( int i = 1; i <= n; i++ ) res += (ll)cnt1[i] * cnt2[i];

    cout << res << endl;
    return 0;
}

/*
  遇到困难时你可能会用到的提示：

    1、能用 ll 就要用 ll。
    2、返回 ll 答案时，函数的返回类型要为 ll
    3、图论数据量大，最好用 scanf 或 sync
*/