module Main where

import           Debug.Trace
import qualified Data.Vector.Unboxed           as VU
import           Data.List
import qualified Data.ByteString               as BS
import qualified Data.ByteString.Char8         as BSC8
import           Data.Char


getVUIntFromInputLineAtBSC8 :: IO (VU.Vector Int)
getVUIntFromInputLineAtBSC8 =
    VU.unfoldr (BSC8.readInt . BSC8.dropWhile isSpace) <$> BSC8.getLine
getListIntFromInputLineAtBSC8 =
    unfoldr (BSC8.readInt . BSC8.dropWhile isSpace) <$> BSC8.getLine
main :: IO ()
main = do
    [aX, aY, aA, aB, aC] <- getListIntFromInputLineAtBSC8
    aP                   <- getVUIntFromInputLineAtBSC8
    aQ                   <- getVUIntFromInputLineAtBSC8
    aR                   <- getVUIntFromInputLineAtBSC8

    putStrLn $ show
        (sumApple
            (VU.fromList (reverse  (sortConved (VU.toList aP) aX)))
            (VU.fromList (reverse (sortConved (VU.toList aQ) aY)))
            (VU.fromList (reverse (sortConved (VU.toList aR) (aX + aY))))
            aX
            aY
            0
        )
            

sortConved :: [Int] -> Int -> [Int]
sortConved []       _ = []
sortConved (x : []) 1 = [x]
sortConved (x : xs) c = if lgteq == c
    then (sortConved gteq (c))
    else if lgteq > c
        then (sortConved gteq c)
        else (sortConved lt (c - lgteq)) ++ [x] ++ (sortConved gteq lgteq)
  where
    lt    = filter (\y -> y <= x) xs
    gteq  = filter (\y -> y > x) xs
    lgteq = length gteq

sortMerged :: [(Int, Int)] -> [(Int, Int)]
sortMerged []       = []
sortMerged (x : xs) = (sortMerged lt) ++ [x] ++ (sortMerged gteq)
  where
    lt   = filter (\y -> (fst y) <= (fst x)) xs
    gteq = filter (\y -> (fst y) > (fst x)) xs



sumApple :: VU.Vector Int -> VU.Vector Int -> VU.Vector Int -> Int -> Int -> Int -> Int
sumApple reds greens nils tX tY tZ 
    |(tX + tY) == tZ = 0
    |otherwise =
        if (maxNum == red) && (tX > 0)
            then red + (sumApple (VU.tail reds) greens nils (tX-1) tY tZ)
            else if ((max green nil) == green) && (tY >0)
                then green + (sumApple reds (VU.tail greens) nils tX (tY-1) tZ)
                else nil + (sumApple reds greens (VU.tail nils) tX tY (tZ+1))
    
    where red = if((VU.length reds)>0) then VU.head reds else 0
          green = if((VU.length greens)>0) then VU.head greens else 0
          nil = if((VU.length nils)>0) then VU.head nils else 0
          maxNum = max red (max green nil)