{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

bisectRight :: Ord a => (Int -> a) -> a -> Int -> Int -> Int
bisectRight f x lo hi
  | lo >= hi  = lo
  | x < f mid = bisectRight f x lo mid
  | otherwise = bisectRight f x (mid+1) hi
  where
    mid = lo + (hi - lo) `div` 2

bisectLeft :: Ord a => (Int -> a) -> a -> Int -> Int -> Int
bisectLeft f x lo hi
  | lo >= hi  = lo
  | f mid < x = bisectLeft f x (mid+1) hi
  | otherwise = bisectLeft f x lo mid
  where
    mid = lo + (hi - lo) `div` 2

-- quickSortVec from https://gist.github.com/kazu-yamamoto/3051375
quickSortList :: (Ord a, VM.Unbox a) => [a] -> [a]
quickSortList xs = ST.runST $ do
    arr <- V.thaw $ V.fromList xs
    let beg = 0
        end = VM.length arr - 1
    quickSortVec beg end arr
    V.toList <$> V.freeze arr

quickSortVec l u arr
  | l >= u    = return ()
  | otherwise = do
      VM.unsafeSwap arr l ((u+l)`div`2)
      t <- VM.unsafeRead arr l
      let i = l
          j = u + 1
      nj <- loopVec t u i j arr
      VM.unsafeSwap arr l nj
      quickSortVec l (nj-1) arr
      quickSortVec (nj+1) u arr

loopVec !t !u !i !j arr = do
  ni <- doWhile i (+1)         (< t)
  nj <- doWhile j (subtract 1) (> t)
  if ni > nj
    then return nj
    else do VM.unsafeSwap arr ni nj
            loopVec t u ni nj arr
              where
                {-# INLINE doWhile #-}
                doWhile k op p
                  | nk > u    = return nk
                  | otherwise = do
                      x <- VM.unsafeRead arr nk
                      if p x then
                        doWhile nk op p
                        else
                        return nk
                        where
                          nk = op k


main = do
  n <- getInt
  as <- getIntVec n
  bs <- getIntVec n
  cs <- getIntVec n

  as' <- V.thaw as
  cs' <- V.thaw cs

  quickSortVec 0 (n-1) as'
  quickSortVec 0 (n-1) cs'

  as'' <- V.freeze as'
  cs'' <- V.freeze cs'

  let numCombByB b = let i = bisectLeft (as'' V.!) b 0 n
                         j = bisectRight (cs'' V.!) b 0 n
                         res = i * (n - j)
                     in res

      solve i res | i == n = res
                  | otherwise = let b = bs V.! i
                                    x = numCombByB b
                                    res' = res + x
                                in solve (i + 1) res'

      ans = solve 0 0

  print ans

Measured memory_bytes: 16012