
import Control.Monad
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Data.Text (Text)

data Problem = Problem {
  n :: Int,
  as :: [Int],
  bs :: [Int],
  cs :: [Int]
  }
  
getInput = do
  res@[n, as, bs, cs] <- replicateM 4 T.getLine
  return res

parse :: [Text] -> Problem 
parse [n, as, bs, cs] =
  Problem (read $ T.unpack  n) (parseList as) (parseList bs) (parseList cs)
  where
    parseList :: Read b => Text -> [b]
    parseList txt =
      let
        bits =  T.splitOn (T.pack " ") txt
      in 
        map (read . T.unpack) bits

solutions problem = do
  -- we want a top, middle, bottom
  -- bot > middle > top
  c <- cs problem
  b <- bs problem
  guard (c > b)
  a <- as problem
  guard (b > a)
  return (a,b,c)   

countSolutions :: Problem -> Int
countSolutions problem =
  length $ solutions problem

main = do
  problem <- parse <$> getInput
  print $ countSolutions problem


