integer(16) N
integer(16),allocatable,dimension(:)::A,B,C,D
integer(16) ans,i,j,k
read*,N
allocate(A(N),B(N),C(N),D(N))
read*,A
read*,B
read*,C
call heapsort(n,a)
call heapsort(n,b)
call heapsort(n,c)

D=0
j=1
do i = 1, n
   do while (j <= n .and. a(j) < b(i))
      j = j + 1
   end do
   D(i) = j - 1
end do
ans=0
k=0
j=1
do i = 1, n
   do while (j <= n .and. b(j) < c(i))
      k = k + D(j)
      j = j + 1
   enddo
   ans = ans + K
enddo

print"(i0)",ans

contains

subroutine heapsort(n,array)
  implicit none
  integer(16),intent(in) :: n
  integer(16),intent(inout) :: array(1:n)
  integer(16)::i,k,j,l
  integer(16):: t

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsort

end