#include<bits/stdc++.h>
using ll = long long;
#define REP(i, n) for (ll i = 0; (i) < ll(n); ++ (i))
#define FOR(i, m, n) for (ll i = (m); (i) <= ll(n); ++ (i))
#define REPR(i, n) for (ll i = ll(n) - 1; (i) >= 0; -- (i))
#define FOR3R(i, m, n) for (ll i = ll(n) - 1; (i) >= ll(m); -- (i))
#define ALL(x) x.begin(),x.end()

#define INF (int)1e9 //10^9:∞
#define LLINF (long long)1e12
#define MOD (int)1e9+7 //10^9+7:合同式の法
#define PI 3.141592653589
#define PB push_back
#define F first
#define S second

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>> //VVI a(n, vector<int>(m));
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)

template <class T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T>
T GCD(T a, T b) {
	if (b == 0)
		return a;
	else
		return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
	return (a * b) / GCD(a, b);
}

using namespace std;

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  //小数の桁数の出力指定
  //cout<<fixed<<setprecision(10);
  int n;
	 cin >> n;
	 vector<ll> a(n+1,0), b(n+1,0), bt(n+1,0);
	 int t;
	 REP(i,n) {
		 cin >> t;
		 ++a[t];
	 }
	 REP(i,n){
	 	 cin >> b[i];
	 }
	 REP(i,n) {
		 cin >> t;
		 ++bt[b[t-1]];
	 }

	 ll c = 0;
	 REP(i,n+1){
		 c += a[i] * bt[i];
	 }
	 cout << c << endl;
}

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (ll)(n); i++)
#define BIT(bit, n) for (int bit = 0; bit < (1 << (n)); ++bit)
#define INF 1000000000
//配列 vector<型> 配列名(要素数, 初期値);
//二次元配列 vector<vector<型>> 配列名(要素数縦,vector<int>(要素数横, 初期値))
//配列のサイズ(二次元縦) 配列名.size(), 二次元横 配列名[0].size()
// 1秒間のforループは10^8くらい
//小数点桁数 cout << fixed << setprecision(20) <<
// bit全探索 条件判定 if(bit & (1 << n))

int main() {
  int N;
  cin >> N;
  vector<pair<ll, ll>> x(N);
  vector<pair<ll, ll>> y(N);
  vector<pair<ll, ll>> ans(6);
  vector<pair<ll, ll>> check(6);

  REP(i, N) {
    cin >> x[i].first >> y[i].first;
    x[i].second = i;
    y[i].second = i;
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());

  ans[0].first = abs(x[0].first - x[N - 1].first);
  ans[1].first = abs(x[0].first - x[N - 2].first);
  ans[2].first = abs(x[1].first - x[N - 1].first);
  ans[3].first = abs(y[0].first - y[N - 1].first);
  ans[4].first = abs(y[0].first - y[N - 2].first);
  ans[5].first = abs(y[1].first - y[N - 1].first);

  check[0].first = x[0].second;
  check[1].first = x[0].second;
  check[2].first = x[1].second;
  check[3].first = y[0].second;
  check[4].first = y[0].second;
  check[5].first = y[1].second;

  check[0].second = x[N - 1].second;
  check[1].second = x[N - 2].second;
  check[2].second = x[N - 1].second;
  check[3].second = y[N - 1].second;
  check[4].second = y[N - 2].second;
  check[5].second = y[N - 1].second;

  REP(i, 6) { ans[i].second = i; }

  sort(ans.begin(), ans.end());

  if (check[ans[4].second].first != check[ans[5].second].first ||
      check[ans[4].second].second != check[ans[5].second].second) {
    cout << ans[4].first << endl;
  } else {
    cout << ans[3].first << endl;
  }
}