Scanf.scanf "%d %d %d %d %d" (fun x y a b c ->
    let p = Array.init a (fun _ -> Scanf.scanf " %d" (fun i -> i)) in
    let q = Array.init b (fun _ -> Scanf.scanf " %d" (fun i -> i)) in
    let r = Array.init c (fun _ -> Scanf.scanf " %d" (fun i -> i)) in
    Array.sort (fun a b -> compare b a) p;
    Array.sort (fun a b -> compare b a) q;
    Array.sort (fun a b -> compare b a) r;

    let pq = Array.make (x + y) 0 in
    for i = 0 to x - 1 do
        pq.(i) <- p.(i)
    done;
    for i = 0 to y - 1 do
        pq.(i + x) <- q.(i)
    done;
    Array.sort (fun a b -> compare b a) pq;

    let pqacc = Array.make (x + y) 0 in
    pqacc.(0) <- pq.(0);
    for i = 1 to x + y - 1 do
        pqacc.(i) <- pqacc.(i - 1) + pq.(i)
    done;

    let racc = Array.make c 0 in
    racc.(0) <- r.(0);
    for i = 1 to c - 1 do
        racc.(i) <- racc.(i - 1) + r.(i)
    done;

    let rec loop i acc =
        if i > c || x + y - 1 < i then acc else
            loop (i + 1) (max acc (racc.(i - 1) + pqacc.(x + y - 1 - i)))
    in
    loop 1 pqacc.(x + y - 1) |> Printf.printf "%d\n"
)
