import Data.Int (Int64) import Data.List (unfoldr) computeMax :: Integral a => a -> a computeMax n = skill - noSkill where f x = if x == 0 then Nothing else Just (x, div x 2) noSkill = sum $ unfoldr f n skill = 2 * n main :: IO () main = print . computeMax =<< (readLn :: IO Int64)