module mod_binary_indexed_tree
  implicit none
  type fenwick_tree
    integer :: n
    integer, pointer :: arr(:)
  end type fenwick_tree
  private
  public :: fenwick_tree, init_bit, release_bit
  public :: add, summate, update, maximum
contains
  subroutine init_bit(bit,n)
    implicit none
    type(fenwick_tree) :: bit
    integer, intent(in) :: n
    bit%n = n
    allocate(bit%arr(n))
    bit%arr = 0
    return
  end subroutine init_bit
  subroutine release_bit(bit)
    implicit none
    type(fenwick_tree) :: bit
    if (associated(bit%arr)) deallocate(bit%arr)
    return
  end subroutine release_bit
  subroutine add(bit,i,v)
    implicit none
    type(fenwick_tree) :: bit
    integer, intent(in) :: i, v
    integer :: x
    if (i.eq.0) return
    x = i
    do while (x.le.bit%n)
      bit%arr(x) = bit%arr(x)+v
      x = x+and(x,-x)
    end do
    return
  end subroutine add
  function summate(bit,i) result(s)
    implicit none
    type(fenwick_tree) :: bit
    integer, intent(in) :: i
    integer :: x, s
    x = i
    s = 0
    do while (x.gt.0)
      s = s+bit%arr(x)
      x = x-and(x,-x)
    end do
    return
  end function summate
  subroutine update(bit,i,v)
    implicit none
    type(fenwick_tree) :: bit
    integer, intent(in) :: i, v
    integer :: x
    x = i
    do while (x.le.bit%n)
      if (bit%arr(x).lt.v) bit%arr(x) = v
      x = x+and(x,-x)
    end do
    return
  end subroutine update
  function maximum(bit,i) result(m)
    implicit none
    type(fenwick_tree) :: bit
    integer, intent(in) :: i
    integer :: x, m
    x = i
    m = 0
    do while (x.gt.0)
      m = max(m,bit%arr(x))
      x = x-and(x,-x)
    end do
    return
  end function maximum
end module mod_binary_indexed_tree
program sorted_and_sorted
  use mod_binary_indexed_tree
  implicit none
  integer, parameter :: infty = 1000000000
  type(fenwick_tree) :: bit
  integer :: n, a, aw, ab, i, j
  integer :: ib(2000), iw(2000), dp(0:2000,0:2000)
  character(1) :: c
  ib = 0
  iw = 0
  dp = infty
  dp(0,0) = 0
  read(*,*) n
  call init_bit(bit,2*n)
  do i = 1, 2*n
    read(*,*) c, a
    if (c.eq."B") then
      ib(a) = i
    else
      iw(a) = i
    end if
  end do
  do i = 0, n
    if (i.ne.0) then
      call add(bit,1,1)
      call add(bit,ib(i),-1)
    end if
    do j = 0, n
      if (j.ne.0) then
        call add(bit,1,1)
        call add(bit,iw(j),-1)
      end if
      if (i.ne.0) dp(i,j) = min(dp(i,j),dp(i-1,j)+ib(i)-i-j+summate(bit,ib(i)))
      if (j.ne.0) dp(i,j) = min(dp(i,j),dp(i,j-1)+iw(j)-i-j+summate(bit,iw(j)))
    end do
    do j = n, 1, -1
      call add(bit,1,-1)
      call add(bit,iw(j),1)
    end do
  end do
  write(*,'(i0)') dp(n,n)
  call release_bit(bit)
  stop
end program sorted_and_sorted