Scanf.scanf "%s" (fun s ->
    let n = String.length s in
    let rec loop i w acc =
        if i = n then acc else
            if s.[i] = 'B' then loop (i + 1) w acc else
                loop (i + 1) (w + 1) (acc + i - w)
    in
    loop 0 0 0 |> Printf.printf "%d\n"
)