let memoize n f =
  let dp = Hashtbl.create n in
  let rec get x =
    try Hashtbl.find dp x with
    | Not_found ->
        let result = f get x in
        Hashtbl.add dp x result;
        result in
  get

let () = Scanf.scanf "%d\n" @@ fun n ->
  let cas = Array.init (2 * n) @@ fun _ -> Scanf.scanf "%c %d\n" @@ fun c a -> c, a in
  let inv_ws = Array.make n 0 in
  let inv_bs = Array.make n 0 in
  let acc_ws = Array.make_matrix (2 * n + 1) (n + 1) 0 in
  let acc_bs = Array.make_matrix (2 * n + 1) (n + 1) 0 in
  for i = 2 * n - 1 downto 0 do
    begin match cas.(i) with
    | ('W', a) ->
        inv_ws.(a - 1) <- i;
        acc_ws.(i).(a) <- 1 + acc_ws.(i).(a)
    | ('B', a) ->
        inv_bs.(a - 1) <- i;
        acc_bs.(i).(a) <- 1 + acc_bs.(i).(a)
    end;
    for j = 1 to n do
      acc_ws.(i).(j) <- acc_ws.(i).(j) + acc_ws.(i).(j - 1);
      acc_bs.(i).(j) <- acc_bs.(i).(j) + acc_bs.(i).(j - 1)
    done;
    for j = 0 to n do
      acc_ws.(i).(j) <- acc_ws.(i).(j) + acc_ws.(i + 1).(j);
      acc_bs.(i).(j) <- acc_bs.(i).(j) + acc_bs.(i + 1).(j)
    done
  done;
  let dp = memoize ((n + 1) * (n + 1)) @@ fun dp (w, b) ->
    if w = 0 && b = 0 then 0
    else min
      (if w = 0 then max_int else
        dp (w - 1, b) + inv_ws.(w - 1)
        + acc_ws.(inv_ws.(w - 1) + 1).(w)
        + acc_bs.(inv_ws.(w - 1) + 1).(b))
      (if b = 0 then max_int else
        dp (w, b - 1) + inv_bs.(b - 1)
        + acc_ws.(inv_bs.(b - 1) + 1).(w)
        + acc_bs.(inv_bs.(b - 1) + 1).(b)) - w - b + 1 in
  Printf.printf "%d\n" @@ dp (n, n)
