Scanf.scanf "%s" (fun s ->
    let n = String.length s in

    let rec loop i cur hist acc =
        if i = n then acc + hist + cur else
            let acc = loop (i + 1) (cur * 10 + int_of_char s.[i] - 48) hist acc in
            if cur = 0 then acc else loop i 0 (hist + cur) acc
    in
    loop 0 0 0 0 |> Printf.printf "%d\n"
)