///                          BISMILLA HIRRAHMANIR RAHIM
///                              ALLAH IS ALMIGHTY
///                          ALLAH IS MUCH MORE CREATIVE

#include<bits/stdc++.h>
#define faster  ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb              push_back
#define ff              first
#define ss              second
#define mem(a,v)        memset(a, v, sizeof(a))
#define all(a)          (a).begin(), (a).end()
#define rep(i,n)        for(int i = 0; i < (n); ++i)

using namespace std;
using ll =                   int64_t;
using ii=                    pair<ll,ll>;
const double PI =            acos(-1.0);
const int mx =               1e5+5;

int dr[]= {0,-1,0,1,-1,-1,1,1};  /// first 4 are right,up,left,bottom
int dc[]= {1,0,-1,0,1,-1,-1,1};
int kx[]= {-1,-2,-2,-1,1,2,2,1};  /// knight move
int ky[]= {2,1,-1,-2,-2,-1,1,2};

bool valid(int row,int col){
    return (row>=1) && (row<=8) && (col>=1) && (col<=8);
}

ll a[mx],b[mx],su[mx];


void Solve()
{
   ll i,j,x,y,sum=0,ans=0,n,m,k,l=1;
   string dd,s="";cin>>dd;
   for(i=0; i<dd.size(); i++){
      if(dd[i]=='.') break;
      else s+= dd[i];
   }
   cout << s<< "\n";
}


int main()
{
    //faster;
   int TC=1;
   int jj=1;
    //cin >> TC;
    while(TC--) {
         Solve();
    }

    return 0;
}

#ifdef __LOCAL
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>
using namespace std;

#pragma region macros

using str=string;
using ll=long long;
using vl=vector<ll>;
using vc=vector<char>;
using pl=pair<ll,ll>;
using ml=map<ll,ll>;
using sl=set<ll>;
using graph=vector<vector<ll>>;
template<class T> using V=vector<T>;
template<class T,class U> using P=pair<T,U>;

#define rep(i,n) for(ll i=0;i<n;i++)
#define reps(i,n) for(ll i=1;i<n;i++)
#define REP(i,m,n) for(ll i=m;i<n;i++)
#define drep(i,n) for(ll i=n-1;i>=0;i--)
#define fore(n) for(auto&& i:n)
#define fors(n) for(auto&&[i,j]:n)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend();
#define sor(v) sort(all(v))
#define rsor(v) sort(all(v),greater<ll>())
#define rev(v) reverse(all(v))
#define low(v,x) lower_bound(all(v),x)-v.begin()
#define up(v,x) upper_bound(all(v),x)-v.begin()
#define acc(v) accumulate(all(v),0LL)
#define ef(x) emplace_front(x)
#define eb(x) emplace_back(x)
#define pf() pop_front()
#define pb() pop_back()
#define mp(a,b) make_pair(a,b)
#define ceil(a,b) (a+b-1)/b
#define bit(n) (1LL<<n)

#define fi first
#define se second
#define be begin()
#define en end()
#define br break
#define cn continue
#define wh while
#define el else if
#define re return

const ll inf=1LL<<60;
const ll mod=1000000007;
const ll MOD=998244353;
const double pi=3.1415926535;
const double eps=1e-10;
const ll dx[4]={1,0,-1,0};
const ll dy[4]={0,1,0,-1};

void input(){}
void inputs(){}
void output(){}
template<class T,class...U> void input(T& x,U&...y){cin>>x;input(y...);}
template<class...T> void in(T&...x){input(x...);}
template<class T> void inputs(const ll t,T& x){cin>>x[t];}
template<class T,class...U> void inputs(const ll t,T& x,U&...y){cin>>x[t];inputs(t,y...);}
template<class T,class...U> void inputs(T& x,U&...y){rep(t,size(x))inputs(t,x,y...);}
template<class...T> void ins(T&...x){inputs(x...);}
template<class T,class...U> void output(T x,U...y){cout<<x<<"\n";output(y...);}
template<class...T> void out(T...x){output(x...);}
template<class...T> void fin(T...x){out(x...);exit(0);}
template<class T> istream&operator>>(istream& i,V<T>& v){for(T& x:v)i>>x;re i;}
template<class T,class U> istream&operator>>(istream& i,P<T,U>& p){re i>>p.fi>>p.se;}
template<class T> ostream&operator<<(ostream& o,V<T>& v){for(T& x:v)o<<x<<" ";re o;}
template<class T,class U> ostream&operator<<(ostream& o,P<T,U>& p){re o<<p.fi<<" "<<p.se;}

void yn(bool b){fin((b?"Yes":"No"));}
void YN(bool b){fin((b?"YES":"NO"));}
void pos(bool b){fin((b?"POSSIBLE":"IMPOSSIBLE"));}
template<class T> void chmax(T& a,T b){if(a<b)a=b;}
template<class T> void chmin(T& a,T b){if(a>b)a=b;}
template<class T,class U> auto max(T a,U b){re a>b?a:b;}
template<class T,class U> auto min(T a,U b){re a<b?a:b;}
ll qp(ll x,ll n){ll r=1;wh(n>0){if(n&1)r*=x;x*=x;n>>=1;}re r;}
ll mdp(ll x,ll n){ll r=1;wh(n>0){if(n&1)r=r*x%mod;x=x*x%mod;n>>=1;}re r;}
ll MDp(ll x,ll n){ll r=1;wh(n>0){if(n&1)r=r*x%MOD;x=x*x%MOD;n>>=1;}re r;}

struct initialize{
    initialize(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout<<fixed<<setprecision(10);
    }
}init;

#pragma endregion

signed main(){
    ll n; in(n);
    vl a(n),b(n),c(n); in(a,b,c);

    ll ans=0;
    sor(a);
    rep(i,n){
        ll x=b[c[i]-1];
        ll y=low(a,x),z=up(a,x);
        ans+=max(z-y,0);
    }
    out(ans);
}