#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstdint>
#include <cstdlib>
#include <cstring>

namespace FastIO{static constexpr size_t E=(1<<17);static constexpr size_t T=23
,A=334;static constexpr char O[]="%.16f";FILE*e=stdin,*t=stdout;char a[E|1],*o,
*i;char n[E|1],*s,*h;inline size_t r(){size_t f=fread(a,1,E,e);*(i=a+f)=0;o=a;
return f;}inline size_t d(){std::ptrdiff_t f=i-o;if(a+f>=o){return 0;}memcpy(a,
o,f);size_t b=fread(a+f,1,E-f,e);*(i=a+(f+=b))=0;o=a;return b;}inline void l(d\
ouble&f){if(*o==0&&r()){f=0;return;}char*p;f=strtod(o,&p);while(p==o){if(!r()){
f=0;return;}f=strtod(o,&p);}if(p==i&&d()){f=strtod(a,&p);}o=p;}inline void l(c\
har&f){if(*o==0){r();}if((f=*o)!=0){++o;}}inline void l(char*f){while(1){if(*o
==0){if(!r()){*f=0;return;}}if(*o<=' '){++o;}else{break;}}for(char*p=o;;++o){if
(*o==0){memcpy(f,p,o-p);f+=o-p;if(!r()){*f=0;return;}p=o;}else if(*o<=' '){mem\
cpy(f,p,o-p);f+=o-p;*f=0;return;}}}template<class N>inline void l(N&f,typename
std::enable_if<std::is_signed<N>::value>::type*g=0){f=0;int y=0;if(o+T>=i){d();
}while(*o<'-'){++o;}if(*o=='-'){y=1;++o;}do{f=f*10+*o-'0';}while(*++o>='0');++o
;if(y){f=-f;}}template<class N>inline void l(N&f,typename std::enable_if<!std::
is_signed<N>::value>::type*g=0){f=0;if(o+T>=i){d();}while(*o<'+'){++o;}do{f=f*
10+*o-'0';}while(*++o>='0');++o;}inline void c(){fwrite(n,1,s-n,t);s=n;}inline
void u(char f){if(s+1>=h)c();*s++=f;}inline void u(const char*f){size_t g=strl\
en(f);if(s+g>=h){c();}if(s+g>=h){fwrite(f,1,g,t);}else{memcpy(s,f,g);s+=g;}}te\
mplate<size_t N>inline void u(const char(&f)[N]){if(s+N>=h){c();}if(s+N>=h){fw\
rite(f,1,N,t);}else{memcpy(s,f,N);s+=N;}}inline void u(double f){char g[A];siz\
e_t y=snprintf(g,A,O,f);char*p=s+y;if(p>=h){c();p=n+y;}memcpy(s,g,y);s=p;}temp\
late<class N>inline void u(N f,typename std::enable_if<std::is_signed<N>::value
>::type*g=0){if(s+T>=h){c();}if(f==0){*s++='0';return;}char v[T],*k=v+T,*j=k;if
(f<0){*s++='-';f=-f;}do{*--k=f%10+'0';f/=10;}while(f);memcpy(s,k,j-k);s+=j-k;}
template<class N>inline void u(N w,typename std::enable_if<!std::is_signed<N>::
value>::type*f=0){if(s+T>=h){c();}if(w==0){*s++='0';return;}char b[T],*v=b+T,*k
=v;do{*--v=w%10+'0';w/=10;}while(w);memcpy(s,v,k-v);s+=k-v;}struct Scanner{Sca\
nner(){o=a;i=a+E;r();}template<class Z>inline void scan(Z&&z){l(z);}template<c\
lass Z,class...Q>inline void scan(Z&&z,Q&&...q){l(z);scan(q...);}};struct Prin\
ter{Printer(){s=n;h=n+E;}~Printer(){c();}template<class Z>inline void print(Z z
){u(z);}template<class Z,class...Q>inline void print(Z z,Q...q){u(z);print(q...
);}template<class Z>inline void println(Z z){u(z);u('\n');}};}

template <class RandomIt>
void rxsort(RandomIt first, RandomIt last) {
  using IntType = typename RandomIt::value_type;
  intmax_t cur_shift=0, max_exp=sizeof(IntType);
  std::vector<IntType> work(last-first);
  for (int i=0; i<max_exp; ++i) {
    size_t num[256]={};

    for (RandomIt it=first; it<last; ++it)
      ++num[((*it)>>cur_shift)&255];

    {
      size_t tmp=0;
      for (int j=0; j<256; ++j)
        std::swap(tmp, num[j]+=tmp);
    }

    for (RandomIt it=first; it<last; ++it)
      work[num[((*it)>>cur_shift)&255]++] = *it;

    {
      size_t j=0;
      for (RandomIt it=first; it<last; ++it)
        *it = work[j++];
    }

    cur_shift += 8;
  }

  if (!std::is_signed<IntType>::value) return;

  RandomIt mid=last;
  for (RandomIt it=last; --it>=first;)
    if (*it >= 0) {
      mid = ++it;
      break;
    }

  if (mid == last)
    return;

  std::copy(first, mid, work.begin()+(last-mid));
  std::copy(mid, last, work.begin());
  std::copy(work.begin(), work.end(), first);
}

FastIO::Scanner cin;

int main() {
  size_t N;
  cin.scan(N);

  std::vector<int> X[3];
  for (std::vector<int> &A: X) {
    A.resize(N);
    for (size_t i=0; i<N; ++i) {
      cin.scan(A[i]);
    }

    rxsort(A.begin(), A.end());
  }

  std::vector<intmax_t> Y[2];
  for (size_t i=0; i<2; ++i) {
    Y[i].assign(N, N);
    for (size_t j=0, k=0; j<N; ++j) {
      while (k < N && X[i][j] >= X[i+1][k]) ++k;
      if (k == N) break;
      Y[i][j] = k;
    }
  }

  for (size_t i=0; i<N; ++i)
    Y[1][i] = N - Y[1][i];

  for (size_t i=N-1; i>0; --i)
    Y[1][i-1] += Y[1][i];

  intmax_t res=0;
  for (size_t i=0; i<N; ++i) {
    size_t j=Y[0][i];
    if (j < N)
      res += Y[1][j];
  }

  printf("%jd\n", res);
  return 0;
}


Measured memory_bytes: 3448