#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<typename T>
std::ostream & operator<<(std::ostream & Str, vector<T> const & vec) {
    Str << "[";
    for (int i = 0; i < vec.size(); ++i) {
        if (i != 0) cout << ", ";
        cout << vec.at(i);
    }
    Str << "]";
    return Str;
}


void solve(long long N, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C){
    ll ans = 0;
    vector<ll> map(200000, 0);
    rep(j, N) {
        map.at(B.at(C.at(j) - 1)) += 1;
    }
    rep(i, N) {
        ans += map.at(A.at(i));
    }
    cout << ans << endl;
}

int main(){
    long long N;
    std::scanf("%lld", &N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        std::scanf("%lld", &A[i]);
    }
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        std::scanf("%lld", &B[i]);
    }
    std::vector<long long> C(N);
    for(int i = 0 ; i < N ; i++){
        std::scanf("%lld", &C[i]);
    }
    solve(N, std::move(A), std::move(B), std::move(C));
    return 0;
}

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

#define ll long long
#define vl vector<ll>
#define ml map<ll,ll>
#define sl set<ll>
#define vp vector< pair <int,int> >
#define pb push_back

#define asort sort(a,a+n)
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(),v.end())


#define F first
#define S second
#define mod 1000000007

#define mit map<ll,ll>::iterator
#define for0(j,n) for(ll i=j;i<n;i++)
#define for1(j,n) for(ll i=j;i<=n;++i)
#define MA LLONG_MAX
#define MI LLONG_MIN
 
long long power(long long x,ll y)
{
    long long res = 1; 
    x = x % mod;
    while (y > 0) 
    {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1; 
        x = (x * x) % mod;
    }
    return res;
}
 
long modInverse(long long n)
{
    return power(n, mod - 2);
}
long long fac[200001];

long long ncr(long long n, ll r)
{
    if (n < r)
        return 0;
    if (r == 0)
        return 1;
    long long fac[n + 1];
    fac[0] = 1;
    for (int i = 1; i <= n; i++)
        fac[i] = (fac[i - 1] * i) % mod;
 
    return (fac[n] * modInverse(fac[r]) % mod*modInverse(fac[n - r])% mod)% mod;
} 
vector<ll> prime;

void sieve()
{
          vector<bool> primes(10000000000000,true);
          primes[0]=primes[1]=false;
          for(int i=2;i<10000000000000;++i)
           {
                     if(primes[i])
                      {
                                for(int j=i*i;j<10000000000000;j+=i)
                                  primes[j]=false;
                      }
           }
           for(int i=0;i<10000000000000;++i)
             if(primes[i])
             prime.pb(i);
          
}
sl factorization;
void trial_division3(long long n) {
   
    for (int d : {2, 3, 5}) {
        while (n % d == 0) {
            factorization.insert(d);
            n /= d;
        }
    }
    static array<int, 8> increments = {4, 2, 4, 2, 4, 6, 2, 6};
    int i = 0;
    for (long long d = 7; d * d <= n; d += increments[i++]) {
        while (n % d == 0) {
            factorization.insert(d);
            n /= d;
        }
        if (i == 8)
            i = 0;
    }
    if (n > 1)
        factorization.insert(n);
  }

 void solve()
  { 
      ll n;string s;
    cin>>n;
 sl p;
   for(ll i=1;i*i<=n;++i)
   {
             if(n%i==0)
              {
                        p.insert(i);p.insert(n/i);
              }
              
   }
   for(auto it=p.begin();it!=p.end();++it)
     cout<<*it<<endl;
      
      
  }
 
int main()
{
    ll t=1;
     fac[0] = 1;
    for (int i = 1; i <= 200000; i++)
        fac[i] = (fac[i - 1] * i) % mod;
   // cin>>t;

    while(t--)
    {
        solve();
    }

    return 0;
}