--- Copyright © 2008 Bart Massey
--- ALL RIGHTS RESERVED
--- [This program is licensed under the "3-clause ('new') BSD License"]
--- Please see the file COPYING in the source
--- distribution of this software for license terms.

import System.Environment
import Data.RLE


rle_data :: Int -> [Int]
rle_data n = concatMap (\k -> replicate k k) [1..n]

main = do
  [arg] <- getArgs
  let a = read arg
  -- a = n * (n + 1) / 2
  -- so solve 0 = n * n + n - 2 * a for n
  -- rounding up, then take only a elements
  let n = ceiling ((sqrt(1 + 8 * fromIntegral a) - 1) / 2)
  (putStrLn . show . length . rle . take a . rle_data) n
