coins i sk = if sk + i > 10000000 then [] else sk + i : coins (i + 1) (sk + i) solve _ 0 = 0 solve cs n = 1 + solve cs' n' where cs' = filter (<= n) cs n' = n - last cs' main = readLn >>= print . solve cs where cs = coins 1 0