data class Ball(val c: Char, val v: Int)

const val INF = Int.MAX_VALUE / 4

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val balls = Array( 2 * n, {
    val (cString, vString) = readLine()!!.split(" ")
    val c = cString[0]
    val v = vString.toInt()
    Ball(c, v)
  })
      .toMutableList()

  val whiteValueToIndex = IntArray(n + 1, { -1 })
  val blackValueToIndex = IntArray(n + 1, { -1 })
  for (i in 0 until 2 * n) {
    if (balls[i].c == 'W') {
      whiteValueToIndex[balls[i].v] = i
    } else {
      blackValueToIndex[balls[i].v] = i
    }
  }

  val whiteLeft = Array(2 * n, { BooleanArray(n + 1) })
  val blackLeft = Array(2 * n, { BooleanArray(n + 1) })
  val countWhiteLE = Array(2 * n, { IntArray(n + 1) })
  val countBlackLE = Array(2 * n, { IntArray(n + 1) })
  for (i in 0 until 2 * n) {
    if (balls[i].c == 'W') {
      for (j in i + 1 until 2 * n) {
        whiteLeft[j][balls[i].v] = true
      }
    } else {
      for (j in i + 1 until 2 * n) {
        blackLeft[j][balls[i].v] = true
      }
    }
  }
  for (i in 0 until 2 * n) {
    for (k in 1..n) {
      countWhiteLE[i][k] = countWhiteLE[i][k - 1] + if (whiteLeft[i][k]) 1 else 0
      countBlackLE[i][k] = countBlackLE[i][k - 1] + if (blackLeft[i][k]) 1 else 0
    }
  }

  val dp = Array(n + 1, { IntArray(n + 1, { INF }) })
  dp[0][0] = 0

  for (w in 0..n) {
    for (b in 0..n) {
      // w White and b Black are used now.

      // w + 1 White
      if (w < n) {
        val index = whiteValueToIndex[w + 1]
        // val index = balls.indexOfFirst { it.c == 'W' && it.v == w + 1 }
        val cost = index - countWhiteLE[index][w] - countBlackLE[index][b]
        dp[w + 1][b] = Math.min(dp[w + 1][b], dp[w][b] + cost)
      }

      // b + 1 Black
      if (b < n) {
        val index = blackValueToIndex[b + 1]
        // val index = balls.indexOfFirst { it.c == 'B' && it.v == b + 1 }
        val cost = index - countWhiteLE[index][w] - countBlackLE[index][b]
        dp[w][b + 1] = Math.min(dp[w][b + 1], dp[w][b] + cost)
      }
    }
  }
  println(dp[n][n])
}
