{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns, CPP, FlexibleInstances, KindSignatures     #-}
{-# LANGUAGE LambdaCase, MagicHash, MultiParamTypeClasses, MultiWayIf #-}
{-# LANGUAGE OverloadedStrings, ScopedTypeVariables, TupleSections    #-}
{-# LANGUAGE TypeFamilies, ViewPatterns                               #-}

import           Control.Applicative
import           Control.Exception
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString             as B
import qualified Data.ByteString.Builder     as B
import qualified Data.ByteString.Char8       as C
import qualified Data.ByteString.Internal    as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import qualified Data.Foldable               as F
import           Data.Function
import           Data.Functor.Identity
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import qualified Data.List                   as L
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           GHC.Exts
import qualified System.IO                   as IO
import           Unsafe.Coerce

main :: IO ()
main = do
    [n,m] <- map read.words <$> getLine :: IO [Int]
    xs <- U.unfoldrN n (runStateT int) <$> C.getLine
    print $ solve n m xs

solve :: Int -> Int -> U.Vector Int -> Int
solve n m xs = runST $ do
    h <- buildMaxBinaryHeap xs
    rep m $ \_ -> do
        modifyTopBH h (`quot` 2)
    vec <- freezeInternalBinaryHeapBH h
    return $ U.sum vec

-------------------------------------------------------------------------------
-- Utils
-------------------------------------------------------------------------------
rep :: Monad m => Int -> (Int -> m ()) -> m ()
rep !n = U.forM_ $ U.generate n id
{-# INLINE rep #-}
rev :: Monad m => Int -> (Int -> m ()) -> m ()
rev !n = U.forM_ $ U.iterateN n (subtract 1) (n - 1)
{-# INLINE rev #-}
infixl 8 `shiftRL`, `unsafeShiftRL`
shiftRL = unsafeShiftRL
{-# INLINE shiftRL #-}
unsafeShiftRL (I# x#) (I# i#) = I# (uncheckedIShiftRL# x# i#)
{-# INLINE unsafeShiftRL #-}
type Parser a = StateT C.ByteString Maybe a
runParser :: Parser a -> C.ByteString -> Maybe (a, C.ByteString)
runParser = runStateT
{-# INLINE runParser #-}
int :: Parser Int
int = coerce $ C.readInt . C.dropWhile isSpace
{-# INLINE int #-}
int1 :: Parser Int
int1 = fmap (subtract 1) int
{-# INLINE int1 #-}
char :: Parser Char
char = coerce C.uncons
{-# INLINE char #-}
byte :: Parser Word8
byte = coerce B.uncons
{-# INLINE byte #-}
-------------------------------------------------------------------------------
-- Data.Heap.Binary
-------------------------------------------------------------------------------
data BinaryHeap (f :: * -> *) s a = BinaryHeap (a -> f a) !(UM.MVector s Int) !(UM.MVector s a)
type MinBinaryHeap s a = BinaryHeap Identity s a
type MaxBinaryHeap s a = BinaryHeap Down s a
class OrdVia f a where { compareVia :: (a -> f a) -> a -> a -> Ordering}
instance (Ord a) => OrdVia Identity a where { compareVia _ = coerce (compare :: Identity a -> Identity a -> Ordering); {-# INLINE compareVia #-}}
instance (Ord a) => OrdVia Down a where { compareVia _ = coerce (compare :: Down a -> Down a -> Ordering); {-# INLINE compareVia #-}}
newBinaryHeap :: (PrimMonad m, U.Unbox a) => Int -> (a -> f a) -> m (BinaryHeap f (PrimState m) a)
newBinaryHeap n prio = BinaryHeap prio <$> UM.replicate 1 0 <*> UM.unsafeNew n
getBinaryHeapSize :: (PrimMonad m) => BinaryHeap f (PrimState m) a -> m Int
getBinaryHeapSize (BinaryHeap _ vars _) = UM.unsafeRead vars 0
{-# INLINE getBinaryHeapSize #-}
siftUpBy :: (PrimMonad m, U.Unbox a) => (a -> a -> Ordering) -> Int -> UM.MVector (PrimState m) a -> m ()
siftUpBy cmp k vec = do { x <- UM.unsafeRead vec k; flip fix k $ \ loop !i -> if i > 0 then do { let { !parent = (i - 1) `unsafeShiftR` 1}; p <- UM.unsafeRead vec parent; case cmp p x of { GT -> do { UM.unsafeWrite vec i p; loop parent}; _ -> UM.unsafeWrite vec i x}} else UM.unsafeWrite vec 0 x}
{-# INLINE siftUpBy #-}
siftDownBy :: (PrimMonad m, U.Unbox a) => (a -> a -> Ordering) -> Int -> UM.MVector (PrimState m) a -> m ()
siftDownBy cmp k vec = do { x <- UM.unsafeRead vec k; let { !n = UM.length vec}; flip fix k $ \ loop !i -> do { let { l = unsafeShiftL i 1 .|. 1}; let { r = l + 1}; if n <= l then UM.unsafeWrite vec i x else do { vl <- UM.unsafeRead vec l; if r < n then do { vr <- UM.unsafeRead vec r; case cmp vr vl of { LT -> case cmp x vr of { GT -> UM.unsafeWrite vec i vr >> loop r; _ -> UM.unsafeWrite vec i x}; _ -> case cmp x vl of { GT -> UM.unsafeWrite vec i vl >> loop l; _ -> UM.unsafeWrite vec i x}}} else case cmp x vl of { GT -> UM.unsafeWrite vec i vl >> loop l; _ -> UM.unsafeWrite vec i x}}}}
{-# INLINE siftDownBy #-}
heapifyBy :: (PrimMonad m, U.Unbox a) => (a -> a -> Ordering) -> UM.MVector (PrimState m) a -> m ()
heapifyBy cmp vec = do { rev (UM.length vec `quot` 2) $ \ i -> do { siftDownBy cmp i vec}}
{-# INLINE heapifyBy #-}
buildBinaryHeapVia :: (PrimMonad m, U.Unbox a, OrdVia f a) => (a -> f a) -> U.Vector a -> m (BinaryHeap f (PrimState m) a)
buildBinaryHeapVia ~f vec = do { vars <- UM.replicate 1 $ U.length vec; mvec <- U.unsafeThaw vec; heapifyBy (compareVia f) mvec; return $! BinaryHeap f vars mvec}
{-# INLINE buildBinaryHeapVia #-}
buildMinBinaryHeap :: (PrimMonad m, U.Unbox a, Ord a) => U.Vector a -> m (BinaryHeap Identity (PrimState m) a)
buildMinBinaryHeap = buildBinaryHeapVia Identity
{-# INLINE buildMinBinaryHeap #-}
buildMaxBinaryHeap :: (PrimMonad m, U.Unbox a, Ord a) => U.Vector a -> m (BinaryHeap Down (PrimState m) a)
buildMaxBinaryHeap = buildBinaryHeapVia Down
{-# INLINE buildMaxBinaryHeap #-}
unsafeViewBH :: (PrimMonad m, U.Unbox a) => BinaryHeap f (PrimState m) a -> m a
unsafeViewBH (BinaryHeap _ _ vec) = UM.unsafeRead vec 0
{-# INLINE unsafeViewBH #-}
viewBH :: (PrimMonad m, U.Unbox a) => BinaryHeap f (PrimState m) a -> m (Maybe a)
viewBH bh = do { size <- getBinaryHeapSize bh; if size > 0 then Just <$!> unsafeViewBH bh else return $! Nothing}
{-# INLINE viewBH #-}
insertBH :: (PrimMonad m, U.Unbox a, OrdVia f a) => a -> BinaryHeap f (PrimState m) a -> m ()
insertBH x bh@(BinaryHeap prio vars vec) = do { size <- getBinaryHeapSize bh; UM.unsafeWrite vars 0 (size + 1); UM.unsafeWrite vec size x; siftUpBy (compareVia prio) size vec}
{-# INLINE insertBH #-}
unsafeDeleteBH :: (PrimMonad m, U.Unbox a, OrdVia f a) => BinaryHeap f (PrimState m) a -> m ()
unsafeDeleteBH bh@(BinaryHeap prio vars vec) = do { size <- getBinaryHeapSize bh; UM.unsafeWrite vars 0 $ size - 1; UM.unsafeSwap vec 0 (size - 1); siftDownBy (compareVia prio) 0 (UM.unsafeTake (size - 1) vec)}
{-# INLINE unsafeDeleteBH #-}
modifyTopBH :: (PrimMonad m, U.Unbox a, OrdVia f a) => BinaryHeap f (PrimState m) a -> (a -> a) -> m ()
modifyTopBH bh@(BinaryHeap prio _ vec) f = do { UM.unsafeModify vec f 0; size <- getBinaryHeapSize bh; siftDownBy (compareVia prio) 0 (UM.unsafeTake size vec)}
{-# INLINE modifyTopBH #-}
deleteFindTopBH :: (PrimMonad m, U.Unbox a, Ord a) => MinBinaryHeap (PrimState m) a -> m (Maybe a)
deleteFindTopBH bh@(BinaryHeap _ _ vec) = do { size <- getBinaryHeapSize bh; if size > 0 then Just <$!> unsafeViewBH bh <* unsafeDeleteBH bh else return $! Nothing}
{-# INLINE deleteFindTopBH #-}
clearBH :: (PrimMonad m) => BinaryHeap f (PrimState m) a -> m ()
clearBH (BinaryHeap _ vars _) = UM.unsafeWrite vars 0 0
freezeInternalBinaryHeapBH :: (PrimMonad m, U.Unbox a) => BinaryHeap f (PrimState m) a -> m (U.Vector a)
freezeInternalBinaryHeapBH bh@(BinaryHeap _ _ vec) = do { size <- getBinaryHeapSize bh; U.unsafeFreeze (UM.unsafeTake size vec)}


Measured memory_bytes: 4988