#include <iostream>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	unsigned long long int N, i, j, k, br=0;
	cin >> N;
	unsigned long long int X[N], Y[N], Z[N], XBr[100001], ZBr[100001];
	for (i = 0; i < N; i++) {
		cin >> X[i];
		XBr[X[i]]=XBr[X[i]] + 1;
	}
    for (j = 0; j < N; j++) {
        cin >> Y[j];
    }

    for (k = 0; k < N; k++) {
        cin >> Z[k];
        ZBr[Z[k] = ZBr[Z[k]]+1;
    }
    for(j = 0; j < N; j++) {
        br =(unsigned long long int) br + (unsigned long long int)ZBr[j+1] * (unsigned long long int)XBr[Y[j]];
    }
    cout << br;
    return 0;
}