#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
inline int read() {
	int x=0,f=1;char c=getchar();
	while(c<48||c>57){if(c=='-')f=-1;c=getchar();}
	while(c>=48&&c<=57)x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
using namespace std;
const int M=1e5+5;
long long res[M];
int A[M],B[M],C[M],sz[M];
int main() {
	int n=read();
	rep(i,1,n)A[i]=read();
	rep(i,1,n)B[i]=read();
	rep(i,1,n)C[i]=read(),sz[C[i]]++;
	rep(i,1,n)res[B[i]]+=sz[i];
	long long ans=0;
	rep(i,1,n)ans+=res[A[i]];
	cout<<ans;
	return 0;
}

#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
#define For(i,l,r) for(int i=l;i<=r;i++)
#define Pair pair<int,int>
#define F first
#define S second
#define pb push_back
#define abs(x) ((x)>0?(x):-(x))
#define MAXN 200001
int N;Pair x[MAXN],y[MAXN];
int main()
{
	cin>>N;For(i,1,N)cin>>x[i].F>>y[i].F,x[i].S=y[i].S=i;sort(x+1,x+N+1);sort(y+1,y+N+1);
	vector<int>b;b.pb(x[N].F-x[1].F),b.pb(x[N-1].F-x[1].F),b.pb(x[N].F-x[2].F),max(y[N].S,y[1].S)!=max(x[N].S,x[1].S)||min(y[N].S,y[1].S)!=min(x[N].S,x[1].S)?b.pb(y[N].F-y[1].F),0:0,b.pb(y[N-1].F-y[1].F),b.pb(y[N].F-y[2].F);
	sort(b.begin(),b.end(),greater<int>());cout<<b[1]<<endl;return 0;
}