import Control.Monad
import qualified Data.Map as M

{-
-- pairing heap
-----------------------------------------------------
data Heap a = Empty | Heap a [(Heap a)] deriving Show

findMin :: Heap a -> a
findMin (Heap h _) = h

merge :: Ord a => Heap a -> Heap a -> Heap a
merge Empty h = h
merge h Empty = h
merge h1@(Heap x hs1) h2@(Heap y hs2)
  | x < y = Heap x (h2:hs1)
  | otherwise = Heap y (h1:hs2)

mergePairs :: Ord a => [Heap a] -> Heap a
mergePairs [] = Empty
mergePairs [h] = h
mergePairs (h1:h2:hs) = merge (merge h1 h2) (mergePairs hs)

insert :: Ord a => a -> Heap a -> Heap a
insert x h = merge (Heap x []) h

deleteMin :: Ord a => Heap a -> Heap a
deleteMin (Heap x hs) = mergePairs hs

fromList :: Ord a => [a] -> Heap a
fromList [] = Empty
fromList (x:xs) = merge (Heap x []) (fromList xs)
-----------------------------------------------------
-}

-- bag
-----------------------------------------------------
type Bag = M.Map Int Int

findMin :: Bag -> Int
findMin bag = fst $ M.findMin bag

findMax :: Bag -> Int
findMax bag = fst $ M.findMax bag

delete :: Int -> Bag -> Bag
delete element bag = M.insertWith (flip (-)) element 1 bag

insert :: Int -> Bag -> Bag
insert element bag = M.insertWith (+) element 1 bag

fromList :: [Int] -> Bag
fromList xs = M.fromList $ zip xs (replicate (length xs) 1)
-----------------------------------------------------

sum_large_n :: Bag -> Int -> Int
sum_large_n _ 0 = 0
sum_large_n bag n = largest + sum_large_n newbag (n - 1)
  where largest = findMax bag
        newbag = delete largest bag

sum_small_n :: Bag -> Int -> Int
sum_small_n _ 0 = 0
sum_small_n bag n = smallest + sum_small_n newbag (n - 1)
  where smallest = findMin bag
        newbag = delete smallest bag


iterate_l :: Int -> [Int] -> Bag -> [Int]
iterate_l _ [] _ = []
iterate_l n (x:xs) bag = ans:iterate_l n xs newbag
  where ans = sum_large_n newbag n
        newbag = insert x bag

iterate_r :: Int -> [Int] -> Bag -> [Int]
iterate_r _ [] _ = []
iterate_r n (x:xs) bag = ans:iterate_r n xs newbag
  where ans = sum_small_n newbag n
        newbag = insert x bag


main = do
  [n] <- map read . words <$> getLine :: IO [Int]
  in_seq <- map read . words <$> getLine :: IO [Int]
  let left_seq = take n in_seq
  let right_seq = drop (2 * n) in_seq
  let mid_seq = take n $ drop n in_seq
  let mid_r_seq = reverse mid_seq

  let left_init = sum left_seq
  let m_l_seq = left_init:iterate_l n mid_seq (fromList left_seq)

  let right_init = sum right_seq
  let m_r_seq = right_init:iterate_r n mid_r_seq (fromList right_seq)

  let ans = minimum (zipWith (\a b -> a - b) m_l_seq (reverse m_r_seq))

  print ans