let s = Stack.create ()

let rec solve acc = function
  | [] | _::[] -> acc
  | x1::x2::xs ->
     match x1, x2 with
     | 0, 1 | 1, 0 -> 
        if not (Stack.is_empty s) then 
          let x' = Stack.pop s in solve (acc + 2) (x'::xs)
        else solve (acc + 2) xs
     | x1, x2 ->
        Stack.push x1 s;
        solve acc (x2::xs)

let input_bits () =
  let rec inner acc =
    try
      let acc' = (Scanf.scanf "%1d" (fun i -> i::acc)) in
      inner acc'
    with e -> acc
  in List.rev @@ inner []

let _ =
  let inputs = input_bits () in
  solve 0 inputs
  |> print_int