package main

import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
  "sort"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt() int {
  n, _ := strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func NextFloat() float64 {
  n, _ := strconv.ParseFloat(NextLine(), 64)
  return n
}
func NextFloatVec() []float64 {
  L := strings.Split(NextLine(), " ")
  N := make([]float64, len(L))
  for i := range N {
    N[i], _ = strconv.ParseFloat(L[i], 64)
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}

type BinaryIndexedTree []int
func (BIT BinaryIndexedTree) Get(idx int) int {
  b := 0
  for i := idx; 0 < i; i -= i & (-i) {
    b += BIT[i]
  }
  return b
}
func (BIT *BinaryIndexedTree) Update(idx, v int) {
  N := len((*BIT))
  d := v - BIT.Get(idx) + BIT.Get(idx - 1)
  for i := idx; i < N; i += i & (-i) {
    (*BIT)[i] += d
  }
}
func (BIT BinaryIndexedTree) Query(s, t int) int {
  return BIT.Get(t) - BIT.Get(s)
}
func (BIT *BinaryIndexedTree) Increment(idx int) {
  N := len((*BIT))
  for i := idx; i < N; i += i & (-i) {
    (*BIT)[i]++
  }
}

func InitBIT(N int) BinaryIndexedTree {
  BIT := make([]int, N + 1)
  return BIT
}

type Balls [][]int
func (B Balls) Len() int { return len(B) }
func (B Balls) Less(i, j int) bool { return B[i][0] < B[j][0] }
func (B Balls) Swap(i, j int) { B[i], B[j] = B[j], B[i] }

func Solve() {
  N := NextInt()
  B := make([][]int, 0)
  W := make([][]int, 0)
  for i := 0; i < 2 * N; i++ {
    CA := strings.Split(NextLine(), " ")
    A, _ := strconv.Atoi(CA[1])
    if CA[0] == "B" {
      B = append(B, []int{A, i + 1})
    } else {
      W = append(W, []int{A, i + 1})
    }
  }
  sort.Sort(sort.Reverse(Balls(B)))
  sort.Sort(sort.Reverse(Balls(W)))
  BITB := InitBIT(2 * N)
  BITW := InitBIT(2 * N)
  CB := make([][]int, N)
  CW := make([][]int, N)
  for i := range CB {
    CB[i] = make([]int, N + 1)
    CW[i] = make([]int, N + 1)
  }
  for i := range CB {
    CB[N - 1 - i][0] = BITB.Query(0, B[i][1])
    BITB.Increment(B[i][1])
    CW[N - 1 - i][0] = BITW.Query(0, W[i][1])
    BITW.Increment(W[i][1])
    for j := range CB[i][1:] {
      CB[N - 1 - i][j + 1] += CB[N - 1 - i][j]
      if B[i][1] < W[N - 1 - j][1] { CB[N - 1 - i][j + 1]++ }
      CW[N - 1 - i][j + 1] += CW[N - 1 - i][j]
      if W[i][1] < B[N - 1 - j][1] { CW[N - 1 - i][j + 1]++ }
    }
  }
  DP := make([][]int, N + 1)
  for i := range DP {
    DP[i] = make([]int, N + 1)
    for j := range DP[i] {
      DP[i][j] = N * N * N
    }
  }
  DP[0][0] = 0
  for i := range DP {
    for j := range DP[i] {
      if 0 < i { DP[i][j] = MinInt(DP[i - 1][j] + CB[i - 1][j], DP[i][j]) }
      if 0 < j { DP[i][j] = MinInt(DP[i][j - 1] + CW[j - 1][i], DP[i][j]) }
    }
  }
  Write(DP[N][N])
  return
}

func main() {
  Solve()
  Output()
}

Measured memory_bytes: 100864