let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let as_ = Array.init (3 * n) (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  Array.init n (fun i -> i + n)
  |> Array.map (fun m ->
      let prelude = Array.sub as_ 0 m in
      let postludium = Array.sub as_ m (3 * n - m) in
      Array.sort (fun a b -> compare b a) prelude;
      Array.sort compare postludium;
      Array.fold_left ( + ) 0 (Array.sub prelude 0 n) - Array.fold_left ( + ) 0 (Array.sub postludium 0 n))
  |> Array.fold_left max min_int
  |> Printf.printf "%d\n"
