
/*

 ALLAH IS ALMIGHTY              ******BISMILLAHIR RAHMANIR RAHIM.******              ALLAH IS ALMIGHTY
                                    ```````````````````````````````
                                        AUTHOR: ANISUR RAHAMAN
                                            BSMRSTU(SHIICT)
                                                ID:017


                            ............LET's START OUR JOURNEY.............

*/
#include <bits/stdc++.h>

#define I_O                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

//~~~~~~~~~~~~ Sort Form Of Long~~~~~~~~~~~//
#define ll long long int
#define lls int64_t
#define ld long double
#define db double
#define ull unsigned long long int

//~~~~~~~~~~~~~~Pair~~~~~~~~~~~~~~~~~~//
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<db, db>
#define psi pair<string, int>
#define vi vector<int>
#define vl vector<ll>
#define vd vector<db>
#define vs vector<string>
#define vb vector<bool>
#define vpi vector<pii>
#define vpl vector<pll>
#define vpd vector<pdd>
#define vpsi vector<psi>

//~~~~~~~~~~~~~~Vector~~~~~~~~~~~~~~~~~//
#define pb push_back
#define pf push_front
#define MP make_pair
#define in insert
#define ff first
#define ss second
#define al(v) v.begin(), v.end()
#define alr(v) v.rbegin(), v.rend()
#define srt(v) sort(al(v))
#define srtr(v) sort(al(v), greater<int>());
#define len(x) ((ll)(x).length())
#define sz(x) ((ll)(x).size())
#define rev(v) reverse(al(v))
#define btcnt(n) __builtin_popcount(n)
#define acl(v, n) accumulate(al(v), n)
#define eb emplace_back
#define lb(v, kk) lower_bound(al(v), kk)
#define ub(v, kk) upper_bound(al(v), kk)
#define tpu(str) transform(al(str), str.begin(), ::toupper)
#define tpl(str) transform(al(str), str.begin(), ::tolower)
#define cignr cin.ignore(numeric_limits<streamsize>::max(), '\n');
#define mxv(v) *max_element(al(v))
#define mnv(v) *min_element(al(v))

const int MOD = 1e9 + 7;
const ll INF = 2e18;
const int mxn = 2e9 + 9;
const int mxd = 2e5 + 5;
const int mxa = 1e5 + 5;

//~~~~~~~~~~~~~~~~~~Function~~~~~~~~~~~~~~~~~~~~//
lls gcd(lls a, lls b)
{
    if (b == 0LL)
        return a;
    return gcd(b, a % b);
}

lls lcm(lls a, lls b)
{
    return (a / gcd(a, b) * b);
}

//~~~~~~~~~~~~~~~Loops and Short~~~~~~~~~~~~~~~~//

#define PI acos(-1)
#define Cn continue
#define Br break
#define off return 0
#define N '\n'
#define WT(somthing)     \
    auto az = something; \
    cout << az << N;
#define WTS(something) cout << something << N;
#define rep(i, n) for (lls i = 0; (lls)i < n; i++)
#define repn(i, a, b) for (lls i = (lls)(a); i < (lls)(b); i++)
#define repr(i, a, b) for (lls i = (lls)(a)-1; i >= (lls)(b); i--)
#define test_case() int T; T = 1; while (T--)

using namespace std;

lls maxll(lls x, lls y) { return x > y ? x : y; }
lls minll(lls x, lls y) { return x < y ? x : y; }
// ===================================~~~~~~ SOLUTION STARTS HERE ~~~~~~=================================== //

//int a, b, c, d, e, res = 0, ans = 0, prod = 1, n, m, cnt = 0, k, l, r, s, t, x, y, f, i, j, p;
 
void Run_Case()
{   
    int n;
    cin >> n;
    vi a(n), b(n), c(n);
    rep (i, n) cin >> a[i];
    rep (i, n) cin >> b[i];
    rep (i, n) cin >> c[i];
    vi va;
    map <int, int> ma, mb;
    rep (i, n) {
        ma[b[c[i] - 1]]++;
    }

    ull cnt = 0;
    rep (i, n) {
        if (ma[a[i]]) cnt += ma[a[i]];
    }
    cout << cnt << N;
}

int main()
{
    I_O
    test_case()
    {
        Run_Case();
    }

    off;
}
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll; 
const int N=5e5+10;
int c[N];
vector<ll>p[N]; 
ll min1(ll a,ll b)
{
	if(a<b) return a;
	else return b;
}
ll lb(ll x)
{
	return x&(-x);
}
void add(int x,int d) {for(;x<N;x+=lb(x))c[x]+=d;}
int geti(ll x)
{
	int r=0;
	for(;x;x-=lb(x))
	r+=c[x];
	return r;
}
void sset(int x)
{
	if(geti(x)-geti(x-1)==0)
	add(x,1);
}
void reset(int x)
{
	if(geti(x)-geti(x-1)==1)
	add(x,-1);
 } 
 //单点修改 就是变得能走还是不能走 
int main()
{
	ll n,m,k;
	cin>>n>>m>>k;
    ll x, y, mx = n + 1, my = m + 1;
    for(ll i=1;i<=k;i++)
    {
    	cin>>x>>y;
    	p[x].push_back(y);
    	if(x==1) my=min1(y,my);
    	if(y==1) mx=min1(x,mx);
	}
	for(ll i=1;i<=mx;i++) sort(p[i].begin(),p[i].end());
// cout<<endl<<"mx="<<mx<<' '<<"my="<<my<<endl;
    for(ll i=1;i<=m;i++) sset(i);
    for(ll y=my;y<=m;y++) reset(y);

    ll ans = 0;
  if(!p[1].empty())
  {  
  ans+=p[1][0]-1;
  //cout<<' '<<ans<<' '<<endl; 
  } 
  else ans+=m;
//cout<<endl;
  //cout<<ans<<endl ;
    for(ll x=2;x<=n;x++)
    {
        for (ll y: p[x]) reset(y);
        if (x < mx) {
            if (p[x].empty()) {
                ans += m;
                //这一行都可以走 
    //         cout<<x<<' '<<ans<<endl;
            }
			 else {
                ans += p[x][0] - 1;
      //         cout<<x<<' '<<ans<<endl;
                ans += geti(m)-geti(p[x][0]);
        //     cout<<x<<' '<<ans<<endl;
            }
        }
		//上面的都没问题
		//reset的位置都能存到下一个 
		else {
			if(p[1].empty())
            ans += geti(m);
            else ans+=geti(p[1][0]-1);
          // cout<<x<<' '<<ans<<endl;
        }

    }
 cout<<ans;
 return 0;
}

	
	
	
	
	
	
	
