import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  val c = new Array[String](2*N + 1)
  val a = new Array[Int](2*N + 1)

  for(i <- 1 to 2*N) {
    val x, y = in.next()
    c(i) = x; a(i) = y.toInt
  }


  //
  val wi = new Array[Int](N+1)
  val bi = new Array[Int](N+1)

  for(i <- 1 to 2*N) {
    if(c(i) == "W")
      wi(a(i)) = i
    else
      bi(a(i)) = i
  }


  val memow = Array.ofDim[Int](N+1, 2*N+1)
  val memob = Array.ofDim[Int](N+1, 2*N+1)

  for(i <- 1 to N) {
    memow(i)(wi(i)) += 1
    if(i == 1) {
      for(k <- 2 to 2*N)
        memow(i)(k) += memow(i)(k-1)
    }
    else {
      for(k <- 2 to 2*N)
        memow(i)(k) += memow(i)(k-1)
      for(k <- 1 to 2*N)
        memow(i)(k) += memow(i-1)(k)
    }
  }


  for(i <- 1 to N) {
    memob(i)(bi(i)) += 1
    if(i == 1) {
      for(k <- 2 to 2*N)
        memob(i)(k) += memob(i)(k-1)
    }
    else {
      for(k <- 2 to 2*N)
        memob(i)(k) += memob(i)(k-1)
      for(k <- 1 to 2*N)
        memob(i)(k) += memob(i-1)(k)
    }
  }


  val dp = Array.ofDim[Int](N+1, N+1)

  dp(0)(0) = 0

  for(x <- 1 to N) {
    val now = (bi(x) - 1) - (memob(x-1)(bi(x) - 1))
    dp(0)(x) = dp(0)(x-1) + now
  }

  for(y <- 1 to N) {
    val now = (wi(y) - 1) - (memow(y-1)(wi(y) - 1))
    dp(y)(0) = dp(y-1)(0) + now
  }

  for(y <- 1 to N; x <- 1 to N) {
    val a = dp(y)(x-1) + (bi(x) - 1) - (memob(x-1)(bi(x)-1)) - (memow(y)(bi(x)-1))
    val b = dp(y-1)(x) + (wi(y) - 1) - (memow(y-1)(wi(y)-1)) - (memob(x)(wi(y)-1))

    dp(y)(x) = Math.min(a, b)
  }

  // dp.foreach{ x => println(x.deep) }
  println(dp(N)(N))
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}

