-- noch nicht fertig

import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.List (sort, group)
import Data.Maybe (fromJust, isNothing)
import Data.Bool (bool)

main :: IO ()
main = do
  let
    unsafeNext :: PH (Entry Int [Int]) -> (Int, PH (Entry Int [Int]))
    unsafeNext = f . fromJust . viewMinPH
      where
        f :: (Entry Int [Int], PH (Entry Int [Int])) -> (Int, PH (Entry Int [Int]))
        f (Entry x (x' : xs), h) = (x, insertPH (Entry x' xs) h)
    unsafeDropWhile :: (Int -> Bool) -> PH (Entry Int [Int]) -> PH (Entry Int [Int])
    unsafeDropWhile p = f
      where
        f :: PH (Entry Int [Int]) -> PH (Entry Int [Int])
        f h | p x       = f h'
            | otherwise = h
          where
            (x, h') = unsafeNext h :: (Int, PH (Entry Int [Int]))
    f :: [(Int, Int)] -> (Int, PH (Entry Int [Int]))
    f = foldl step (0, emptyPH)
      where
        step :: (Int, PH (Entry Int [Int])) -> (Int, Int) -> (Int, PH (Entry Int [Int]))
        step (_, h) (x, l) | isEmptyPH h  = (bool l 0 (l == 1), insertPH (Entry (2 * x) (map (x *) [3..])) h)
        step (k, h) (x, l) | x < y     = (k + bool l 0 (l == 1), insertPH (Entry (2 * x) (map (x *) [3..])) h')
                           | otherwise = (k + l, h'')
          where
            h' = unsafeDropWhile (< x) h :: PH (Entry Int [Int])
            (y, h'') = unsafeNext h' :: (Int, PH (Entry Int [Int]))
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  as <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  print . (n -) . fst . f . map ((,) <$> head <*> length) . group . sort $ as

data PH' a = PH' a [PH' a]

type PH a = Maybe (PH' a)

data Entry a b = Entry a b

instance Eq a => Eq (Entry a b)
  where
    Entry x _ == Entry y _ = x == y

instance Ord a => Ord (Entry a b)
  where
    Entry x _ <= Entry y _ = x <= y

emptyPH :: PH a
emptyPH = Nothing
{-# INLINE emptyPH #-}

isEmptyPH :: PH a -> Bool
isEmptyPH = isNothing
{-# INLINE isEmptyPH #-}

minPH :: PH a -> Maybe a
minPH = fmap minPH'
  where
    -- minPH' :: PH' a -> a
    minPH' (PH' x _) = x
{-# INLINE minPH #-}

singletonPH' :: a -> PH' a
singletonPH' = flip PH' []
{-# INLINE singletonPH' #-}

singletonPH :: a -> PH a
singletonPH = Just . singletonPH'
{-# INLINE singletonPH #-}

mergePH' :: Ord a => PH' a -> PH' a -> PH' a
mergePH' xs@(PH' x xss) ys@(PH' y yss) | y < x     = PH' y (xs : yss)
                                       | otherwise = PH' x (ys : xss)
{-# INLINE mergePH' #-}

mergePH :: Ord a => PH a -> PH a -> PH a
mergePH Nothing v = v
mergePH u Nothing = u
mergePH (Just xs) (Just ys) = Just $ mergePH' xs ys
{-# INLINE mergePH #-}

insertPH :: Ord a => a -> PH a -> PH a
insertPH = mergePH . singletonPH
{-# INLINE insertPH #-}

viewMinPH :: Ord a => PH a -> Maybe (a, PH a)
viewMinPH = fmap viewMinPH'
  where
    -- viewMinPH' :: Ord a => PH' a -> (a, Maybe (PH' a))
    viewMinPH' = next
      where
        next (PH' x xss) = (x, merges xss)
        merges = uncurry mergePH . foldl step (Nothing, Nothing)
          where
            step = uncurry . flip $ step'
              where
                step' Nothing    u ys = (u, Just ys)
                step' (Just ys') u ys = (mergePH u v, Nothing)
                  where
                    v = Just $ mergePH' ys' ys
{-# INLINE viewMinPH #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}
