{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad
import Control.Monad.Fix
import Data.Int
import Data.Foldable
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Set as S
import qualified Data.ByteString.Char8 as B
import Debug.Trace

solve :: Int -> VU.Vector Int -> Int
solve !n !an = (\(_, _, _, _, x) -> x) $ foldl'
  (\(!minh, !maxh, !sumA, !sumB, !acc) (!i) ->
    let
      ai    = an VU.! (n + i)

      minh' = S.insert (ai, i) minh
      (sumA', minh'') =
        let Just ((m, _), minh'') = S.minView minh' in (sumA + ai - m, minh'')

      idx   = S.findIndex (ai, i) maxh
      maxh' = S.delete (ai, i) maxh
      sumB' =
        if idx < n then sumB - ai + fst (S.elemAt (n - 1) maxh') else sumB
    in
      (minh'', maxh', sumA', sumB', max acc (sumA' - sumB'))
  )
  (minHeap, maxHeap, sumA, sumB, sumA - sumB)
  [0 .. n - 1]
 where
  minHeap =
    S.fromList $ VU.toList $ VU.imap (\(!i) (!a) -> (a, i)) $ VU.take n an
  maxHeap =
    S.fromList $ VU.toList $ VU.imap (\(!i) (!a) -> (a, i)) $ VU.drop n an
  sumA = VU.sum (VU.take n an)
  sumB = VU.sum (VU.drop n an)
    - foldl' (\(!acc) (!y, _) -> acc + y) 0 (drop n $ S.toList maxHeap)

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  n  <- (\vec -> (vec VU.! 0)) . VU.unfoldrN 1 readInt <$> B.getLine
  an <- VU.unfoldrN (3 * n) readInt <$> B.getLine
  print $ solve n an
