import Data.List
import Data.List.Split
main = mapM_ (print . solve . map (map read . words)) . chunksOf 2 . lines =<< getContents
solve = sum . map snd . filter (\(i,_)->i`mod`2==0) . zip [0..] . sort . (!!1)