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 = Array.make_matrix (n + 1) (n + 1) max_int in
  dp.(0).(0) <- 0;
  for w = 1 to n do
    dp.(w).(0) <- dp.(w - 1).(0) - w + 1
      + inv_ws.(w - 1)
      + acc_ws.(inv_ws.(w - 1) + 1).(w)
  done;
  for b = 1 to n do
    dp.(0).(b) <- dp.(0).(b - 1) - b + 1
      + inv_bs.(b - 1)
      + acc_bs.(inv_bs.(b - 1) + 1).(b)
  done;
  for w = 1 to n do
    for b = 1 to n do
      dp.(w).(b) <- min
        ( dp.(w - 1).(b) + inv_ws.(w - 1)
          + acc_ws.(inv_ws.(w - 1) + 1).(w)
          + acc_bs.(inv_ws.(w - 1) + 1).(b) )
        ( 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
    done
  done;
  Printf.printf "%d\n" @@ dp.(n).(n)
