let () =
  let rec loop () =
    let x = read_line ()in
    match x with
      "0" -> ()
    | x -> let rec sum result = function
               0 -> result
             | i -> sum (result + (int_of_char x.[i-1]) - (int_of_char '0')) (i-1)
           in
           print_int @@ sum 0 (String.length x);
           print_char '\n';
           loop ()           
  in
  loop ()
;;
