let id x = x

let init n f =
  let rec g i ns = if i = 0 then 0 :: ns else g (i - 1) (i :: ns) in
  List.map f (g n [])

let split_string ?(pattern="") = Str.split @@ Str.regexp pattern

let ss = split_string @@ Scanf.scanf "%s\n" id

let len = List.length ss

let () =
  ss
    |> List.mapi (fun idx s -> (len - idx - 1, s))
    |> (fun lst -> List.fold_right (fun (idx, s) (sum, b_cnt) -> if s = "B" then (sum + idx - b_cnt, b_cnt + 1) else (sum, b_cnt)) lst (0, 0))
    |> (fun (sum, _) -> sum)
    |> print_int;
  print_newline ()