open Batteries
let rec collect acc sum = function
  | [] -> (sum + acc)
  | (x::xs) ->
      collect (10*acc+x) sum xs +
      collect x (sum+acc) xs

let (h::s) = Scanf.scanf "%s" String.to_list
  |> List.map (fun d -> int_of_char d - 48)
;;

collect h 0 s |> Printf.printf "%d\n"

