#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
using P = pair<int,int>;
int main() {
   ll n;cin>>n;
   vector<ll> A(n),B(n+1,0),C(n+1,0),D(n+1,0);
   rep(i,n)cin>>A[i];
   B[0]=0;
   rep(i,n)B[i+1]=B[i]+A[i];
   C[0]=0;
   rep(i,n)C[i+1]=max(C[i],B[i+1]);
   D[0]=0;
   rep(i,n)D[i+1]=D[i]+B[i+1];
   ll ans=0;
   rep(i,n){
      ans=max(ans,D[i]+C[i+1]);
   }
   ans=max(ans,D[n]);
   cout<<ans<<endl;
}
#include<bits/stdc++.h>
#define ll long long 
#define mp make_pair 
#define f(i,n) for(int i=0;i<n;i++) 
#define F first 
#define S second 
#define pb push_back 

using namespace std;

void test(){
	ll n;
	cin>>n;
	ll a[n],b[n],c[n];
	f(i,n)cin>>a[i];
	f(i,n)cin>>b[i];
	f(i,n)cin>>c[i];
	
	ll freq[n+1];
	f(i,n+1)freq[i] = 0;
	f(i,n)freq[b[c[i]-1]]++;
	
	ll ans = 0;
	
	f(i,n){
		ans = ans + freq[a[i]];
	}
	
	cout<<ans<<"\n";
	
}

int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	// cin>>tests;
	while(tests--){
		test();
	}
}
