import Control.Applicative import Control.Monad import System.IO main :: IO () main = do n_temp <- getLine let n = read n_temp :: Int a_temp <- getLine let a = map read $ words a_temp :: [Int] print $ foldr (\ x -> (retry x +)) 0 a fromdown k n | n == 1 = 1 | n < k^2 = succ n | r == 0 = n + fromdown k d | otherwise = fromdown (succ k) n where (d,r) = divMod n k retry = fromdown 2