
digitSum n = inner n 0
  where inner 0 rv = rv
        inner m rv = let (q, r) = quotRem m 10
                     in
                       inner q (r + rv)

sums n = [ (k, digitSum k) | k <- [1 .. n]]

sums10000 = sums 10000

filterSums n a b = filter (\(_, x) -> a <= x && x <= b) $ take n sums10000

answer n a b = foldr (\(x, _) y -> x + y) 0
               $ filterSums n a b

main = interact $ (++ "\n")
       . show 
       . (\[x, y, z] -> answer x y z)
       . map read
       . take 3
       . words
       . head
       . lines
       
