import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.Map as Map
import Debug.Trace

main = do
    n <- readLn :: IO Int
    temp <- map read . words <$> getLine :: IO [Int]
    let ns =  reverse . sort $ temp
    -- print $ ns
    -- print $ group ns
    let inputs = map (\x -> let val = x !! 0 in (val, length x)) $ group ns
    let m = Map.fromList inputs
    -- print $ m
    print $ foldl greedyCnt (0,m) $ nub ns

greedyCnt :: (Int, Map.Map Int Int) -> Int -> (Int, Map.Map Int Int)
greedyCnt (n,m) val = case (Map.lookup pair m) of 
    -- Just x -> trace ("value " ++  show pair ++ " has Just x : " ++ show x ++ " at " ++ show val) $ (n+x, m)
    Just numOfPair -> if (numOfPair - numOfVal) >= 0 then (n+numOfVal, Map.insert pair (numOfPair - numOfVal) $ Map.delete pair m) else  (n+numOfPair, Map.delete pair m)
    Nothing -> (n,m)
    where 
        numOfVal = fromJust $ Map.lookup val m
        pair = getPairNum val 0

getPairNum :: Int -> Int -> Int
getPairNum val n = if val >= 2^n then getPairNum val (n+1) else 2^n - val

-- traceはおそらくその文全体が式として評価されたときに動く
-- 問題としては，最適状態が達成されたときの状況を考えるのが重要

