#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI acos(-1)
#define vi vector<int>
const int kMod = 1e9 + 7;
const int kInf = (~(1<<31)) / 2 - 500;
const ll kInfL = (~(1LL<<63)) / 2 - 2000;

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  for (int i = 0; i < N; ++i) {
    cin >> B[i];
  }
  vector<int> idx(N);
  for (int i = 0; i < N; ++i) {
    int tmp;
    cin >> tmp;
    --tmp;
    ++idx[tmp];
  }
  map<int, int> cnt;
  for (int i = 0; i < N; ++i) {
    cnt[B[i]] += idx[i];
  }
  ll ans = 0;
  for (int i = 0; i < N; ++i) {
    ans += cnt[A[i]];
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e5 + 5;
const int modu = 998244353;
const double eps = 1e-5;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

typedef long long LL;

int n;
LL sum[maxn];

int main() {
    // freopen("my.txt", "w", stdout);
	cin >> n;
    sum[0] = 0;
    for (int i = 1; i <= n; ++i) {
        scanf("%lld", &sum[i]);
        sum[i] += sum[i-1];
    }
    LL ss = 0, ans = 0, incr = sum[1];
    for (int i = 1; i <= n; ++i) {
        ans = max(ans, ss+incr);
        ss += sum[i];
        if (i+1 <= n)
            incr = max(incr, sum[i+1]);
    }
    cout << ans << endl;
	return 0;
}
