import Control.Arrow
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.IntMap as IM
main=print.solve.unfoldr(B.readInt.B.dropWhile isSpace)=<<B.getContents
solve(n:as)=maximum$zipWith(-)bs$reverse cs where
  (a1s,(a2s,a3s))=second(splitAt n).splitAt n$as
  bs=f IM.findMin(>)a1s a2s
  cs=f IM.findMax(<)a3s$reverse a2s
f f1 f2 as bs=(s:).snd.mapAccumL(g f1 f2)(s,m)$bs where
  s=sum as
  m=IM.fromList$map(head&&&length).group.sort$as
g f1 f2(s,m)a
  |f2 a b=let t=s-b+a in((t,IM.insertWith(+)a 1.IM.update(\i->if i>1 then Just(i-1) else Nothing)b$m),t)
  |otherwise=((s,m),s)
  where (b,_)=f1 m