import Data.List

main = do
    n <- readLn :: IO Int
    v <- map read . words <$> getLine :: IO [Int]
    let evens = getEvenIndex v
        odds = getOddIndex v
    print $ if evens == odds then length evens else diff evens odds

getOddIndex :: [a] -> [a]
getOddIndex = getOddIndex' 1
    where
        getOddIndex' _ [] = []
        getOddIndex' n (x:xs)
          | odd n = x : getOddIndex' (n+1) xs
          | otherwise = getOddIndex' (n+1) xs

getEvenIndex :: [a] -> [a]
getEvenIndex = getEvenIndex' 1
    where
        getEvenIndex' _ [] = []
        getEvenIndex' n (x:xs)
          | even n = x : getEvenIndex' (n+1) xs
          | otherwise = getEvenIndex' (n+1) xs

diff :: Eq a => [a] -> [a] -> Int
diff xs ys = diff' xs + diff' ys
    where
        diff' = sum . init . sort . map length . group