{-# 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 = maximum $ zipWith (+)
                                 (take (n + 1) $ drop n $ reverse calcSumAs)
                                 (take (n + 1) $ drop n $ calcSumBs)
 where
  ain = VU.imap (\(!i) (!a) -> (a, i)) an
  calc an = (\(_, _, !x) -> x) $ VU.foldl'
    (\(!heap, !s, !acc) (!ai, !i) ->
      let heap'        = S.insert (ai, i) heap
          (s', heap'') = if S.size heap' > n
            then
              let Just ((m, _), heap'') = S.minView heap'
              in  (s + ai - m, heap'')
            else (s + ai, heap')
      in  (heap'', s', s' : acc)
    )
    (S.empty, 0, [0])
    an

  calcSumAs = calc ain
  calcSumBs = calc $ VU.map (\(!ai, !i) -> (-ai, i)) $ VU.reverse ain

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
